-
-
Notifications
You must be signed in to change notification settings - Fork 61
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
Add support for exit callback/cleanup script #129
Comments
I currently have a PoC that might be a candidate for this. A new keyword 'on_term' can be added to a service config line with the following syntax: on_term:</absolut/path/to/script> If on_term is set, and the path points to an existing file, that file is assumed to be an executable script. This script is then run, being put in the background with a system() call with & appended to the command line to ensure finit itself is not locked up in case the script behaves poorly. Currently, this call is made in the following functions: service_kill() and service_stop() service_step My experience with finit thus far is quite limited so there are certainly quite a few improvements to be made. Limited testing has been done with a dummy script on an embedded target which verifies that the PoC in its current form works as expected in the simple cases, namely
The PoC is currently based on finit 3.1 with additional in-house patches but I will create a proper branch ASAP based on master. |
I have created a branch here for the PoC. |
Looks promising. There are a few things I dislike, from cosmetic to design:
|
Sorry for the delayed response. Thanks for the excellent feedback.
Lastly, two things I am pondering: a) Should a service be prevented from restarting until the post-script has finished (or been terminated due to timeout)? b) If post-script is run on SIGKILL, SIGSEGV, SIGPIPE, etc, would it be of interest to have the option to execute a clean exit script? For instance, exit-script:/path/to/script would be run on SIGTERM. Or is this putting too much responsibility on finit? Will contemplate over all this for a bit and see if I arrive at anything codewise. 😄 |
I see, well https://www.freedesktop.org/software/systemd/man/systemd.service.html#ExecStopPost= defines its action as always run when the process is stopped. Meaning the commands/script executed must be able to handle cases when the process didn't even start properly. So I'm not sure there is any added value to only running cleanup scripts on crashes. All processes that exit land in So to answer your questions:
|
Similar to the systemd
ExecStopPost=
. Sometimes useful for services not cleaning up after themselves, or crashing.The text was updated successfully, but these errors were encountered: