Ich hab mir jetzt einmal diese Test-Unit gebaut:
Bau dir einmal diese Test-Unit:
Code: Alles auswählen
/etc/systemd/system: # cat test@.service
[Unit]
Description=Testservice notification
OnFailure=notification-telegram-failed@%n.service
[Service]
Type=simple
Restart=on-failure
#RestartSec=10
ExecStart=/bin/%i
SyslogIdentifier=test@%i.service
StartLimitBurst=5
StartLimitInterval=10
Code: Alles auswählen
# cat notification-telegram@.service
[Unit]
Description=Send failure-notification about %i to telegram
[Service]
User=jakob
ExecStart=/bin/bash -c "/usr/local/bin/ntfy -b telegram send \"FAILED\n$(systemctl status %i)\""
Code: Alles auswählen
systemctl start test@false
Mär 08 00:31:53 aldebaran systemd[1]: Started Testservice notification.
Mär 08 00:31:53 aldebaran systemd[1]: test@false.service: Main process exited, code=exited, status=1/FAILURE
Mär 08 00:31:53 aldebaran systemd[1]: test@false.service: Failed with result 'exit-code'.
Mär 08 00:31:53 aldebaran systemd[1]: test@false.service: Triggering OnFailure= dependencies.
Mär 08 00:31:54 aldebaran systemd[1]: test@false.service: Service hold-off time over, scheduling restart.
Mär 08 00:31:54 aldebaran systemd[1]: test@false.service: Scheduled restart job, restart counter is at 1.
Mär 08 00:31:54 aldebaran systemd[1]: Stopped Testservice notification.
Mär 08 00:31:54 aldebaran systemd[1]: Started Testservice notification.
Mär 08 00:31:54 aldebaran systemd[1]: test@false.service: Main process exited, code=exited, status=1/FAILURE
Mär 08 00:31:54 aldebaran systemd[1]: test@false.service: Failed with result 'exit-code'.
Mär 08 00:31:54 aldebaran systemd[1]: test@false.service: Triggering OnFailure= dependencies.
Mär 08 00:31:54 aldebaran systemd[1]: test@false.service: Service hold-off time over, scheduling restart.
Mär 08 00:31:54 aldebaran systemd[1]: test@false.service: Scheduled restart job, restart counter is at 2.
Mär 08 00:31:54 aldebaran systemd[1]: Stopped Testservice notification.
Mär 08 00:31:54 aldebaran systemd[1]: Started Testservice notification.
Mär 08 00:31:54 aldebaran systemd[1]: test@false.service: Main process exited, code=exited, status=1/FAILURE
Mär 08 00:31:54 aldebaran systemd[1]: test@false.service: Failed with result 'exit-code'.
Mär 08 00:31:54 aldebaran systemd[1]: test@false.service: Triggering OnFailure= dependencies.
Mär 08 00:31:54 aldebaran systemd[1]: test@false.service: Service hold-off time over, scheduling restart.
Mär 08 00:31:54 aldebaran systemd[1]: test@false.service: Scheduled restart job, restart counter is at 3.
Mär 08 00:31:54 aldebaran systemd[1]: Stopped Testservice notification.
Mär 08 00:31:54 aldebaran systemd[1]: Started Testservice notification.
Mär 08 00:31:54 aldebaran systemd[1]: test@false.service: Main process exited, code=exited, status=1/FAILURE
Mär 08 00:31:54 aldebaran systemd[1]: test@false.service: Failed with result 'exit-code'.
Mär 08 00:31:54 aldebaran systemd[1]: test@false.service: Triggering OnFailure= dependencies.
Mär 08 00:31:54 aldebaran systemd[1]: test@false.service: Service hold-off time over, scheduling restart.
Mär 08 00:31:54 aldebaran systemd[1]: test@false.service: Scheduled restart job, restart counter is at 4.
Mär 08 00:31:54 aldebaran systemd[1]: Stopped Testservice notification.
Mär 08 00:31:54 aldebaran systemd[1]: test@false.service: Start request repeated too quickly.
Mär 08 00:31:54 aldebaran systemd[1]: test@false.service: Failed with result 'exit-code'.
Mär 08 00:31:54 aldebaran systemd[1]: Failed to start Testservice notification.
Mär 08 00:31:54 aldebaran systemd[1]: test@false.service: Triggering OnFailure= dependencies.
Ich bekomme 3 Notifications. Wahrscheinlich, weil die notification-Unit zu oft hintereinander aufgerufen wird, und der sendeprozess noch nicht abgeschlssen ist.
Daher hab ich RestartSec=2 einkommentiert und noch einmal ausgeführt:
Mär 08 00:44:14 aldebaran systemd[1]: Started Testservice notification.
Mär 08 00:44:14 aldebaran systemd[1]: test@false.service: Main process exited, code=exited, status=1/FAILURE
Mär 08 00:44:14 aldebaran systemd[1]: test@false.service: Failed with result 'exit-code'.
Mär 08 00:44:14 aldebaran systemd[1]: test@false.service: Triggering OnFailure= dependencies.
Mär 08 00:44:16 aldebaran systemd[1]: test@false.service: Service hold-off time over, scheduling restart.
Mär 08 00:44:16 aldebaran systemd[1]: test@false.service: Scheduled restart job, restart counter is at 1.
Mär 08 00:44:16 aldebaran systemd[1]: Stopped Testservice notification.
Mär 08 00:44:16 aldebaran systemd[1]: Started Testservice notification.
Mär 08 00:44:16 aldebaran systemd[1]: test@false.service: Main process exited, code=exited, status=1/FAILURE
Mär 08 00:44:16 aldebaran systemd[1]: test@false.service: Failed with result 'exit-code'.
Mär 08 00:44:16 aldebaran systemd[1]: test@false.service: Triggering OnFailure= dependencies.
Mär 08 00:44:19 aldebaran systemd[1]: test@false.service: Service hold-off time over, scheduling restart.
Mär 08 00:44:19 aldebaran systemd[1]: test@false.service: Scheduled restart job, restart counter is at 2.
Mär 08 00:44:19 aldebaran systemd[1]: Stopped Testservice notification.
Mär 08 00:44:19 aldebaran systemd[1]: Started Testservice notification.
Mär 08 00:44:19 aldebaran systemd[1]: test@false.service: Main process exited, code=exited, status=1/FAILURE
Mär 08 00:44:19 aldebaran systemd[1]: test@false.service: Failed with result 'exit-code'.
Mär 08 00:44:19 aldebaran systemd[1]: test@false.service: Triggering OnFailure= dependencies.
Mär 08 00:44:21 aldebaran systemd[1]: test@false.service: Service hold-off time over, scheduling restart.
Mär 08 00:44:21 aldebaran systemd[1]: test@false.service: Scheduled restart job, restart counter is at 3.
Mär 08 00:44:21 aldebaran systemd[1]: Stopped Testservice notification.
Mär 08 00:44:21 aldebaran systemd[1]: Started Testservice notification.
Mär 08 00:44:21 aldebaran systemd[1]: test@false.service: Main process exited, code=exited, status=1/FAILURE
Mär 08 00:44:21 aldebaran systemd[1]: test@false.service: Failed with result 'exit-code'.
Mär 08 00:44:21 aldebaran systemd[1]: test@false.service: Triggering OnFailure= dependencies.
Mär 08 00:44:23 aldebaran systemd[1]: test@false.service: Service hold-off time over, scheduling restart.
Mär 08 00:44:23 aldebaran systemd[1]: test@false.service: Scheduled restart job, restart counter is at 4.
Mär 08 00:44:23 aldebaran systemd[1]: Stopped Testservice notification.
Mär 08 00:44:23 aldebaran systemd[1]: test@false.service: Start request repeated too quickly.
Mär 08 00:44:23 aldebaran systemd[1]: test@false.service: Failed with result 'exit-code'.
Mär 08 00:44:23 aldebaran systemd[1]: Failed to start Testservice notification.
Mär 08 00:44:23 aldebaran systemd[1]: test@false.service: Triggering OnFailure= dependencies.
Wie man sieht, sind immer 2 Sekunden Pause zwischen den einzelnen Aufrufen, bis dann in der vorletzten Zeile der Failed-Status eintritt, nachdem StartLimitBurst erreicht wird.
Das Verhalten entspricht in der Tat nicht der Manpage von systemd.
Und weil es mir nicht liegt, irgendwie auf irgendwen hinzupecken, nur weil es andere auch tun, hab ich genau dieses Verhalten auf der systemd-Mailingliste geschildert. Bin gespannt, was da zurück kommt.
Bisher hab ich auf dieser Liste immer nur positive Erfahrungen gemacht. Und ja, Pöttering diskutiert dort mit. Und man kann auch als keiner Debianforist mit The Master Himself diskutieren... das machen nicht nur irgendwelche Entwickler oder Journalisten...
lg scientific