0

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?

1 Answer 1

1

According to systemd D-Bus interface documentation, there's the method LoadUnit(name) to get unit information and loading it from disk if not already.

Also it seems that the StartUnit(name, mode) method doesn't seems to indicate if it loads the unit but it would be a reasonable guess it does.

1
  • I'm not sure why systemctl status says that the service is loaded, it's misleading. But that seems to work. Thanks!
    – Hugal31
    Commented Oct 19, 2020 at 8:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .