Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Help with clean shutdown command #13

Open
Molorius opened this issue Dec 27, 2018 · 2 comments
Open

Help with clean shutdown command #13

Molorius opened this issue Dec 27, 2018 · 2 comments
Labels

Comments

@Molorius
Copy link

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?

@mathielo
Copy link
Owner

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 🤓

@Molorius
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants