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

Clean shutdown #4

Open
bdr99 opened this issue May 17, 2020 · 9 comments
Open

Clean shutdown #4

bdr99 opened this issue May 17, 2020 · 9 comments

Comments

@bdr99
Copy link

bdr99 commented May 17, 2020

When I stop this container, does it perform a clean shutdown of the server? In other words, does it command the Terraria server to save the world file before killing the process? Or is it possible that world data could be lost upon stopping the container if the world file was not saved recently?

If not, then can the container be modified to include this feature so that world data will not be lost?

docker-compose config:

version: '3.5'
services:
  terraria:
    image: beardedio/terraria
    container_name: terraria
    environment:
      - world=world.wld
    ports:
      - 7777:7777
    volumes:
      - ./config:/config
    restart: unless-stopped
    stdin_open: true
    tty: true
@JustinGrote
Copy link

The world definitely saves periodically, and as far as I can tell as long as I do a "soft" shutdown of the container it saves the world before exit.

@hskrtich
Copy link
Contributor

The container is just a wrapper for the server code itself. So how ever the server handles a shutdown is how that works. I assume it will attempt to send a normal shutdown command and it should only issue a kill command if the process doesn't close in a certin amount of time.

@hskrtich
Copy link
Contributor

After some testing I dont think ether Vanilla or Tshock will do a save before closing. I will re-open this and see if I can add it to the startup script. Tho It may take a while.

@hskrtich hskrtich reopened this May 19, 2020
@bdr99
Copy link
Author

bdr99 commented May 19, 2020

Thanks for looking into this! Based on my own testing, I agree. It doesn't seem to do a save before closing, it seems to just kill the process. It would be nice if we could send the "exit" command (which saves and exits the server) to the Terraria server process when the container is stopped.

@AustinMcPhail
Copy link

How is this looking? Came across this the other day and was super happy to see it being talked about. Was interested in trying my hand at it, but if it is already in the works or anything then I'll leave it to whomever.

@lpeabody
Copy link

Super subscribed! Appreciate the work on this.

@hskrtich
Copy link
Contributor

@AustinMcPhail I have not had time to work on this feature, feel free to take a crack at it.

@kevinkjt2000
Copy link

kevinkjt2000 commented May 24, 2020

I was looking at this too, and think it should be possible to install screen into the container for running the server. There is an AUR package that uses screen as part of running as a systemd service https://aur.archlinux.org/cgit/aur.git/tree/[email protected]?h=terraria-server

The relevant bits are:e

# Screen is used, because the terraria server binary crashes if called on its own.
ExecStart=/usr/bin/screen -DmS terraria-server-%i /usr/bin/terraria-server -config /opt/terraria-server/%i.conf
# Send a warning message to all players and the exit command through screen to let the program terminate itself gracefully
ExecStop=/usr/bin/screen -S terraria-server-%i -X stuff "say Server shutting down. Saving world.\015"
ExecStop=/usr/bin/screen -S terraria-server-%i -X stuff "exit\015"

I bet this could be adapted into a startup script for docker, so I am going to give this a try today.

Edit: I give up; all this pseudo TTY attach stuff is outside of my expertise.

@Noutbuk
Copy link

Noutbuk commented May 27, 2020

I finally settled with the following scripts: https://gist.github.com/Noutbuk/85d455a90fa68862c9437678f89d27d7
I don't know if this is the recommended way, but works well for a small server with some friends.
Maybe they are useful for some of you as well.

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

No branches or pull requests

7 participants