I want to start a systemd service from its D-Bus interface. However, it seems that services that are not already started or "enabled" (running on startup) are unknown to the Systemd D-Bus interface :
# my-service.service
[Unit]
Description=My service
[Service]
Type=simple
ExecStart=/usr/local/bin/my-service
[Install]
WantedBy=multi-user.target
> systemctl status my-service
● my-service.service - My service
Loaded: loaded (/usr/local/lib/systemd/system/my-service.service; disabled; vendor preset: enabled)
Active: inactive (dead)
> gdbus call --system --dest org.freedesktop.systemd1 -o /org/freedesktop/systemd1 -m org.freedesktop.systemd1.Manager.GetUnit my-service.service
Erreur : GDBus.Error:org.freedesktop.systemd1.NoSuchUnit: Unit my-service.service not loaded.
> systemctl enable my-service.service
Created symlink /etc/systemd/system/multi-user.target.wants/my-service.service → /usr/local/lib/systemd/system/my-service.service.
> gdbus call --system --dest org.freedesktop.systemd1 -o /org/freedesktop/systemd1 -m org.freedesktop.systemd1.Manager.GetUnit my-service.service
(objectpath '/org/freedesktop/systemd1/unit/my_2dservice_2eservice',)
I can start my-service with systemctl, but I cannot access it via D-Bus.
How can I use the D-Bus interface as I can use systemctl
, to start disabled services?