Skip to content

Commit

Permalink
Merge pull request #424 from yast/start-dbus
Browse files Browse the repository at this point in the history
[service] Start the daemon in the systemd service
  • Loading branch information
imobachgs committed Feb 15, 2023
2 parents 2f3154a + 411af8a commit df2f403
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 20 deletions.
5 changes: 2 additions & 3 deletions service/bin/d-installer
Expand Up @@ -57,7 +57,7 @@ end
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"] = [ENV["Y2DIR"], module_y2dir, general_y2dir].compact.join(":")
ENV["Y2DIR"] = [ENV.fetch("Y2DIR", nil), module_y2dir, general_y2dir].compact.join(":")

service_runner = DInstaller::DBus::ServiceRunner.new(name, logger: logger_for(name))
service_runner.run
Expand Down Expand Up @@ -111,8 +111,7 @@ elsif ["-k", "--kill"].include?(ARGV[0])
dbus_server_manager.stop_server
elsif ["-d", "--daemon"].include?(ARGV[0])
# start the D-Bus server
pid = dbus_server_manager.find_or_start_server
puts pid
dbus_server_manager.find_or_start_server
else
dbus_server_manager.find_or_start_server
name = ARGV[0]
Expand Down
19 changes: 9 additions & 10 deletions service/lib/dinstaller/dbus/server_manager.rb
Expand Up @@ -19,7 +19,6 @@
# To contact SUSE LLC about this file by physical or electronic mail, you may
# find current contact information at www.suse.com.

require "cheetah"
require "fileutils"

module DInstaller
Expand Down Expand Up @@ -55,20 +54,20 @@ def find_or_start_server
def start_server
FileUtils.mkdir_p(run_directory)

output = Cheetah.run(
cmd = [
"/usr/bin/dbus-daemon",
"--config-file", config_file,
"--address", address,
"--fork", "--systemd-activation",
"--print-pid",
stdout: :capture
)
"--systemd-activation",
"--print-pid"
]
pid = Process.spawn(*cmd)
Process.detach(pid)
File.write(address_file, address)
pid = output.strip
File.write(pid_file, pid)
pid.to_i
rescue Cheetah::ExecutionFailed => e
puts "Could not start the DBus daemon: #{e.message}"
pid
rescue SystemCallError => e
warn "Could not start the DBus daemon: #{e.message}"
nil
end

Expand Down
3 changes: 2 additions & 1 deletion service/share/systemd.service
Expand Up @@ -5,7 +5,8 @@ After=network-online.target

[Service]
Type=simple
ExecStart=/usr/bin/d-installer
ExecStart=/usr/bin/d-installer --daemon
PIDFile=/run/d-installer/bus.pid
User=root
TimeoutStopSec=5

Expand Down
8 changes: 5 additions & 3 deletions service/test/dinstaller/dbus/server_manager_test.rb
Expand Up @@ -31,7 +31,8 @@
let(:tmpdir) { Dir.mktmpdir }

before do
allow(Cheetah).to receive(:run).and_return("9999")
allow(Process).to receive(:spawn).and_return(9999)
allow(Process).to receive(:detach)
end

after do
Expand Down Expand Up @@ -63,9 +64,10 @@

describe "#start_server" do
it "starts the dbus-daemon and returns the PID" do
expect(Cheetah).to receive(:run)
expect(Process).to receive(:spawn)
.with(/dbus-daemon/, "--config-file", /dbus.conf/, any_args)
.and_return("1000")
.and_return(1000)
expect(Process).to receive(:detach).with(1000)
expect(subject.start_server).to eq(1000)
end

Expand Down
23 changes: 23 additions & 0 deletions web/src/client/dbus.js
Expand Up @@ -129,6 +129,29 @@ class DBusClient {
return this.client.call(path, iface, method, args);
}

/**
* Gets a property for a given path and interface
*
* @param {string} path - D-Bus object path
* @param {string} iface - D-Bus interface name
* @param {string} name - D-Bus property name
* @return {Promise<any>}
*/
async getProperty(path, iface, name) {
let property;

try {
const result = await this.client.call(
path, "org.freedesktop.DBus.Properties", "Get", [iface, "Errors"]
);
property = result[0];
} catch (error) {
console.warn(`Could not get the ${name} property in ${iface}`, error);
}

return (property === undefined) ? null : property.v;
}

/**
* Register a callback to run when properties change for given D-Bus path
*
Expand Down
11 changes: 9 additions & 2 deletions web/src/client/mixins.js
Expand Up @@ -155,8 +155,15 @@ const WithValidation = (superclass, object_path) => class extends superclass {
* @return {Promise<ValidationError[]>}
*/
async getValidationErrors() {
const proxy = await this.client.proxy(VALIDATION_IFACE, object_path);
return proxy.Errors.map(createError);
let errors;

try {
errors = await this.client.getProperty(object_path, VALIDATION_IFACE, "Errors");
} catch (error) {
console.error(`Could not get validation errors for ${object_path}`, error);
}

return errors.map(createError);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion web/src/components/overview/StorageSection.jsx
Expand Up @@ -32,7 +32,7 @@ import { InstallerSkeleton, Section } from "~/components/core";
import { ProposalSummary } from "~/components/storage";

const initialState = {
busy: false,
busy: true,
proposal: undefined,
errors: []
};
Expand Down

0 comments on commit df2f403

Please sign in to comment.