Running on Boot

Using systemd

systemd is the default init system for most modern distros.
You need to create a service file in /etc/systemd/system/
Example ts3server.service
1
[Unit]
2
Description=LinuxGSM Teamspeak3 Server
3
After=network-online.target
4
Wants=network-online.target
5
​
6
[Service]
7
Type=forking
8
User=ts3server
9
WorkingDirectory=/home/ts3server
10
RemainAfterExit=yes #Assume that the service is running after main process exits with code 0
11
ExecStart=/home/ts3server/ts3server start
12
ExecStop=/home/ts3server/ts3server stop
13
Restart=no
14
​
15
[Install]
16
WantedBy=multi-user.target
Copied!
Replace the user and paths to fit your setup.
You need to reload the systemd-daemon once to make it aware of the new service file by systemctl daemon-reload
Now you can do
1
systemctl start ts3server # Start the server
2
systemctl stop ts3server # Stop the server
3
systemctl enable ts3server # Enable start on boot
4
systemctl disable ts3server # Disable start on boot
Copied!

Crontab

The crontab will allow you to create cronjobs that allow you to run a command on a set time or on boot. The below example uses @reboot that will run a command on boot.
1
@reboot '/home/username/gameserver monitor' > /dev/null 2>&1
Copied!
Most admins will also have a timed monitor cronjob configured. If you do not want to have extra cronjobs the timed monitor will also start a server but with a timed delay.

Using monitor command

After a reboot, any game server that has a "started" status will be started on boot. Servers that were manually stopped will remain stopped.
1
crontab -e
2
@reboot su - username -c '/home/username/gameserver monitor' > /dev/null 2>&1
Copied!
To learn more, see cronjobs and automated monitoring.

Using start command

Start a game server unconditionally, even if you manually stop a server.
1
crontab -e
2
@reboot su - username -c '/home/username/gameserver start' > /dev/null 2>&1
Copied!
To learn more, see Start-Stop-Restart​

rc.local

rc.local is another method to run scripts on boot. Any commands added to the rc.local file will run on boot.
1
nano /etc/rc.local
2
su - username -c '/home/username/gameserver start'
Copied!