lloesche / valheim-server-docker

Valheim dedicated gameserver with automatic update, World backup, BepInEx and ValheimPlus mod support
https://hub.docker.com/r/lloesche/valheim-server
Apache License 2.0
1.91k stars 269 forks source link

Valheim does not handle SIGTERM well, have supervisor use SIGINT instead #625

Closed mshade closed 1 year ago

mshade commented 1 year ago

Reference: https://valheimbugs.featureupvote.com/suggestions/159711/dedicated-server-does-not-save-world-on-sigterm

Supervisor can be told to issue SIGINT instead of SIGTERM which will allow valheim to exit cleanly and save world on shutdown. See docs here. This should be as simple as adding a section to supervisor config in the valheim-server section:

stopsignal=INT

Similarly, Dockerfile can declare a STOPSIGNAL if necessary - though supervisor may handle the shutdown properly if it knows to send SIGINT to valheim-server when supervisor itself receives a SIGTERM.

lloesche commented 1 year ago

@mshade great suggestion. I'll prepare a PR.

lloesche commented 1 year ago

Actually, I just looked at my old code again and realised that the server is already shutting down via SIGINT, so I'm not sure what this issue is about in the first place. 😄

There's an entire elaborate shutdown procedure that first sends SIGINT to the server, then waits a while for it to shutdown - if the server doesn't shut down it follows up with a SIGTERM and if that doesn't help finally a SIGKILL.

For details see: https://github.com/lloesche/valheim-server-docker/blob/192e806345e4a4a691bb3f34362954492a4a4c9b/valheim-server#L186-L214

Reverting the previous PR.

mshade commented 1 year ago

Ah - not sure how I missed that! Thanks for taking a look. I thought I got bit by this, went looking and didn't see this snippet.