Skip to content

Commit 87e68fe

Browse files
Merge pull request #538 from bogdando/bug/1529897
Syntax and local vars usage fixes to OCF HA
2 parents 03fd0c2 + b00c057 commit 87e68fe

File tree

1 file changed

+18
-26
lines changed

1 file changed

+18
-26
lines changed

scripts/rabbitmq-server-ha.ocf

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -323,22 +323,23 @@ proc_kill()
323323
{
324324
local pid="${1}"
325325
local service_name="${2}"
326-
local signal=${3:-SIGTERM}
327-
local count=${4:-5}
328-
local process_sleep=${5:-2}
326+
local signal="${3:-SIGTERM}"
327+
local count="${4:-5}"
328+
local process_sleep="${5:-2}"
329329
local LH="${LL} proc_kill():"
330-
local pgrp=$(ps -o pgid= ${pid} | tr -d '[[:space:]]')
330+
local pgrp="$(ps -o pgid= ${pid} | tr -d '[[:space:]]')"
331331

332332
if [ "${pid}" -a "${pgrp}" = "1" ] ; then
333333
ocf_log err "${LH} shall not kill by the bad pid 1 (init)!"
334334
return 2
335335
fi
336336

337337
if [ -z "${pid}" ]; then
338-
ocf_log info "${LH} no pid provided, will try the ${service_name}"
339-
ocf_run pkill -f -${signal} "${service_name}"
340-
rc=$?
341-
if [ $rc -eq 0 ] ; then
338+
local matched
339+
matched="$(pgrep -fla ${service_name})"
340+
ocf_log info "${LH} no pid provided, will try the ${service_name}, matched list: ${matched}"
341+
ocf_run pkill -f -"${signal}" "${service_name}"
342+
if [ $? -eq 0 ] ; then
342343
ocf_log warn "${LH} sent kill -${signal} to processes matched the ${service_name}"
343344
return 0
344345
else
@@ -348,23 +349,18 @@ proc_kill()
348349
fi
349350

350351
while [ $count -gt 0 ]; do
351-
if [ -d /proc/${pid} ]; then
352-
ocf_log debug "${LH} Stopping ${service_name} with ${signal}..."
353-
ocf_run pkill -${signal} -g "${pgrp}"
354-
if [ ! -d /proc/${pid} ] ; then
355-
ocf_log debug "${LH} Stopped ${service_name} with ${signal}"
356-
return 0
357-
fi
352+
if [ ! -d "/proc/${pid}" ]; then
353+
break
358354
else
359-
ocf_log debug "${LH} Stopped ${service_name} with ${signal}"
360-
return 0
355+
ocf_log debug "${LH} Stopping ${service_name} with ${signal}..."
356+
ocf_run pkill -"${signal}" -g "${pgrp}"
361357
fi
362358
sleep $process_sleep
363359
count=$(( count-1 ))
364360
done
365361

366362
# Check if the process ended after the last sleep
367-
if [ ! -d /proc/${pid} ] ; then
363+
if [ ! -d "/proc/${pid}" ] ; then
368364
ocf_log debug "${LH} Stopped ${service_name} with ${signal}"
369365
return 0
370366
fi
@@ -396,7 +392,7 @@ proc_stop()
396392
{
397393
local pid_param="${1}"
398394
local service_name="${2}"
399-
local timeout=${3:-15}
395+
local timeout="${3:-15}"
400396
local LH="${LL} proc_stop():"
401397
local pid
402398
local pidfile
@@ -761,11 +757,9 @@ update_cookie() {
761757

762758
# Stop rmq beam process by pid or rabbit node name match. Returns SUCCESS/ERROR
763759
kill_rmq_and_remove_pid() {
764-
local rc
765760
local LH="${LL} kill_rmq_and_remove_pid():"
766761
proc_stop "${OCF_RESKEY_pid_file}" "beam.*${RABBITMQ_NODENAME}" "${OCF_RESKEY_stop_time}"
767-
rc=$?
768-
if [ $rc -eq 0 ] ; then
762+
if [ $? -eq 0 ] ; then
769763
return $OCF_SUCCESS
770764
else
771765
return $OCF_ERR_GENERIC
@@ -1280,8 +1274,7 @@ check_timeouts() {
12801274

12811275
local count
12821276
count=`crm_attribute -N $THIS_PCMK_NODE -l reboot --name $crm_attr_name --query 2>/dev/null`
1283-
op_rc=$?
1284-
if [ $op_rc -ne 0 ]; then
1277+
if [ $? -ne 0 ]; then
12851278
# the crm_attribute exited with error. In that case most probably it printed garbage
12861279
# instead of the number we need. So defensively assume that it is zero.
12871280

@@ -1633,8 +1626,7 @@ action_stop() {
16331626

16341627
# Ensure the actual status to be returned
16351628
get_status
1636-
rc=$?
1637-
if [ $rc -eq $OCF_NOT_RUNNING ] ; then
1629+
if [ $? -eq $OCF_NOT_RUNNING ] ; then
16381630
ocf_log info "${LH} RMQ-runtime (beam) not running."
16391631
ocf_log info "${LH} action end."
16401632
return $OCF_SUCCESS

0 commit comments

Comments
 (0)