-
Notifications
You must be signed in to change notification settings - Fork 678
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
service(windows): add support for PreShutdown #257
base: master
Are you sure you want to change the base?
Conversation
@kardianos for additional context, we need this for GitLab's Runner. Runner has jobs running that we don't immediately want to terminate, some of them can take a really long time, so ideally we'd want to block until they're complete. |
The defaults aren't good here. Maybe could add a configuration options, but not 5 min timeout by default. |
What 5 minute timeout are you referring to? If it's the above |
This is exactly the PR that I have been looking for! I have a cleanup service that needs to happen and may take up to a few minutes to fully complete. Being able to setup the PreShutdownInfo seems like the correct solution from MS. I was doing research into this so here are some additional docs for @kardianos in case context is needed. Talking about allowing windows services and how to allow for longer shutdown times, this talks about globally and per-service (PreShutdownTimeout). MS page on the SERVICE_PRESHUTDOWN_INFO struct: https://learn.microsoft.com/en-us/windows/win32/api/winsvc/ns-winsvc-service_preshutdown_info. Thank you @saracen for proposing this! |
If it makes it any easier, I have done a rebase of this code on top of master so that there are no conflicts. You can see that branch here: https://github.com/Ahuge/service/tree/ah/feature/windows-preshutdown |
@kardianos I've resolved the merge conflicts with this one. Please see my previous comment in regards to the 5 minute default concern. |
Is there a specific code I can run in this PreShutDown state? So I can add a log like "entering preshutdown" ? |
This adds support for
PreShutdown
as described here.This allows multiple "StopPending" state updates to let Windows know that a service is still shutting down, incrementing a "CheckPoint" to let WIndows know progress is being made. By default, this extends the timeout for stopping a service to 3 minutes.
If more than 3 minutes are required (a database that absolutely requires more time to avoid corruption, for example), the time can be additionally extended by setting the
PreshutdownTimeout
option during installation of the service.Modified
stopPause
as an example:Without
PreshutdownTimeout
,Stop()
will only survive 3 minutes. With PreshutdownTimeout extended to an hour,Stop()
will exit after 5 minutes.