This article may contain instructional language and subjective recommendations. Readers should read the content carefully, and follow accordingly. |
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
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. I named the file "start_dst" for my own reference you may change it "name".sh with out the quotes.
Create the file:
sudo vim /etc/init.d/start_dst.sh
Script:
!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/
updates the file to be excutable:
sudo chmod +x start_dst.sh
allow the script to run on boot:
sudo update-rc.d start_dst.sh defaults
I used the script supplied on this page for reference modifying the INIT information to point to the appropriate directories for DST. https://wiki.teamfortress.com/wiki/Linux_dedicated_server