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

Add graceful shutdown to systemd unit #260

Open
bharrisau opened this issue Feb 20, 2024 · 4 comments
Open

Add graceful shutdown to systemd unit #260

bharrisau opened this issue Feb 20, 2024 · 4 comments

Comments

@bharrisau
Copy link
Contributor

It's a bit hacky to get around the lack of asynchronous stop commands. But I've got something like this to give a 5 minute window to the process to finish any remaining work.

[Service]
ExecStart=/home/fishnet/fishnet --auto-update --conf /home/fishnet/fishnet.ini run
ExecStop=/bin/kill -INT "$MAINPID"
ExecStop=/usr/bin/sh -c 'while kill -0 "$MAINPID" 2>/dev/null; do sleep 1; done'
KillMode=mixed
TimeoutStopSec=300
@niklasf
Copy link
Member

niklasf commented Feb 21, 2024

Generally such long timeouts for shutdown are not acceptable, so instead the default KillSignal=SIGTERM is used. This will cause a somewhat graceful shutdown, i.e., work won't be completed, but the server is notified.

The hack above can be simplified to:

KillMode=mixed
KillSignal=SIGINT
TimeoutStopSec=300

@bharrisau
Copy link
Contributor Author

bharrisau commented Feb 22, 2024 via email

@niklasf
Copy link
Member

niklasf commented Feb 23, 2024

Ah, interesting. I didn't realize how nicely your snippet works: So it's immediate SIGINT, SIGTERM after the timeout, and then eventually SIGKILL if something went wrong?

@bharrisau
Copy link
Contributor Author

bharrisau commented Feb 23, 2024 via email

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

No branches or pull requests

2 participants