Created attachment 435642 [details] processes are not killed when restarting haproxy I noticed that haproxy (1.6.5, but the other versions are affected), when run with several processes, would continue to respond to requests even after stopping the haproxy service (/etc/init.d/haproxy stop). This is due to only one process being killed instead of all. Of course, when restarting, the number of processes increases each time (see attachment). My haproxy configuration contains the following: global user haproxy group haproxy nbproc 4 Reproducible: always Some insight: ~ # ps aux |grep haproxy haproxy 29858 0.0 0.0 51504 1144 ? Ss 16:19 0:00 /usr/bin/haproxy -D -p /var/run/haproxy.pid -f /etc/haproxy.cfg haproxy 29859 0.0 0.0 51504 1144 ? Ss 16:19 0:00 /usr/bin/haproxy -D -p /var/run/haproxy.pid -f /etc/haproxy.cfg haproxy 29860 0.0 0.0 51504 1144 ? Ss 16:19 0:00 /usr/bin/haproxy -D -p /var/run/haproxy.pid -f /etc/haproxy.cfg haproxy 29861 0.0 0.0 51504 1144 ? Ss 16:19 0:00 /usr/bin/haproxy -D -p /var/run/haproxy.pid -f /etc/haproxy.cfg ~ # cat /var/run/haproxy.pid 29858 29859 29860 29861 ~ # I suspect that the bug resides in that the multiline pidfile is not handled properly by the stop function of the service. Said function must be OpenRC's default, since the service specifies none.
Indeed, pid file then contains one line per haproxy daemon running # cat /var/run/haproxy.pid 559 560 man 8 start-stop-daemon says When stopping we only stop the pid(s) listed in the pidfile But looking at the code, only the first PID is actually read (see https://gitweb.gentoo.org/proj/openrc.git/tree/src/rc/start-stop-daemon.c#n349) and a struct pid_t is returned to caller
It would seem like there is no possible option to make OpenRC's start-stop-daemon accomodate for this, see the discussion at https://bugs.gentoo.org/show_bug.cgi?id=601540 So this needs be fixed in the init.d/haproxy service script.
See https://github.com/gentoo/gentoo/pull/3104 for a fix proposal
The bug is technically solved, however with curious error messages: ~ # /etc/init.d/haproxy stop * Stopping haproxy ... [ ok ] * Stopping haproxy ... [ ok ] * Stopping haproxy ... * start-stop-daemon: no matching processes found [ ok ] * Stopping haproxy ... * start-stop-daemon: no matching processes found [ ok ] ~ # pgrep -a haproxy ~ # /etc/init.d/haproxy start * Checking /etc/haproxy.cfg ... [ ok ] * Starting haproxy ... [ ok ] ~ # /etc/init.d/haproxy stop * Stopping haproxy ... [ ok ] * Stopping haproxy ... [ ok ] * Stopping haproxy ... * start-stop-daemon: no matching processes found [ ok ] * Stopping haproxy ... * start-stop-daemon: no matching processes found [ ok ] ~ # /etc/init.d/haproxy start * Checking /etc/haproxy.cfg ... [ ok ] * Starting haproxy ... [ ok ] ~ # I don't see the reason for this happening. The parent PID of the four haproxy processes is init.
The strange messages on stop are caused by multiple bugs interacting This was fixed in commit 1016c8d09a77369c4b37e511bf6b3f03922f7c23 With older openrc versions before 0.34.11 it would kill all processes called haproxy on the second iteration due to a bug, with newer openrc it refuses to kill. The fixed init script kills the expected PIDs at last.