[systemd-devel] OT: Which tool to use to restart service if check-script fails

Thomas Güttler guettliml at thomas-guettler.de
Mon May 30 07:29:43 UTC 2016



Am 27.05.2016 um 09:40 schrieb Reindl Harald:
>
>
> Am 27.05.2016 um 06:48 schrieb Thomas Güttler:
>> OK, I understand that I need different tool to restart a service
>> if a check-script fails.
>>
>> In my case the check script will be custom code. But the restart stuff
>> is very general and reusable:
>>
>>  Step1: Call check-script
>>  Step2: If exit 0 (meaning service is working), then wait N seconds, got
>> to Step1
>>  Step3: Service is not working: Send process the signal TERM_SIGNAL
>> (should be configurable)
>>  Step4: Wait N seconds until process terminated.
>>  Step5: If process did terminate, restart the service. Wait, go to Step1
>>  Step6: Process did not terminate: Wait N seconds, Send signal KILL
>>  Step7: Wait until OS has cleaned up the service
>>  Step8: Restart the service, Wait, got to Step1
>>
>> I could implement these steps myself, but I am lazy. I guess this
>> has already been done several times before.
>>
>> Any tool recommendation?
>
> that are just a few lines code in any programming language

Yes, but I nevertheless I prefer to reuse.

> your logic is way too complex - just SIGTERM and SIGKILL the service and a proper configured systemd-unit with
> "Restart=always" will automatically restarted when you shoot the main process in the head

That's a reason why I like to reuse. I am just a small sheep,
and more intelligent sheep already solved many edge cases I don't see
at the first sight.

> also; if the service was *manually* stopped it will keep stopped because the kill-calls won't do anything
> _________________________
>
> [root at testserver:~]$ cat /etc/systemd/system/monitor-dbmail-lmtpd.service
 > ..

Thank you for the code snippet.

If I don't find anything I can install via package manager, then I will
take this as a start.


Regards,
   Thomas

-- 
Thomas Guettler http://www.thomas-guettler.de/


More information about the systemd-devel mailing list