linux – 在指定的服务运行后执行Upstart脚本
作者:互联网
我有两个upstart脚本,一个用于启动teamspeak服务器,另一个用于启动teamspeak bot,如下所示.
teamspeak.service:
[Unit]
Description=Teamspeak Server
After=network.target
[Service]
WorkingDirectory=/home/teamspeak/
User=teamspeak
Group=teamspeak
Type=forking
ExecStart=/home/teamspeak/ts3server_startscript.sh start
ExecStop=/home/teamspeak/ts3server_startscript.sh stop
ExecReload=/home/teamspeak/ts3server_startscript.sh restart
PIDFile=/home/teamspeak/ts3server.pid
RestartSec=15
Restart=always
[Install]
WantedBy=multi-user.target
tsbot.service
[Unit]
Description=Teamspeak Bot
After=network.target
[Service]
WorkingDirectory=/home/tsbot/
User=tsbot
Group=tsbot
Type=forking
ExecStart=/home/tsbot/jts3servermod_startscript.sh start
ExecStop=//home/tsbot/jts3servermod_startscript.sh stop
ExecReload=/home/tsbot/jts3servermod_startscript.sh restart
PIDFile=/home/tsbot/jts3servermod.pid
RestartSec=15
Restart=always
[Install]
WantedBy=multi-user.target
我想知道只有在teamspeak.service成功启动之后才能执行tsbot.service脚本,我尝试将After = network.target teamspeak.service添加到脚本但是没有用.
解决方法:
如果upstart语法错误但实际的bash脚本应该是可靠的,那么我对upstart没有任何亲身体验,所以道歉.所有这一切都是循环,在启动tsbot服务之前检查teamspeak服务是否正在运行(在检查之间等待5秒).
script
while true; do
if [[ $(pgrep teamspeak) ]]; then
systemctl start tsbot.service
break
fi
sleep 5
done
end script
标签:upstart,linux 来源: https://codeday.me/bug/20190815/1661974.html