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!
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With