7
votes

I've created a new systemd service that I would like to be able to active via a dbus call. The service simply executes a shell script.

I've defined the service here:

/lib/systemd/system/testamundo.service


[Unit]
Description=Testamundo

[Service]
Type=dbus
BusName=org.freedesktop.testamundo
ExecStart=/home/test/systemd/testamundo.sh

I've also defined a D-Bus service for it here:

/usr/share/dbus-1/system-services

[D-BUS Service]
Name=org.freedesktop.testamundo
Exec=/usr/sbin/console-kit-daemon --no-daemon
User=root
SystemdService=testamundo.service

I am attempting to start it using gdbus, this is the command I'm trying to use:

sudo gdbus call --system --dest org.freedesktop.systemd1 --object-path /org/freedesktop/systemd1 --method org.freedesktop.systemd1.StartUnit "org.freedesktop.testamundo"

If I use --system as I did above the command returns with an Unknown Method error, if I use --session it returns with an exit code 1 from the child process. When I look at journalctl with --session and --system I can see the command, but beyond that no additional information.

Appreciate any thoughts or advice, thanks!

1

1 Answers

5
votes

Your dbus command is using non-existing interfaces. First of all it is org.freedesktop.systemd1.Manager.Start unit not org.freedesktop.systemd1.StartUnit. Second, org.freedesktop.systemd1.Manager.Start needs 2 parameters, service name and start mode. Ref: http://www.freedesktop.org/wiki/Software/systemd/dbus/

You have defined a dbus service but you are bypassing dbus by directly asking systemd to activate the service. Other note is, dbus actually sends a signal to systemd not a method call.

You have everything in place, if you just do an introspection on your service, it should be activate.

sudo gdbus call --system --dest org.freedesktop.testamundo --object-path /org/freedesktop/testamundo --method org.freedesktop.DBus.Introspectable. Introspect