JACOBSMILE / tmodloader1.4

An easy to configure Docker Image for tModLoader 1.4 servers.
Other
120 stars 29 forks source link

Graceful shutdown timeout #32

Closed CatEricka closed 1 year ago

CatEricka commented 1 year ago

After several server restarts I noticed these:

...
tModLoader is launching with the following command:
/terraria-server/LaunchUtils/ScriptCaller.sh -server -steamworkshopfolder "/data/mods/steamapps/workshop" -config "/terraria-server/serverconfig.txt"
mkfifo: cannot create fifo '/tmp/tmod.pipe': File exists
You are on platform: "Linux"
Verifying .NET....
This may take a few moments.
...

and when I shutdown the server I got this in logs:

...
say shutdown...
: <Server> shutdown...
exit
: Saving before exit...

and this after command:

$ podman stop tmodloader-server 
WARN[0010] StopSignal SIGTERM failed to stop container tmodloader-server in 10 seconds, resorting to SIGKILL 
tmodloader-tmodloader-server

~I think the difference between these may be the cause of the problem:~ It's irrelevant.

https://github.com/JACOBSMILE/tmodloader1.4/blob/ed964c4c6fe3c0c99f32de7c847b59cbc23f26ea/entrypoint.sh#L99

https://github.com/rfvgyhn/tmodloader-docker/blob/b7715d98669ed1f2e1d7cca1e5b5520869a357d5/entrypoint.sh#L34

JACOBSMILE commented 1 year ago

Can you try increasing the wait time for podman to do a SIGKILL? podman stop --time 30 tmodloader-server or podman stop --time 60 tmodloader-server.

Depending what the server is doing at the moment, it may not have enough time in 10 seconds to gracefully shutdown.

CatEricka commented 1 year ago

Command:

$ podman stop --time 60 tmodloader-server

Log:

...
say shutdown...
: <Server> shutdown...
Network is unreachable (see server.log for full trace)
exit
: Saving before exit...
no server running on /tmp/tmux-0/default
no server running on /tmp/tmux-0/default
pgrep: not a number: Main

I tried to use the inject command to exit directly, and it only takes a few seconds.

CatEricka commented 1 year ago

I'm not sure, it seems the server did saved (according to the file timestamp), but the container still timeout in response to SIGTERM...

CatEricka commented 1 year ago
root@tmodloader:/terraria-server# ps -aef --forest | more  
UID          PID    PPID  C STIME TTY          TIME CMD
root          33       0  0 15:40 pts/0    00:00:00 bash
root         332      33  0 15:52 pts/0    00:00:00  \_ ps -aef --forest
root         333      33  0 15:52 pts/0    00:00:00  \_ more
root           1       0  0 15:40 ?        00:00:00 /bin/bash /terraria-server/./entrypoint.sh
root         114       1  0 15:41 ?        00:00:00 /bin/sh /terraria-server/autosave.sh
root         299     114  0 15:51 ?        00:00:00  \_ sleep 10m
root         118       1  0 15:41 ?        00:00:00 tmux new-session -d /terraria-server/LaunchUtils/ScriptCaller.sh -server -steamworkshopfolder "/data/mods/steamapps/workshop" -config "/terraria-server/serverconfig.txt" | tee /tmp/tmod.pipe
root         121     118  0 15:41 pts/1    00:00:00  \_ bash -c /terraria-server/LaunchUtils/ScriptCaller.sh -server -steamworkshopfolder "/data/mods/steamapps/workshop" -config "/terraria-server/serverconfig.txt" | tee /tmp/tmod.pipe
root         123     121 13 15:41 pts/1    00:01:38      \_ /terraria-server/dotnet/6.0.0/dotnet tModLoader.dll  -server -steamworkshopfolder /data/mods/steamapps/workshop -config /terraria-server/serverconfig.txt
root         124     121  0 15:41 pts/1    00:00:00      \_ tee /tmp/tmod.pipe
root         120       1  0 15:41 ?        00:00:00 cat /tmp/tmod.pipe

root@tmodloader:/terraria-server# pgrep tmux
118

root@tmodloader:/terraria-server# pgrep --parent 118 Main

root@tmodloader:/terraria-server# 

So this loop never ends:

https://github.com/JACOBSMILE/tmodloader1.4/blob/ed964c4c6fe3c0c99f32de7c847b59cbc23f26ea/entrypoint.sh#L32-L36

What does pgrep --parent 118 Main means?

CatEricka commented 1 year ago

BTW there is missing an -e:

https://github.com/JACOBSMILE/tmodloader1.4/blob/ed964c4c6fe3c0c99f32de7c847b59cbc23f26ea/entrypoint.sh#L85

CatEricka commented 1 year ago

What does pgrep --parent 118 Main means?

I'm guessing it's part of an early version tModLoader startup script.

CatEricka commented 1 year ago

Here is a patch and it works for me: #33

JACOBSMILE commented 1 year ago

Merged #33 .