[systemd-devel] systemd restart patch

Cristian Patrascu Cristian.Patrascu at windriver.com
Thu Jun 23 01:59:04 PDT 2011


On 02/08/2011 12:34 PM, Lennart Poettering wrote:
> On Mon, 07.02.11 10:01, Cristian Patrascu (Cristian.Patrascu at windriver.com) wrote:
>
>> On 02/03/2011 11:19 PM, Michael Biebl wrote:
>>> 2011/2/3 Tomasz Torcz<tomek at pipebreaker.pl>:
>>>> On Thu, Feb 03, 2011 at 09:35:55PM +0100, Michael Biebl wrote:
>>>>> ExecStartOnFailure=/some/cmd (send an email or what not)
>>>>   Isn't “OnFailure=send-email-to-admin.service” sufficent?
>>> Having to use a service file for this use case is imho cumbersome,
>>> especially since you can't pass information to that service afaik,
>>> e.g. via env variables.
>>> So this send-email-to-admin.service doesn't know which service it was,
>>> that failed and its last status code. Or am I misinformed here?
>>>
>>> Also, does OnFailure= work as I described with regard to Restart=on-failure?
>>>
>>> Michael
>> On 02/03/2011 10:35 PM, Michael Biebl wrote:
>>> ExecStartOnFailure=/some/cmd (send an email or what not)
>>>
>>> If Restart=on-failure is not set, this command is executed when the
>>> starting the service has failed.
>> 2011/2/3 Cristian Patrascu<Cristian.Patrascu at windriver.com>:
>>> - RestartRetries=n (where n is the number of restart retries)
>> Using "Restart=on-failure" and "OnFailure=some-other.service",  the
>> specified service will be started for every restart that exits with
>> fail, of current service.
> I think tis current behaviour probably makes little sense, so my
> suggestion would be to simply change it and run the services listed in
> OnFailure= only after we tried to restart the service and gave up.
>
> So here's what I'd suggest:
>
> a) Introduce RestartRetries= as you suggested
>
> b) Reshuffle things so that OnFailure= is run only after RestartRetries=
>     is reached when it is set or each time if RestartRetries= is not set.
>
> c) Do not introduce ExecPostRestarts=
>
> I think this would be a very simple, minimal and natural extension and
> should do everything you need, right? I'd be happy to merge such a patch!
>
> Lennart
Patch is attached, sorry for answering so late.

Functionality:
      In case a service failed to start properly (it exited with a code
not 0 - not successfull) it has to be retried, to be restarted a
predefined number of times, until it ends successfully or until the
predefined number of restarts is reached. For that, there is the option
"MaxRestartRetries" wich accepts an integer = number of restarts. This
applies only to ".service" units.

      So, if a service has "MaxRestartRetries=<x>" and option
"Restart=no" or not set: it should be restarted maximum "x" times, if it
exits unsuccessfully every time; if service has "Restart=on-success"
then it will allways be restarted on successfull exit and maximum "x"
restarts with unsuccessfull exits. For "Restart=always" it will restart
"x" times max. if exited unsuccessfully and for successfull exit always
restart. Otherwise for "Restart=on-abort" it's the same functionality.

      After "x" restarts have happened, the "OnFailure" unit will start
(if specified) but only after all unsuccessfull restarts (after "x"
restarts reached).

This patch is made for systemd-29, on master branch with SHA1 ID:
3661ac04b4f2840d3345605aa35963bbde3c469d

-------------- next part --------------
A non-text attachment was scrubbed...
Name: systemd-restart-on-fail.patch
Type: text/x-patch
Size: 9515 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/systemd-devel/attachments/20110623/a6ea5962/attachment.bin>


More information about the systemd-devel mailing list