How to provide a restart count to systemd service

Viewed 2368

I have an embedded device which manages its various services using systemd. Our status reporting application is one of these services. It is always on and it automatically restarts on failure (crashes, exceptions, OOM conditions, whatever).

We report an event to our cloud services on device restart (technically application restart) but I'd like to distinguish first start (after reboot) from restart. Is there a mechanism built into systemd which can provide the service restart count, or do I need to roll my own method?

2 Answers

you can use following command:

systemctl show foo.service -p NRestarts

It will return a value if the service is in a restart loop, otherwise, will return nothing.

Related