Skip to content
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

Implement oncrash:script feature #282

Closed
hongkongkiwi opened this issue Jun 1, 2022 · 3 comments
Closed

Implement oncrash:script feature #282

hongkongkiwi opened this issue Jun 1, 2022 · 3 comments
Milestone

Comments

@hongkongkiwi
Copy link
Contributor

I would like to be able to use the oncrash option to run a script in this specific case. I think this is more useful than restarting because you can do some logging or other tasks before requesting a restart.

Is this possibly on the list for 4.4?

@troglobit
Copy link
Owner

Interesting! Maybe we can reuse the post:script feature? I'm thinking we extend it with EXIT_CODE=crashing.

Since the service state machine needs to be reworked, adding this should not be too much extra effort.

@troglobit troglobit added this to the 4.4 milestone Jun 1, 2022
@hongkongkiwi
Copy link
Contributor Author

Yea, I was thinking that it could work in exactly that way.

I do think it might be valuable to know the EXIT_CODE of the script though, that might tell the script information of why it crashed (sometimes). It might make sense to set another variable? e.g. SERVICE_CRASHED="yes" maybe?

@troglobit
Copy link
Owner

From the current manual, EXIT_CODE is already used like this (naming is what it is, unfortunately):

The scripts are not called with any argument (currently), but both get the
SERVICE_IDENT=foo environment variable set. Here foo denotes the
identity of the service, which if there are multiple services named foo,
may be foo:1, or any unique identifier specified in the .conf file. The
post:script is called with an additional set of environment variables:

  • EXIT_CODE=[exited,signal]: set to one of exited or signal
  • EXIT_STATUS=[num,SIGNAME]: set to one of exit status code from
    the program, if it exited normally, or the signal name (HUP,
    TERM, etc.) if it exited due to signal

My idea was adding crashing (or crashed) so that you can set up a switch case of $EXIT_CODE to handle the various cases. This way you could use the same script for handling pre/post setup and teardown, and now also crashing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants