service
service copied to clipboard
Relaunch on crash should be consistent among systems or configurable.
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?
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, 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).
This is correct.
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
?
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)
+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.
Hi @clns, did you have time to send the PR? Do you have a fork that has this feature implemented?
@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.
I might have time to look at this next week. This feature isn't a priority for me however.
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?
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 .
For anyone wondering, it was implemented via these options: https://github.com/kardianos/service/blob/master/service.go#L197-L206