When we re-deploy an application we use systemd restart
to restart the application. It would seem that either systemd restart
or systemd status
(or both) are unreliable.
- Sometimes
systemd restart
DOESN'T restart the application and doesn't throw an error. PID is the same as before and the old version of the app is still running. Isrestart
effective immediately? - Sometimes
systemd restart
does kill the old process and start the new process butsystemd status
shows the service as dead. We see the process running as a child of systemd.
As an example of the 2nd problem: systemctl status
is says the service inactive(dead) but it's definitely running (new pids 25548 and 25551)!
$systemctl status gateway.service
gateway.service - The API Gateway - Nginx
Loaded: loaded (/etc/systemd/system/gateway.service; enabled; vendor preset: disabled)
Active: inactive (dead) since Wed 2020-08-05 14:00:16 CEST; 1h 43min ago
Process: 25545 ExecStart=/usr/sbin/nginx -c /prg/nginx/conf/gateway.conf (code=exited, status=0/SUCCESS)
Process: 25542 ExecStartPre=/usr/sbin/nginx -t -c /prg/nginx/conf/gateway.conf (code=exited, status=0/SUCCESS)
Process: 25540 ExecStartPre=/usr/bin/rm -f /daten/nginx.pid (code=exited, status=0/SUCCESS)
Main PID: 25545 (code=exited, status=0/SUCCESS)
Tasks: 2
Memory: 130.0M
CGroup: /system.slice/gateway.service
├─25548 nginx: master process /usr/sbin/nginx -c /prg/nginx/conf/gateway.conf
└─25551 nginx: worker process
ps | grep nginx
shows the 2 nginx processes:
nginx 25548 root 5u IPv4 58124367 0t0 TCP *:8080 (LISTEN)
nginx 25551 nginx 5u IPv4 58124367 0t0 TCP *:8080 (LISTEN)
pstree
shows these 2 processes as children of systemd:
systemd─┬...
├─nginx───nginx
systemd Config
[Service]
Type=forking
PIDFile=/daten/nginx.pid
# Nginx will fail to start if /run/nginx.pid already exists but has the wrong
# SELinux context. This might happen when running `nginx -t` from the cmdline.
# https://bugzilla.redhat.com/show_bug.cgi?id=1268621
ExecStartPre=/usr/bin/rm -f /daten/nginx.pid
ExecStartPre=/usr/sbin/nginx -t -c /prg/nginx/conf/gateway.conf
ExecStart=/usr/sbin/nginx -c /prg/nginx/conf/gateway.conf
KillSignal=QUIT
TimeoutStopSec=5
KillMode=process
PrivateTmp=true
0 Answers