Skip to content
This repository was archived by the owner on Aug 29, 2018. It is now read-only.

Commit 203d57b

Browse files
committed
Kill haproxy during restart even when pid does not exist
Bug 1211526 https://bugzilla.redhat.com/show_bug.cgi?id=1211526 The haproxy process was not killed with pkill as expected due to a logging message being reported instead of returning non-zero at the end of the `_stop_haproxy_service` function. `pkill` is now run if the haproxy process still exists after the stop during a restart. The `_stop_haproxy_ctld` method was setting $pid to the haproxy_ctld pid. This same variable is set in `_stop_haproxy_service` only if the haproxy pid file does exist. If the haproxy pid file doesn't exist, the $pid variable still contains the haproxy_ctld pid, causing us to assume that the haproxy pid file does exist. The stop function would report that the haproxy instance is stopped when the haproxy pid files does not exist. Now `stop()` attempts to force-kill the haproxy instance if the process is still running, whether the pid file exists or not. Lastly, modified several `echo` statements to use the sdk's client_* methods. This ensures that the user perfoming these actions using rhc will receive the message in the rhc output.
1 parent 123da46 commit 203d57b

1 file changed

Lines changed: 30 additions & 12 deletions

File tree

  • cartridges/openshift-origin-cartridge-haproxy/bin

cartridges/openshift-origin-cartridge-haproxy/bin/control

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ function wait_to_start() {
4141

4242
function _stop_haproxy_ctld() {
4343
if [ -f ${HAPROXY_CTLD_PID} ]; then
44-
pid=$( /bin/cat "${HAPROXY_CTLD_PID}" )
45-
if ps --no-headers --pid ${pid} > /dev/null 2>&1; then
46-
kill -TERM $pid
44+
local ctld_pid=$( /bin/cat "${HAPROXY_CTLD_PID}" )
45+
if ps --no-headers --pid ${ctld_pid} > /dev/null 2>&1; then
46+
kill -TERM $ctld_pid
4747
else
4848
rm -f ${HAPROXY_CTLD_PID}
4949
fi
@@ -147,15 +147,19 @@ function _stop_haproxy_service() {
147147
else
148148
if `pgrep -x haproxy > /dev/null 2>&1`
149149
then
150-
echo "Warning: HAProxy process exists without a pid file. Use force-stop to kill." 1>&2
150+
client_message "Warning: HAProxy process exists without a pid file."
151151
else
152-
echo "HAProxy already stopped" 1>&2
152+
client_message "HAProxy already stopped"
153153
fi
154154
fi
155155
}
156156

157157
function _restart_haproxy_service() {
158-
_stop_haproxy_service || pkill haproxy || :
158+
_stop_haproxy_service
159+
if `pgrep -x haproxy > /dev/null 2>&1`; then
160+
client_message "Could not stop HAProxy. Forcefully killing the process."
161+
pkill haproxy
162+
fi
159163
_start_haproxy_service
160164
}
161165

@@ -175,17 +179,31 @@ function _reload_service() {
175179

176180
function start() {
177181
_start_haproxy_service
178-
isrunning && echo "HAProxy instance is started"
182+
if isrunning; then
183+
client_result "HAProxy instance is started"
184+
else
185+
client_error "HAProxy instance could not be started"
186+
exit 1
187+
fi
179188
}
180189

181190
function stop() {
182191
_stop_haproxy_service
183-
isrunning || echo "HAProxy instance is stopped"
192+
if `pgrep -x haproxy > /dev/null 2>&1`; then
193+
client_message "Could not stop HAProxy. Forcefully killing the process."
194+
pkill haproxy
195+
if `pgrep -x haproxy > /dev/null 2>&1`; then
196+
client_error "Could not stop the HAProxy process."
197+
exit 1
198+
fi
199+
fi
200+
201+
client_result "HAProxy instance is stopped"
184202
}
185203

186204
function restart() {
187205
_restart_haproxy_service
188-
isrunning && echo "Restarted HAProxy instance"
206+
isrunning && client_result "Restarted HAProxy instance"
189207
}
190208

191209
function reload() {
@@ -196,14 +214,14 @@ function reload() {
196214
_reload_service
197215
fi
198216

199-
isrunning && echo "Reloaded HAProxy instance"
217+
isrunning && client_result "Reloaded HAProxy instance"
200218
}
201219

202220
function force-reload() {
203221
if isrunning; then
204-
echo "`date`: Conditionally reloading HAProxy service " 1>&2
222+
client_message "`date`: Conditionally reloading HAProxy service "
205223
_reload_service
206-
isrunning && echo "Conditionally reloaded HAProxy"
224+
isrunning && client_result "Conditionally reloaded HAProxy"
207225
fi
208226
}
209227

0 commit comments

Comments
 (0)