Skip to content

Commit ec93e39

Browse files
committed
fence_sbd: Check if the sbd daemon is running before using SBD_DEVICE enviroment variable
And add @SBDPID_PATH@ for the sbd daemon pid file path
1 parent 744d534 commit ec93e39

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

agents/sbd/fence_sbd.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
DEVICE_NOT_INIT = -3
1515
PATH_NOT_EXISTS = -1
1616
PATH_NOT_BLOCK = -2
17+
SBD_PID_FILE = "@SBDPID_PATH@"
1718

1819
def is_block_device(filename):
1920
"""Checks if a given path is a valid block device
@@ -356,6 +357,34 @@ def define_new_opts():
356357
"order": 200
357358
}
358359

360+
361+
def sbd_daemon_is_running():
362+
"""Check if the sbd daemon is running
363+
"""
364+
if not os.path.exists(SBD_PID_FILE):
365+
logging.info("SBD PID file %s does not exist", SBD_PID_FILE)
366+
return False
367+
368+
try:
369+
with open(SBD_PID_FILE, "r") as pid_file:
370+
pid = int(pid_file.read().strip())
371+
except Exception as e:
372+
logging.error("Failed to read PID file %s: %s", SBD_PID_FILE, e)
373+
return False
374+
375+
try:
376+
# send signal 0 to check if the process is running
377+
os.kill(pid, 0)
378+
except ProcessLookupError:
379+
logging.info("SBD daemon is not running")
380+
return False
381+
except Exception as e:
382+
logging.error("Failed to send signal 0 to PID %d: %s", pid, e)
383+
return False
384+
385+
return True
386+
387+
359388
def main():
360389
"""Main function
361390
"""
@@ -385,7 +414,7 @@ def main():
385414
# If not specified then read SBD_DEVICE from environment
386415
if "--devices" not in options:
387416
dev_list = os.getenv("SBD_DEVICE")
388-
if dev_list:
417+
if sbd_daemon_is_running() and dev_list:
389418
options["--devices"] = ",".join(dev_list.split(";"))
390419
else:
391420
fail_usage("No SBD devices specified. \

configure.ac

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ eval FENCETMPDIR="`eval echo ${FENCETMPDIR}`"
145145
AC_DEFINE_UNQUOTED(FENCETMPDIR,"$FENCETMPDIR", Where Fence agents keep state files)
146146
AC_SUBST(FENCETMPDIR)
147147

148+
SBDPID_PATH=${localstatedir}/run/sbd.pid
149+
AC_SUBST(SBDPID_PATH)
148150

149151
if test "x$AGENTS_LIST" = x; then
150152
AC_ERROR([No agents selected])

make/fencebuild.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ define gen_agent_from_py
99
-e 's#@''SBINDIR@#${sbindir}#g' \
1010
-e 's#@''LIBEXECDIR@#${libexecdir}#g' \
1111
-e 's#@''FENCETMPDIR@#${FENCETMPDIR}#g' \
12+
-e 's#@''SBDPID_PATH@#${SBDPID_PATH}#g' \
1213
-e 's#@''IPMITOOL_PATH@#${IPMITOOL_PATH}#g' \
1314
-e 's#@''OPENSTACK_PATH@#${OPENSTACK_PATH}#g' \
1415
-e 's#@''AMTTOOL_PATH@#${AMTTOOL_PATH}#g' \

0 commit comments

Comments
 (0)