[systemd-devel] How to dynamically retrieve my service name?

Etienne Doms etienne.doms at gmail.com
Tue Nov 10 16:28:10 UTC 2020


Hello,

My service needs to behave a bit differently when it has been
automatically because of a software fault. I use the
"Restart=on-failure", and I understand that I can read the "NRestarts"
property which is incremented whenever the service is restarted.

The thing is, inside my service, I have no idea if I'm foobar.service,
barfoo.service, etc. and I believe I should be agnostic of that.

Is there a way to dynamically retrieve
/org/freedesktop/systemd1/unit/foobar_2eservice, so that I can ask
org.freedesktop.systemd1 the NRestarts property value of the
org.freedesktop.systemd1.Service interface?

Maybe I'm just over-engineering and should just hardcode
"foobar.service" inside my service, but it feels a bit odd to me...
Maybe also I understand nothing about D-Bus, sorry about that.

Thank you for your support.

Best regards,
Etienne Doms


More information about the systemd-devel mailing list