I can fire up my Mojo app via systemd
without any issues, but I can't stop or restart it in the same way. I've poached my config mostly from the Mojo docs at http://mojolicious.org/perldoc/Mojolicious/Guides/Cookbook#Pre-forking:
[Unit]
Description=ldsquiz.org
After=network.target
[Service]
Type=simple
Restart=always
RestartSec=30
ExecStart=/home/sites/www.ldsquiz.org/checkout/bin/carton-exec app.pl prefork -m production -l http://*:5103
KillMode=process
User=ldsquiz
Group=ldsquiz
SyslogIdentifier=ldsquiz-org
[Install]
WantedBy=multi-user.target
If I stop it via sudo service ldsquiz-org stop
then syslog says Jan 13 16:37:48 web-hosting systemd[1]: Stopped ldsquiz.org.
but the processes are still running.
A restart
via systemd
looks like I would expect, since the listen socket is still in use because of the failed shutdown:
Jan 13 16:39:13 web-hosting systemd[1]: Stopped ldsquiz.org.
Jan 13 16:39:13 web-hosting systemd[1]: Started ldsquiz.org.
Jan 13 16:39:14 web-hosting ldsquiz-org[20353]: Can't create listen socket: Address already in use at
/home/sites/www.ldsquiz.org/checkout/local/lib/perl5/Mojo/IOLoop.pm line 126.
Jan 13 16:39:14 web-hosting systemd[1]: ldsquiz-org.service: Main process exited, code=exited, status=98/n/a
Jan 13 16:39:14 web-hosting systemd[1]: ldsquiz-org.service: Unit entered failed state.
Jan 13 16:39:14 web-hosting systemd[1]: ldsquiz-org.service: Failed with result 'exit-code'.
Jan 13 16:39:15 web-hosting ldsquiz-org[16886]: [Sat Jan 13 16:39:15 2018] [info] Creating process id file "/tmp/prefork.pid"
What am I missing here?
systemd
units withsystemctl start/stop/status/restart $serviceName
. Does that make any difference? I.e.systemctl stop ldsquiz-org
? – JemptyType=simple
but thisprefork
parameter makes me doubt. Perhaps giveType=forking
a try. See here for the possible values. Perhaps you also need to play a bit with theKillMode=
setting. See here for the possible values. And remember to callsystemctl daemon-reload
whenever you fiddle with the unit file. – JemptyKillMode=control-group
did the trick for me. Looks like I'll need to see about a Mojo doc patch. If you'd like to write an answer I'm happy to accept it. – Richly