玟茵开源社区知识库

如果您有自己的想法或者金点子,请提交给我们或直接参与项目,在此欢迎各位,您的反馈是我们持续前进的动力。
  1. 首页
  2. 天下杂谈
  3. 正文

Linux Game Server Running on Boot

2020年3月6日 316点热度 0人点赞 0条评论

文章目录[隐藏]

  • Using systemd
  • Crontab
    • Using monitor command
    • Using start command
  • rc.local

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

[Unit]
Description=LinuxGSM Teamspeak3 Server
After=network-online.target
Wants=network-online.target
​
[Service]
Type=forking
User=ts3server
WorkingDirectory=/home/ts3server
ExecStart=/home/ts3server/ts3server start
ExecStop=/home/ts3server/ts3server stop
Restart=no
RemainAfterExit=yes   #Assume that the service is running after main process exits with code 0
​
[Install]
WantedBy=multi-user.target

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:

sudo systemctl start ts3server # Start the server
sudo systemctl stop ts3server  # Stop the server
sudo systemctl enable ts3server # Enable start on boot
sudo systemctl disable ts3server # Disable start on boot

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 examples uses @reboot that will run a command on boot.

    @reboot '/home/username/gameserver monitor' > /dev/null 2>&1

note: 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.

crontab -e@reboot su - username -c '/home/username/gameserver monitor' > /dev/null 2>&1

To learn more, see cronjobs and automated monitoring.

Using start command

Start a game server unconditionally, even if you manually stopped a server.

crontab -e@reboot su - username -c '/home/username/gameserver start' > /dev/null 2>&1

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.

nano /etc/rc.localsu - username -c '/home/username/gameserver start'

本作品采用 知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议 进行许可
标签: gameserver Linux systemd
最后更新:2020年4月6日

WenYinOS

这个人很懒,什么都没留下

点赞
< 上一篇
下一篇 >

文章评论

razz evil exclaim smile redface biggrin eek confused idea lol mad twisted rolleyes wink cool arrow neutral cry mrgreen drooling persevering
取消回复

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理。

COPYLEFT © 2023 玟茵开源社区知识库. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang