Bug #15895
closedHaproxy control script doesnt work
0%
Description
Default http-haproxy file causes it to not start due to not parsing the pid:
root@openindiana:/etc/haproxy# /lib/svc/method/http-haproxy start
Verifying HAProxy configuration: OK
/lib/svc/method/http-haproxy: line 43: /var/run/haproxy.pid: cannot open [No such file or directory]
[NOTICE] (2089) : haproxy version is 2.7.10-d796057
[NOTICE] (2089) : path to executable is /usr/sbin/haproxy
[ALERT] (2089) : -sf option: failed to parse {}: Invalid argument
Removing the double quotes around "$(<${PID_FILE})" resolves the "failed to parse {}" error and it starts, even if pid file doesnt exist:
start)
exec ${HAPROXY} -D -f ${CONF_FILE} -p ${PID_FILE} -sf $(<${PID_FILE})
root@openindiana:/lib/svc/method# ./http-haproxy start
Verifying HAProxy configuration: OK
./http-haproxy: line 43: /var/run/haproxy.pid: cannot open [No such file or directory]
[NOTICE] (2096) : haproxy version is 2.7.10-d796057
[NOTICE] (2096) : path to executable is /usr/sbin/haproxy
[ALERT] (2096) : config : parsing [/etc/haproxy/haproxy.cfg:16] : 'pidfile' already specified. Continuing.
root@openindiana:/lib/svc/method# pgrep haproxy
2098
However the stop function doesnt work with haproxy 2.7.10, it stays running with the same PID:
root@openindiana:/lib/svc/method# pgrep haproxy
2098
root@openindiana:/lib/svc/method# ./http-haproxy stop
[NOTICE] (2116) : haproxy version is 2.7.10-d796057
[NOTICE] (2116) : path to executable is /usr/sbin/haproxy
[ALERT] (2116) : config : parsing [/etc/haproxy/haproxy.cfg:16] : 'pidfile' already specified. Continuing.
[ALERT] (2116) : Binding [/etc/haproxy/haproxy.cfg:48] for frontend stats: cannot bind socket (Address already in use) for [0.0.0.0:8404]
[ALERT] (2116) : [/usr/sbin/haproxy.main()] Some protocols failed to start their listeners! Exiting.
root@openindiana:/lib/svc/method# pgrep haproxy
2098
HAProxy documents reference using SIGTERM to stop it:
https://docs.haproxy.org/2.7/management.html#4
Updating http-haproxy to use kill -TERM for the stop function resolved it and this matches haproxy scripts from other OSs:
stop)
exec /usr/bin/kill -TERM $(<${PID_FILE})
root@openindiana:/lib/svc/method# ./http-haproxy stop
root@openindiana:/lib/svc/method# pgrep haproxy
root@openindiana:/lib/svc/method#
However the -sf flag doesnt work, running refresh or start again shows a bind error instead of reloading haproxy as expected. This output is with set -x in http-haproxy, note that the pid doesnt change either:
root@openindiana:/lib/svc/method# ./http-haproxy refresh
+ ulimit -n 65536
+ . /lib/svc/share/smf_include.sh
+ SMF_EXIT_OK=0
+ SMF_EXIT_NODAEMON=94
+ SMF_EXIT_ERR_FATAL=95
+ SMF_EXIT_ERR_CONFIG=96
+ SMF_EXIT_MON_DEGRADE=97
+ SMF_EXIT_MON_OFFLINE=98
+ SMF_EXIT_ERR_NOSMF=99
+ SMF_EXIT_ERR_PERM=100
+ HAPROXY=/usr/sbin/haproxy
+ CONF_FILE=/etc/haproxy/haproxy.cfg
+ PID_FILE=/var/run/haproxy.pid
+ [ ! -f /etc/haproxy/haproxy.cfg ]
+ haproxy_verify_config
+ echo 'Verifying HAProxy configuration: \c'
Verifying HAProxy configuration: + /usr/sbin/haproxy -c -f /etc/haproxy/haproxy.cfg
+ 1> /dev/null 2>& 1
+ echo OK
OK
+ 0< /var/run/haproxy.pid
+ exec /usr/sbin/haproxy -D -f /etc/haproxy/haproxy.cfg -p /var/run/haproxy.pid -sf 2210
[NOTICE] (2224) : haproxy version is 2.7.10-d796057
[NOTICE] (2224) : path to executable is /usr/sbin/haproxy
[ALERT] (2224) : Binding [/etc/haproxy/haproxy.cfg:47] for frontend stats: cannot bind socket (Address already in use) for [0.0.0.0:8404]
[ALERT] (2224) : [/usr/sbin/haproxy.main()] Some protocols failed to start their listeners! Exiting.
root@openindiana:/lib/svc/method#
root@openindiana:/lib/svc/method#
root@openindiana:/lib/svc/method# pgrep haproxy
2210
I cant find any reason at all for -sf not working... But it doesn't seem to be needed with the master-worker feature of haproxy so I changed to that. This also allows for hitless reloads with haproxy. The refresh function was changed to send a SIGUSER2 to the master pid.
New refresh function:
refresh)
haproxy_verify_config
exec /usr/bin/kill -USR2 $(<${PID_FILE})
root@openindiana:/lib/svc/method# pgrep haproxy
2270
2269
root@openindiana:/lib/svc/method# ./http-haproxy refresh
+ ulimit -n 65536
+ . /lib/svc/share/smf_include.sh
+ SMF_EXIT_OK=0
+ SMF_EXIT_NODAEMON=94
+ SMF_EXIT_ERR_FATAL=95
+ SMF_EXIT_ERR_CONFIG=96
+ SMF_EXIT_MON_DEGRADE=97
+ SMF_EXIT_MON_OFFLINE=98
+ SMF_EXIT_ERR_NOSMF=99
+ SMF_EXIT_ERR_PERM=100
+ HAPROXY=/usr/sbin/haproxy
+ CONF_FILE=/etc/haproxy/haproxy.cfg
+ PID_FILE=/var/run/haproxy.pid
+ MASTER_SOCKET=/var/run/haproxy-master.sock,uid,root,gid,root,mode,600
+ [ ! -f /etc/haproxy/haproxy.cfg ]
+ haproxy_verify_config
+ echo 'Verifying HAProxy configuration: \c'
Verifying HAProxy configuration: + /usr/sbin/haproxy -c -f /etc/haproxy/haproxy.cfg
+ 1> /dev/null 2>& 1
+ echo OK
OK
+ 0< /var/run/haproxy.pid
+ exec /usr/bin/kill -USR2 2269
root@openindiana:/lib/svc/method# pgrep haproxy
2281
2269
With master-worker enabled in http-haproxy as well as the removal of the quotes haproxy now starts, stops, and refreshes properly. Master-worker also allows hitless reloads from other scripts and processes.