service icon indicating copy to clipboard operation
service copied to clipboard

Relaunch on crash should be consistent among systems or configurable.

Open mvanotti opened this issue 9 years ago • 12 comments

Installing a service allows it to start on boot and in some cases relaunch on crash, but this option is not configurable and is different among different systems, for example:

  • With systemd it will restart after 120 seconds if it crashed
  • With upstart it will restart after 5 seconds but only 10 times
  • With systemv it won't restart (I think)

Should this be part of the "Specific Options" for each system?

mvanotti avatar Oct 10 '15 07:10 mvanotti

I may add to this that on Windows there is no way to set failure actions, like restart. This is something missing from the golang.org/x/sys/windows package too.

I have a working implementation of this, I need to find the time to send a PR.

clns avatar Oct 11 '15 06:10 clns

clns, that is true, but adding it is not that hard.

The best way would be to add a function to the mgr package. It is just a syscall to ChangeServiceConfig2 with the service handle.

But as a quick solution, this can be done from inside the service package I think (only during setup, that's when we still have the service handle).

mvanotti avatar Oct 11 '15 06:10 mvanotti

This is correct.

clns avatar Oct 11 '15 06:10 clns

I would lean to leaving per system "default" behavior, but then adding knobs to set this behavior as much as possible.

Perhaps add an enum in the config "BehaviorOnNonZeroExit":

  • SystemDefault = 0
  • LeaveStopped
  • AlwaysRestart

?

kardianos avatar Oct 12 '15 16:10 kardianos

That solves my specific problem, but maybe someone wants to configure it using more specific settings supported by the system (for example, upstart lets you set the time between restarts and the amount of restart attempts)

mvanotti avatar Oct 12 '15 16:10 mvanotti

+1 to the ability to configure relaunch on crash behavior.

I would lean to leaving per system "default" behavior, but then adding knobs to set this behavior as much as possible.

I agree.

but maybe someone wants to configure it using more specific settings supported by the system

Yes. I would like control over how long to wait before restarting. Currently we have to set this in a separate .bat script on Windows and provide a manually constructed systemd file for linux.

ChrisHines avatar Oct 12 '15 16:10 ChrisHines

Hi @clns, did you have time to send the PR? Do you have a fork that has this feature implemented?

mvanotti avatar Nov 06 '15 17:11 mvanotti

@mvanotti Unfortunately I do not have a fork, I implemented this in my own code. I'll try to make some time to submit a PR.

clns avatar Nov 06 '15 18:11 clns

I might have time to look at this next week. This feature isn't a priority for me however.

kardianos avatar Nov 06 '15 20:11 kardianos

What about restarting with SystemV after server reboot? If I understand correctly library doesn't handle that right now? What are the options? Entry in /etc/inittab?:

  • https://superuser.com/a/507835/204035
  • https://www.digitalocean.com/community/tutorials/how-to-configure-a-linux-service-to-start-automatically-after-a-crash-or-reboot-part-1-practical-examples#auto-start-checklist-for-system-v

Could library automatically add entries to /etc/inittab? Would that be feasible?

arvenil avatar Dec 08 '17 14:12 arvenil

I think it handled it. Send a PR if it doesn't.

On Fri, Dec 8, 2017, 06:53 Kamil Dziedzic [email protected] wrote:

What about restarting with SystemV after server reboot? If I understand correctly library doesn't handle that right now? What are the options? Entry in /etc/inittab?:

  • https://superuser.com/a/507835/204035

https://www.digitalocean.com/community/tutorials/how-to-configure-a-linux-service-to-start-automatically-after-a-crash-or-reboot-part-1-practical-examples#auto-start-checklist-for-system-v

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/kardianos/service/issues/33#issuecomment-350282317, or mute the thread https://github.com/notifications/unsubscribe-auth/AAuFscMo9EvGWtrfDi2ZSe4x2wHCUrbtks5s-U1xgaJpZM4GMhQr .

kardianos avatar Dec 08 '17 15:12 kardianos

For anyone wondering, it was implemented via these options: https://github.com/kardianos/service/blob/master/service.go#L197-L206

vpoliakov01 avatar Mar 22 '24 17:03 vpoliakov01