Mephi00 / v-rising-wine-docker-image

MIT License
53 stars 32 forks source link

Handle signals from docker to server process for handling shutdowns #9

Closed RealityWinner closed 6 months ago

RealityWinner commented 2 years ago

Currently if you execute docker stop on the container it will be force killed after a timeout because signals are not correctly forwarded to the child VRisingServer.

Prepending exec to the final wine VRisingServer.exe should be enough. I can test and submit a PR if desired. https://github.com/Mephi00/v-rising-wine-docker-image/blob/0ce5e7bf37be14e44b61172571b8632f2efd4d1a/entrypoint.sh#L99

A more complex option is manually catching and forwarding it to the child process

_term() { 
  echo "Caught SIGTERM signal!" 
  kill -TERM "$child" 2>/dev/null
}

trap _term SIGTERM

echo "Doing some initial work...";
/bin/start/main/server --nodaemon &

child=$! 
wait "$child"
Mephi00 commented 2 years ago

I have been working on this functionality for a week now and haven't manged to shut down the server in a way for it to save the game on stop. This is definitely something I want to add, if you manage to stop the server and get it to save, please go forward and create a pull request.

RealityWinner commented 2 years ago

Wanted to follow up on this, did a bit of testing of this image and others and was not able to get it working in detached mode. The only successful scenario with interactive with tty. Which is really not the scenario I wanted because the entire point of a server is yea know a server. I'll update again if I ever figure anything out.

Mephi00 commented 2 years ago

Please beware, if you are trying to work this out, that the server has to log the stop signal. If this happens, the server also saves the game. If it doesn't happen the server wil not save the game and simple stop.

I have tried many solutions and managed to get it to stop with a kill command. I haven't managed to stop the server with a docker stop command without external access. I have however found, that killing the process group will stop the server gracefully, I haven't managed to get this behaviour to work on exit with the entrypoint script.

Thank you for looking into this and please let me know if you stumble upon an option to make this work.

RealityWinner commented 2 years ago

I have tried many solutions and managed to get it to stop with a kill command. I haven't managed to stop the server with a docker stop command without external access. I have however found, that killing the process group will stop the server gracefully, I haven't managed to get this behaviour to work on exit with the entrypoint script.

From what I understand of the docker stop command it sends SIGINT to pid 1 entrypoint.sh. Using the below will correctly trap the command and pass it to the server process.

_sig () { 
  echo "Caught signal!" 
  kill -SIGINT $(pgrep VRisingServer)
}

trap _sig SIGINT

What command specifically have you found working for killing and saving? Does it work when you are running a server manually or via docker-compose up -d?

Mephi00 commented 2 years ago

May issue so far has been that, even though I am sending a SIGINT to the server process, it isn't saving and I don't know why.

Sending a SIGINT to the servers process group (with kill -INT -$(pgrep VRisingServer), when it's running under another bash process works, but I haven't managed to trigger the OnDestroy method of the server automatically with a trap.