Recently, I have been playing a game called Don’t Starve Together with my wife. I wanted to play with setting up a dedicated server and followed the very well made guide at Don’t Starve Together Game Wikia Dedicated Server Setup
But at the end of setting things up, I didn’t like that it was being run using screen instead of a proper managed process that would start on a reboot. Since I run Cent7 on my server, it was actually super easy to get this going with systemd. I have messed with setting up init scripts before, but systemd made things way easier to get going. Below is a paste of the systemd unit file I came up with.
[Unit] Description=Don't Starve Together Server After=network.target
[Service] ExecStart=/home/steam/dontstarve/bin/dontstarve_dedicated_server_nullrenderer GuessMainPID=no Type=simple User=steam Group=steam WorkingDirectory=/home/steam/dontstarve/bin
[Install] WantedBy=multi-user.target
Most of the file is pretty self explanatory, but the main things I had to change was the Type from fork to simple, and I had to set the WorkingDirectory to where the binary was installed. For some reason, it fails to start if you don’t set that. The last thing I had to do was like a “systemctl enable dontstarve“. You may or may not have to also do a “systemctl daemon-reload“. I know I had to several times when I was making edits to the file to get it just right.
Lastly, I made a script to update it nightly and added it into cron. Below is that script:
#!/bin/bash systemctl stop dontstarve su - steam -c "/home/steam/updatedontstarve.sh" systemctl start dontstarve
And then I made one more script to send an email everyday with a list of the users that connected to the service that day. Again, this was made super simple due to journalctl. I know a lot of people are down on that part of systemctl, but I found it a bit easier to get what I wanted vs having to pull it from a normal syslog file.
#!/bin/bash /bin/journalctl --since today | grep joined | mailx -s "Today's Don't Starve Together players" root@localhost