Skip to content

Handle SIGTERM by saving world and shutting down gracefully#30

Open
chrisjoj wants to merge 1 commit into
beardedio:mainfrom
chrisjoj:handle-shutdown
Open

Handle SIGTERM by saving world and shutting down gracefully#30
chrisjoj wants to merge 1 commit into
beardedio:mainfrom
chrisjoj:handle-shutdown

Conversation

@chrisjoj

@chrisjoj chrisjoj commented Apr 2, 2021

Copy link
Copy Markdown

This is an initial attempt at a way to handle restarts and shutdowns gracefully as a resolution for #4

It does this by sending the 'exit' command to the TerrariaServer stdin which saves the world and shuts down the server.
It was based on https://github.com/alexivkin/terraria-server-container/blob/master/buildcontext/serverwatcher.sh

I've tested this with vanilla-1.4.2.1. If this looks like a good approach, I can do some testing with TShock to see if a similar approach would work for those images.


echo "Starting container, CMD: $CMD $@"
exec $CMD $@
(tail -f > /vanilla/console & $CMD $@ < console) &

@meonkeys meonkeys Feb 26, 2024

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

console does not exist. Should that be /vanilla/console?

@meonkeys

Copy link
Copy Markdown

Nice, thanks! Works for me after fixing the one console typo on line 60. Some feedback:

  1. I'd appreciate some comments around the more esoteric Bash code (maybe what is esoteric Bash is just convention to a more experienced Bash programmer).
  2. After applying this patch I'm unable to attach to the container and issue commands to the server. We could maybe clean it up with more (named) pipes.

I could maintain this with great comments and a good deal of study or if it were in Python.

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants