Don't Starve Together

Don't Starve Together

Not enough ratings
Automatically Start Dedicated Server after reboot (Linux)
By Citizen Billy
This guide is intended to help setup a script to automatically start your dedicated server in the event the host is rebooted.
Many of the refences that were used for directories are based on the Dedicated server setup process detailed here. Dedicated Server Setup Guide Wikia[dont-starve-game.wikia.com]
   
Award
Favorite
Favorited
Unfavorite
Setup
The following is a script that can be used to start a dedicated server on boot/reboot of the host. This was setup after noticing my Ubuntu Server 14.0 had rebooted after updates which in-turn killed the DST dedicated server.

If you have not yet setup a dedicated server on a Linux machine I would recommend using the following as reference. This was used to setup DST on my Linux server: http://dont-starve-game.wikia.com/wiki/Guides/Simple_Dedicated_Server_Setup

Depending on your personal preference, I would suggest adding the following line under [network] in settings.ini to pause the server if no users is connected. Otherwise your DST world will continue regardless if anyone is connected.
pause_when_empty = true

As a final note you'll want to likely create a backup of your exsisting script if you intend on modifying an existing one.

You'll need to create the file in your /etc/init.d/ directory (command supplied below). If you followed the above guide then the directories should be the same. Otherwise review the INIT info as well as the directories which you need to reference inorder for screen to start your server. I named the file "start_dst" for my own reference you may change it "name".sh with out the quotes.You may also use nano in place of vim its all preference.

Create the file:
sudo vim /etc/init.d/start_dst.sh
----

!i/bin/sh ##BEGIN INIT INFO # Provides:dst # Short-Description: Don't starve server # Description: Starts a Dont Starve Together server ### END INIT INFO NAME="Dont Starve together" #The user that you installed DST server as USER="steam" SCREENREF="DST" #should be the same as the dedicated server's install directory BINARYPATH="/home/steam/steamapps/DST/bin" BINARYNAME="dontstarve_dedicated_server_nullrenderer" PIDFILE="dstserver.pid" cd "$BINARYPATH" running() { if [ -n "`pgrep -f $BINARYNAME`" ]; then return 0 else return 1 fi } start() { if ! running; then echo -n "Starting the $NAME server... " start-stop-daemon --start --chuid $USER --user $USER --chdir $BINARYPATH --exec "/usr/bin/screen" -- -dmS $SCREENREF $BINARYPATH pgrep -f $BINARYNAME > $PIDFILE if [ -s $PIDFILE ]; then echo "Done" else echo "Failed" rm $PIDFILE fi else echo "The $NAME server is already started." fi } stop() { if running; then echo -n "Stopping the $NAME server... " kill `cat $PIDFILE` while running; do sleep 1 done rm $PIDFILE echo "Done" else echo "The $NAME server is already stopped." fi } case "$1" in start) start ;; stop) stop ;; restart) stop start ;; status) if running; then echo "The $NAME server is started." else echo "The $NAME server is stopped." fi ;; *) echo "Usage: $0 (start|stop|restart|status)" exit 1 esac exit 0

Navigate to the directory you created the file ealrier.
cd /etc/init.d/

Set the script to be excutable:
sudo chmod +x start_dst.sh

Allows the script to run on boot:
sudo update-rc.d start_dst.sh defaultsp

At this point you should be all set. You in the event that you need to restart your DST server you can alway use the standard linux command start and stop the server.

Manually Start
sudo /etc/init.d/start_dst.sh start

Status (verify if running)
sudo /etc/init.d/start_dst.sh status

Manually Stop
sudo /etc/init.d/start_dst.sh stop

Manually Restart
sudo /etc/init.d/start_dst.sh restart

2 Comments
Citizen Billy  [author] Feb 6, 2018 @ 4:24pm 
I need to update this guide. At the time I had used screen for starting the server, because without running this as a background service or via screen would cause the process to halt whenn closing the session (was accessing the host via putty)
_|R3ko Feb 6, 2018 @ 2:57am 
pourquoi utiliser screen pour un service ?