I have written a bashscript with the following content:
#!/bin/bash
cd /opt/ut_server/System
./ucc-bin-linux-amd64 server DM-Rankin?game=XGame.xDeathMatch?mutator=AntiTCC2009r6.MutAntiTCCFinal,utcompv17a.MutUTComp?AdminName=admin?AdminPassword=1111 ini=server.ini -port=1234 -log=s9.log -nohomedir &
sleep 10
echo "finish ucc"
exit 0
and now I want start it with a unit file and systemd:
[Unit]
Description=Unreal Tournament 2004 Server
After=network.target
[Service]
WorkingDirectory=/home/unreal-user/
User=unreal-user
Group=unreal-user
Type=forking
ExecStart=/home/unreal-user/start_ut_serv.sh &
ExecStartPost=/bin/bash -c "umask 022; echo $MAINPID > /home/unreal-user/ut2k4-server.pid"
ExecReload=/bin/kill -HUP $MAINPID
ExecStop=/bin/kill -9 $MAINPID
TimeoutSec=400
ExecRestart=/bin/kill -9 $MAINPID && /home/unreal-user/start_ut_serv.sh
PIDFile=/home/unreal-user/ut2k4-server.pid
RestartSec=30
Restart=on-failure
#Restart=always
[Install]
WantedBy=multi-user.target
When I start the service file I've got an error like:
ut2k4-serv.service: Start operation timed out. Terminating.
systemd[1]: ut2k4-serv.service: Control process exited, code=killed, status=15/TERM
Why is this timing out here? How handle this problem?
When I start the bashscript manual it also seems that there is still something on the STDOUT from it, even though a job was specified in it? This is just curious..
Best Answer
This is mostly just copy-paste from the systemd.service documentation since it's largely enough.
Your process is clearly not a forking process, you've attempted multiple hacks to make it one when it's natively supported by systemd.
You're writing the systemd
MAINPID
variable to that file, but not only isMAINPID
undocumented forExecStartPost=
but more importantly, sincePIDFile
is set, it is actually read from that file (at this point, I'm not too sure what it expands to since in this situation, it make no sense; it should have been read whenExecStart=
returned so I'd say it's empty).Your
ExecStart=
andExecRestart=
are clearly broken in addition to being pointless with regards toType=
and the default implementation ofExecRestart=
.As of now, your bash wrapper is useless and depending on what its aim is, you should remove it altogether and set the UT server directly as the
ExecStart=
argument. The server command-line can be sourced from anEnvironmentFile=
and you're done!Furthermore, unless that server is an absolute nightmare, stopping any kind of service with a SIGKILL is... bad, to say the least. The default implemention of
ExecStop=
will likely be better suited.Next time you're writing a service script, try starting from the default one and progressively change parameters instead of changing everything and then wondering which one of the twenty parameters is broken, it's easier to debug 😉