Re: How to dynamically retrieve my service name?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



You can call org.freedesktop.systemd1.Manager.GetUnitByPID() to directly get the D-Bus object path based on your PID.

There is also the magic path "/org/freedesktop/systemd1/unit/self" which always gives properties of the same service (or scope) that you're in.

Finally, it is possible to call sd_pid_get_unit() from sd-login.h to get your unit name (straight from /proc/<pid>/cgroup, with no D-Bus yet), then call .Manager.GetUnit() to translate the name into an object path.



On Tue, Nov 10, 2020 at 6:28 PM Etienne Doms <etienne.doms@xxxxxxxxx> wrote:
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
_______________________________________________
systemd-devel mailing list
systemd-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/systemd-devel


--
Mantas Mikulėnas
_______________________________________________
systemd-devel mailing list
systemd-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/systemd-devel

[Index of Archives]     [LARTC]     [Bugtraq]     [Yosemite Forum]     [Photo]

  Powered by Linux