Skip to content

Commit

Permalink
Switch to master-worker mode to enable nbproc > 1 reloads
Browse files Browse the repository at this point in the history
  • Loading branch information
domdom82 committed Feb 10, 2021
1 parent ac2c3d0 commit 36334d9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
8 changes: 4 additions & 4 deletions jobs/haproxy/templates/haproxy_wrapper.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ PATH=/var/vcap/packages/haproxy/bin:${PATH}
DAEMON=/var/vcap/packages/haproxy/bin/haproxy
CONFIG=/var/vcap/jobs/haproxy/config/haproxy.config
PID_FILE=/var/vcap/sys/run/haproxy/haproxy.pid
SOCK_FILE=/var/vcap/sys/run/haproxy/stats.sock
export PATH=$PATH:/var/vcap/packages/ttar/bin

cleanup_daemon() {
Expand All @@ -20,7 +19,8 @@ cleanup_daemon() {
reload_daemon() {
update_certs
echo "$(date): Reloading HAProxy"
"${DAEMON}" -f "${CONFIG}" -D -p ${PID_FILE} -sf "$(cat ${PID_FILE})" -x ${SOCK_FILE} 0<&-
# Relay the reload signal to the master process
kill -USR2 "$(cat ${PID_FILE})"
sleep infinity
}

Expand Down Expand Up @@ -87,9 +87,9 @@ trap reload_daemon USR2
# Start up
echo "$(date): Starting HAProxy"
<%- if p('ha_proxy.syslog_server') == "stdout" || p('ha_proxy.syslog_server') == "stderr" -%>
"${DAEMON}" -f "${CONFIG}" -p ${PID_FILE} -V -db
"${DAEMON}" -f "${CONFIG}" -W -p ${PID_FILE} -V -db
<%- else -%>
"${DAEMON}" -f "${CONFIG}" -D -p ${PID_FILE} 0<&-
"${DAEMON}" -f "${CONFIG}" -W -D -p ${PID_FILE}

# Since HAProxy requires Daemonized mode for its `nbproc` multi-process feature
# to work properly, and BPM requires the process to stay running, sleep infinitely here
Expand Down
3 changes: 2 additions & 1 deletion jobs/haproxy/templates/reload.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ fi

pid="$(cat ${pidfile})"
haproxy_wrapper_pid=$(pgrep -P "$pid" haproxy_wrapper)
haproxy_instances=$(pgrep -P "$pid" -x haproxy | wc -l)
haproxy_master_pid=$(pgrep -P "$pid" -x haproxy)
haproxy_instances=$(pgrep -P "$haproxy_master_pid" -x haproxy | wc -l)

if [[ -n $haproxy_wrapper_pid ]]; then
if [[ $max_instances -eq 0 ]] || [[ $haproxy_instances -lt $max_instances ]]; then
Expand Down

0 comments on commit 36334d9

Please sign in to comment.