Ensure ceph resources pid file

At some point, caused by a race condition, it may happen that
a daemon process (osd, mon, mds) is running, but the pid file
(located in /var/run/ceph) has been removed. This means that
/etc/init.d/ceph does not have the process reference and is
unable to manage it, such as stopping or starting.

To fix this, the "daemon_is_running" function was modified so
that when the pid file does not exist, it checks if the daemon
process is running. This is done via the 'ps aux' command.
When the daemon process is found, its PID is obtained and then
the file is created in /var/run/ceph/<daemon.id>.pid

Test Plan:
 - PASS: Fresh install on AIO-SX/AIO-DX/STD.
 - PASS: Delete pid file of mon, mds and osd and have it
         restored automatically.

Closes-Bug: 2095184

Change-Id: Ia2969f61f5a64ca2b800647387ae7d54b740a1b1
Signed-off-by: Erickson Silva de Oliveira <Erickson.SilvadeOliveira@windriver.com>
This commit is contained in:
Erickson Silva de Oliveira 2025-01-16 18:45:57 -03:00
parent 8314d33629
commit 03a837d396

View File

@ -736,7 +736,11 @@ daemon_is_running() {
daemon=$2
daemon_id=$3
pidfile=$4
do_cmd "[ -e $pidfile ] || exit 1 # no pid, presumably not running
do_cmd "if [ ! -e $pidfile ] ; then
pid_found=\$(ps aux | grep \"$daemon -i $daemon_id\" | grep -v grep | awk '{print \$2}')
[ \"\$pid_found\" != \"\" ] || exit 1 # no pid, presumably not running
echo \$pid_found > $pidfile
fi
pid=\`cat $pidfile\`
cat /proc/\$pid/cmdline | tr '\\0' ' ' | grep $daemon | grep -qwe -i.$daemon_id && exit 0 # running
exit 1 # pid is something else" "" "okfail"