Ubuntu 下通过 systemd 自动启动 TeamSpeak

Ubuntu 下通过 systemd 自动启动 TeamSpeak

我有一个 systemd 服务脚本来启动和停止 TeamSpeak。如果我手动启动和停止它,它可以正常工作,但它不会在服务器重新启动时自动启动 TeamSpeak。这是文件:

[Unit]
Description=TeamSpeak Server
Wants=network-online.target
After=syslog.target network.target nss-lookup.target network-online.target

[Service]
Type=forking
WorkingDirectory=/usr/local/bin/teamspeak3-server_linux-amd64
ExecStart=/usr/local/bin/teamspeak3-server_linux-amd64/ts3server_startscript.sh start
ExecReload=/usr/local/bin/teamspeak3-server_linux-amd64/ts3server_startscript.sh restart
ExecStop=/usr/local/bin/teamspeak3-server_linux-amd64/ts3server_startscript.sh stop
PIDFile=/usr/local/bin/teamspeak3-server_linux-amd64/ts3server.pid
User=smares
Group=smares

[Install]
WantedBy=multi-user.target

我的方舟:生存进化服务器的以下脚本运行良好:

[Unit]
Description=ARK: Survival Evolved Server
Wants=network-online.target
After=syslog.target network.target nss-lookup.target network-online.target

[Service]
ExecStart=/home/smares/Steam/games/ark/ShooterGame/Binaries/Linux/ShooterGameServer TheIsland?MaxPlayers=5?listen -server -log
LimitNOFILE=100000
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s INT $MAINPID
User=smares
Group=smares

[Install]
WantedBy=multi-user.target

我究竟做错了什么?

答案1

我在 Ubuntu Server 16.04 上设置 TeamSpeak 服务器时遇到了同样的问题,并设法使用以下 systemd 单元解决了该问题(保存到/etc/systemd/system/teamspeak3.service):

[Unit]
Description=TeamSpeak3 Server
Wants=network-online.target
After=syslog.target network.target

[Service]
WorkingDirectory=/opt/teamspeak3-server
User=teamspeak3-user
Type=forking
ExecStart=/opt/teamspeak3-server/ts3server_startscript.sh start initfile=ts3server.ini
ExecStop=/opt/teamspeak3-server/ts3server_startscript.sh stop
ExecReload=/opt/teamspeak3-server/ts3server_startscript.sh reload
PIDFile=/opt/teamspeak3-server/ts3server.pid

[Install]
WantedBy=multi-user.target

通过像这样启用此服务:

systemctl enable teamspeak3.service

由于您没有给出 的输出journalctl -u teamspeak3.service,因此很难说到底是什么问题。我还使用与您指定的相同的配置测试了我的配置After,这也有效,所以我认为问题是您未能正确启用服务,或者文件有问题.ini,因为您没有指定一个在你的ExecStart参数中。

答案2

[Unit]
Description=TeamSpeak3 Server
Wants=network-online.target
After=syslog.target network.target

[Service]
WorkingDirectory=/opt/teamspeak3
User=teamspeak
Type=simple
ExecStart=/opt/teamspeak3/ts3server

[Install]
WantedBy=multi-user.target

我发现使用效果Type=simple更好。通过这种方式,systemd 可以监控进程,并且您还可以在journalctl输出中从 teampeak 服务器获取 stdout 输出。

相关内容