Don't Starve Together

by gapple
9 deployments · 2 still active · last rev. 9 months ago

Don't Starve Together game server

Compatible with: Ubuntu 16.04 LTS
						#!/bin/bash

# <UDF name="dst_token" Label="Server Token" />
# <UDF name="dst_name" Label="Server Name" />
# <UDF name="dst_description" Label="Server Description" default="" />
# <UDF name="dst_game_mode" Label="Game Mode" oneOf="survival,endless,wilderness" default="survival" />
# <UDF name="dst_intention" Label="Intention" oneOf="cooperative,competitive,social,madness" default="cooperative" />
# <UDF name="dst_pvp" Label="PvP" oneOf="false,true" default="false" />
# <UDF name="dst_pause_when_empty" Label="Pause world when empty" oneOf="true,false" default="true" />
# <UDF name="dst_cluster_pass" Label="Server Password" default="" />

export DEBIAN_FRONTEND=noninteractive

apt-get update
apt-get -y upgrade
apt-get -y install debconf-utils
echo steamcmd steam/license note | debconf-set-selections
echo steamcmd steam/question select I AGREE | debconf-set-selections
apt-get -y install steamcmd libcurl4-gnutls-dev:i386
useradd -m dst

su dst steamcmd +login anonymous +app_update 343050 validate +quit

sudo -u dst mkdir -p /home/dst/.klei/DoNotStarveTogether/Cluster_1
sudo -u dst cat >> /home/dst/.klei/DoNotStarveTogether/Cluster_1/cluster_token.txt <<EOD
${DST_TOKEN}
EOD

sudo -u dst cat >> /home/dst/.klei/DoNotStarveTogether/Cluster_1/cluster.ini <<EOD
[GAMEPLAY]
game_mode = ${DST_GAME_MODE}
max_players = 8
pvp = ${DST_PVP}
pause_when_empty = ${DST_PAUSE_WHEN_EMPTY}

[NETWORK]
lan_only_cluster = false
cluster_intention = ${DST_INTENTION}
cluster_name = ${DST_NAME}
cluster_description = ${DST_DESC}
offline_cluster = false
cluster_password = ${DST_CLUSTER_PASS}
whitelist_slots = 1

[MISC]
console_enabled = true

[SHARD]
shard_enabled = true
bind_ip = 127.0.0.1
master_ip = 127.0.0.1
master_port = 10888
cluster_key = 
EOD

sudo -u dst mkdir -p /home/dst/.klei/DoNotStarveTogether/Cluster_1/Master
sudo -u dst cat >> /home/dst/.klei/DoNotStarveTogether/Cluster_1/Master/server.ini <<EOD
[Shard]
is_master = true
name = Master

[Steam]
authentication_port = 8766
master_server_port = 27016


[NETWORK]
server_port = 11001
EOD

sudo -u dst mkdir -p /home/dst/.klei/DoNotStarveTogether/Cluster_1/Caves
sudo -u dst cat >> /home/dst/.klei/DoNotStarveTogether/Cluster_1/Caves/server.ini <<EOD
[Shard]
is_master = false
name = Caves

[Steam]
authentication_port = 8767
master_server_port = 27017


[NETWORK]
server_port = 11002
EOD

sudo -u dst cat >> /home/dst/.klei/DoNotStarveTogether/Cluster_1/Caves/worldgenoverride.lua <<EOD
return {
  override_enabled = true,
  preset = "DST_CAVE",
}
EOD

###########
# SystemD #
###########

cat >> /etc/systemd/system/dst_master.service <<EOD
[Unit]
Description=Don't Starve Master Server
After=network-online.target
Requires=network-online.target

[Service]
User=dst
WorkingDirectory=/home/dst/.steam/SteamApps/common/Don't Starve Together Dedicated Server/bin
# ExecStart has issues with special characters in command paths, which /usr/bin/env handles
ExecStart=/usr/bin/env "/home/dst/.steam/SteamApps/common/Don't Starve Together Dedicated Server/bin/dontstarve_dedicated_server_nullrenderer" -cluster Cluster_1 -shard Master

[Install]
WantedBy=multi-user.target
EOD

cat >> /etc/systemd/system/dst_caves.service <<EOD
[Unit]
Description=Don't Starve Caves Server
After=network-online.target
Requires=network-online.target

[Service]
User=dst
WorkingDirectory=/home/dst/.steam/SteamApps/common/Don't Starve Together Dedicated Server/bin
# ExecStart has issues with special characters in command paths, which /usr/bin/env handles
ExecStart=/usr/bin/env "/home/dst/.steam/SteamApps/common/Don't Starve Together Dedicated Server/bin/dontstarve_dedicated_server_nullrenderer" -cluster Cluster_1 -shard Caves

[Install]
WantedBy=multi-user.target
EOD

cat >> /etc/systemd/system/dst_restart.service <<EOD
[Unit]
Description=Restart Don't Starve servers
Requires=network-online.target

[Service]
Type=oneshot
ExecStart=/bin/systemctl stop dst_master.service
ExecStart=/bin/systemctl stop dst_caves.service
ExecStart=/bin/systemctl start dst_master.service
ExecStart=/bin/systemctl start dst_caves.service
EOD

cat >> /etc/systemd/system/dst_updated.path <<EOD
[Unit]
Description=Watch for Don't Starve application update
Requires=network-online.target

[Path]
PathChanged=/home/dst/.steam/SteamApps/common/Don't Starve Together Dedicated Server/version.txt
Unit=dst_restart.service

[Install]
WantedBy=paths.target
EOD

cat >> /etc/systemd/system/dst_update.service <<EOD
[Unit]
Description=Check for Don't Starve Application Updates
Requires=network-online.target

[Service]
User=dst
WorkingDirectory=/home/dst
ExecStart=/usr/games/steamcmd +login anonymous +app_update 343050 validate +quit
EOD

cat >> /etc/systemd/system/dst_update.timer <<EOD
[Unit]
Description=Check for Don't Starve Application updates
Requires=network-online.target

[Timer]
# Daily at 9am
OnCalendar=*-*-* 09:00:00
Persistent=True
Unit=dst_update.service

[Install]
WantedBy=timers.target
EOD

systemctl enable dst_master.service
systemctl enable dst_caves.service
systemctl enable dst_update.timer
systemctl enable dst_updated.path


systemctl start dst_master.service
systemctl start dst_caves.service
systemctl start dst_update.timer
systemctl start dst_updated.path