74 lines
2.1 KiB
Ruby
Executable file
74 lines
2.1 KiB
Ruby
Executable file
#!/usr/bin/env ruby
|
|
# frozen_string_literal: true
|
|
|
|
#
|
|
# Copyright (c) [2022] SUSE LLC
|
|
#
|
|
# All Rights Reserved.
|
|
#
|
|
# This program is free software; you can redistribute it and/or modify it
|
|
# under the terms of version 2 of the GNU General Public License as published
|
|
# by the Free Software Foundation.
|
|
#
|
|
# This program is distributed in the hope that it will be useful, but WITHOUT
|
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
# more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License along
|
|
# with this program; if not, contact SUSE LLC.
|
|
#
|
|
# To contact SUSE LLC about this file by physical or electronic mail, you may
|
|
# find current contact information at www.suse.com.
|
|
|
|
# TEMPORARY overwrite of Y2DIR to use DBus for communication with dependent yast modules
|
|
|
|
$LOAD_PATH.unshift File.expand_path("../lib", __dir__)
|
|
|
|
require "rubygems"
|
|
require "bundler/setup"
|
|
require "dinstaller/dbus/service_runner"
|
|
|
|
# Runs the service with the given name
|
|
#
|
|
# @param name [Symbol] Service name
|
|
# @see ORDERED_SERVICES
|
|
def start_service(name)
|
|
general_y2dir = File.expand_path("../lib/dinstaller/dbus/y2dir", __dir__)
|
|
module_y2dir = File.expand_path("../lib/dinstaller/dbus/y2dir/#{name}", __dir__)
|
|
ENV["Y2DIR"] = "#{module_y2dir}:#{general_y2dir}"
|
|
|
|
logger = Logger.new($stdout, progname: name.to_s)
|
|
service_runner = DInstaller::DBus::ServiceRunner.new(name, logger: logger)
|
|
service_runner.run
|
|
end
|
|
|
|
ORDERED_SERVICES = [:software, :users, :manager].freeze
|
|
|
|
# Starts all the services
|
|
#
|
|
# @return [Array<Integer>] PIDs
|
|
# @see ORDERED_SERVICES
|
|
def start_all_services
|
|
ORDERED_SERVICES.map do |name|
|
|
fork { exec("#{__FILE__} #{name}") }
|
|
# TODO: implement a better mechanism to check whether the service is running
|
|
sleep(1)
|
|
end
|
|
end
|
|
|
|
if ARGV.empty?
|
|
pids = start_all_services
|
|
Signal.trap("SIGINT") do
|
|
puts "Stopping all services..."
|
|
exit
|
|
end
|
|
Process.wait
|
|
else
|
|
name = ARGV[0]
|
|
Signal.trap("SIGINT") do
|
|
puts "Stopping #{name} service..."
|
|
exit
|
|
end
|
|
start_service(name.to_sym)
|
|
end
|