Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using gdbus to start a systemd service

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!

like image 254
RandomUser Avatar asked Jul 14 '15 19:07

RandomUser


People also ask

Does systemd use Dbus?

It consists of a daemon, which can be run both system-wide and for each user session, and a set of libraries to allow applications to use D-Bus. dbus is pulled and installed as a dependency of systemd and user session bus is started automatically for each user.

What is ExecStop systemd?

The ExecStop setting is optional and is used to communicate with the service for a clean termination. The process specified by ExecStop will run in case the service crashes.

What is Type forking in systemd?

forking: This service type is used when the service forks a child process, exiting the parent process almost immediately. This tells systemd that the process is still running even though the parent exited.


1 Answers

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
like image 144
Umut Avatar answered Sep 28 '22 03:09

Umut