This is my systemd service on ubuntu 16.04:
[Unit]
Description=Starts Caspar CG
[Service]
Type=forking
WorkingDirectory=/home/broadcastingza/CasparCG/Server
Environment=DISPLAY=:0
ExecStart=/bin/sh ./run.sh --watch
StandardOutput=null
Restart=on-failure
[Install]
WantedBy=multi-user.target graphical.target
EDIT: This is the output of sudo systemctl status -l
sudo systemctl status start-caspar.service -l
● start-caspar.service - Starts Caspar CG
Loaded: loaded (/etc/systemd/system/start-caspar.service; enabled; vendor preset: enabled)
Active: inactive (dead) since Tue 2017-03-21 17:04:28 SAST; 1 day 16h ago
Process: 5198 ExecStart=/bin/bash -c ./run.sh --watch (code=exited, status=0/SUCCESS)
Mar 21 17:04:14 ZAPS001 systemd[1]: Starting Starts Caspar CG...
Mar 21 17:04:28 ZAPS001 systemd[1]: Started Starts Caspar CG.
This service gets enabled and runs fine. No problems with starting it manually either. The only issue I'm having is that as soon as the shell script runs ("run.sh"), the server it starts up then receives an EXIT signal, and exits with EXIT code 0. It's almost as if the server requires the console to be open all the time.
When I run the exact same script from the console it runs perfectly fine.
Is there a way to start the service without exiting the console immediately, or is there a way to start the service independent of the console in the first place?
sudo systemctl status <yourservice> -l
? – 13dimitar Mar 23 '17 at 07:43StandardOutput=
line and check for messages from your command. If you want to use the X11 display you may need to set more in the environment, and wait longer for X11 to be ready. – meuh Mar 23 '17 at 12:00I know that it's not a matter of waiting for the X11 display to start, because even after logging in and starting the service manually through the terminal emulator, I have the same problem.
– string theorist Mar 23 '17 at 12:17./run.sh <&-
or./run.sh </dev/null
does it die too? If your server is a binary, not a script, you can try usingstrace
to see what system calls it does and so perhaps find the one making it decide to exit. – meuh Mar 23 '17 at 12:26If it try to background the process from within the script, using nohup, or &, it interprets it as an "EXIT" signal.
– string theorist Mar 23 '17 at 13:48