3

This question is related to: reliable systemd service for autossh

I have a service which uses type=simple. Here the systemd docs:

Type=simple (default): systemd considers the service to be started up immediately. The process must not fork. Do not use this type if other services need to be ordered on this service, unless it is socket activated.

Imagine the service is in an endless loop or hangs.

How can systemd know if the service is ok or not?

Is there some kind if IPC between systemd and the service possible?

What I want: I want systemctl status foo-service to tell me if the service is ok. That's different from "the linux-process of the service still exists".

guettli
  • 3,113
  • 14
  • 59
  • 110
  • How is anyone supposed to know that the service is in an endless loop or hangs? – Michael Hampton Apr 15 '16 at 05:14
  • @MichaelHampton good question: If systemd has some kind of IPC to queryy the status, then my service can provide it. Providing the status is no problem. The question is: does systemd provide a way to query the status of the service? – guettli Apr 15 '16 at 06:08
  • [Yes, it does.](https://www.freedesktop.org/software/systemd/man/sd_notify.html) – Michael Hampton Apr 15 '16 at 06:17
  • @MichaelHampton The sd_notify alone could be used, but in most cases the service won't tell systemd "hey, I am going to start an endless loop - I am in nirvana now - good bye :-)". ... But thank you for the link. There I found a good next step: "watchdog". Thank you – guettli Apr 15 '16 at 07:43

1 Answers1

2

systemctl status does not provide advanced information on the service running.

If you are looking for ways to notify systemd about status changes on your service, sd_notify might be helpful. This depends on your services ability for self-diagnosis, though. If your service uses sd_notify, you can configure the service withWatchdogSec`. To cite from the documentation:

Configures the watchdog timeout for a service. The watchdog is activated when the start-up is completed. The service must call sd_notify(3) regularly with "WATCHDOG=1" (i.e. the "keep-alive ping"). If the time between two such calls is larger than the configured time, then the service is placed in a failed state and it will be terminated with SIGABRT.

However using systemctl show you can retrieve some additional machine-readable information on the service, which might help you deciding if the service is okay.

In case you are looking for systemd to tell if your service runs in an infinite loop, your are most likely out of luck. That problemis closely related to the halting problem, for which is proven that no general algorithm to solve the problem exists. While your specific problem might be solvable, it is most likely at least an enormous waste of resources. See this related question.

M. Glatki
  • 1,868
  • 1
  • 16
  • 33