dst-dedicated-server icon indicating copy to clipboard operation
dst-dedicated-server copied to clipboard

Help with clean shutdown command

Open Molorius opened this issue 6 years ago • 2 comments

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:

echo "c_shutdown()" | docker attach dst_master

But I get the error:

the input device is not a TTY

I'm not familiar with docker, is there another way I can pipe the command into the session?

Molorius avatar Dec 27 '18 21:12 Molorius

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:

mathielo avatar Dec 30 '18 09:12 mathielo

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

Molorius avatar Jan 17 '19 21:01 Molorius