2

I have two upstart scripts, one to start the teamspeak server and one to start the teamspeak bot as showed below.

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

I wonder if it's possible to excecute the tsbot.service script only after the teamspeak.service has been successfully started, I tried adding After=network.target teamspeak.service to the script but that did not work.

  • I presume you meant you edited tsbot.service? Did you remember to do sudo systemctl daemon-reload after the edit? – meuh Aug 17 '16 at 18:46
  • @meuh I edited the tsbot.service and reloaded the systemctl daemon but that did not work – josephzigler Aug 18 '16 at 8:09
  • With Type=forking systemd assumes that when your ts3server_startscript.sh returns it has finished setting up things adequately so that systemd can now run any dependency, like tsbot. Is that the case? Or does the script ts3server_startscript.sh run a daemon and return immediately, so that the daemon has not even had a chance to start before systemd runs tsbot? – meuh Aug 18 '16 at 8:20
0

I don't have any hands-on experience with upstart so apologies if the upstart syntax is wrong but the actual bash script should be solid. All it does is loop around, checking if the teamspeak service is running (waiting 5 seconds between checks) before starting the tsbot service.

script
while true; do    
    if [[ $(pgrep teamspeak) ]]; then
        systemctl start tsbot.service
        break
    fi
    sleep 5
done
end script

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.