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,811

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
  • 2,164