Open Molorius opened 5 years ago
Hey @Molorius I tried some ideas but unfortunately didn't manage to make it work. I remember this is something I wanted to implement long ago, i.e. create a stop.sh
script that would do a clean shutdown saving the game, but never got it to work.
docker attach
seems a bit limited as it works only in a very specific way (interactively). Tried with docker exec
, which spawns another process in the container (e.g. another bash
), but couldn't attach tty or send the c_shutdown()
signal to the running proccess, dontstarve_dedicated_server_nullrenderer
.
What I usually do when playing is to manually shut it down if I'm the last player to leave through the game console directly. It's still a manual process, but quicker.
Let's leave the issue open, if we ever come around a solution we can share it here as I believe more people would benefit from it :nerd_face:
I got it to work using socat.
echo "c_shutdown()" | socat EXEC:"docker attach dst_master",pty STDIO
By putting that in a "my_shutdown.sh" script, I also got a working systemd file:
[Unit]
Description=Don't Starve Together Server
After=docker.service
After=network.service
[Service]
Type=oneshot
RemainAfterExit=yes
User={user you want starting this container}
WorkingDirectory={your working directory here}
ExecStart=docker-compose up -d
ExecStop=/bin/bash my_shutdown.sh
[Install]
WantedBy=multi-user.target
Host OS: Arch Linux Local Computer
This isn't an issue so much as a help request. I am starting my server using systemd, but want to be able to cleanly close it without attaching to the docker session and sending 'c_shutdown()'. You can't do a simple
docker exec
because it's part of an interactive shell, not a direct command. I found this possible solution, so I sent:But I get the error:
I'm not familiar with docker, is there another way I can pipe the command into the session?