fault/fm-rest-api/fm/scripts/fm-api
Dan Voiculeasa 9d9ea1ed24 Fix fm-api service startup
The fm-api service is not properly started since the status logic is
wrong.

Updated the status logic to drop the regex approach and use the PIDFILE
instead.

There is a confirm_stop logic step which still needs to use the regex
approach because the main process spawns children. Updated the regex
for confirm_stop logic step. Now looking for /usr/bin/pythton3 and
/usr/libexec/platform-python.

Story: 2008454
Task: 42631
Depends-On: I970c2600475e32f2c5fb815738a2fe79f99a5b17
Signed-off-by: Dan Voiculeasa <dan.voiculeasa@windriver.com>
Change-Id: Ia77988ce282ea17de84b89e833ec686df342b3c4
(cherry picked from commit 4d5c6c7f21)
2021-08-16 01:25:31 +00:00

145 lines
2.9 KiB
Bash

#! /bin/sh
#
# Copyright (c) 2018 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
### BEGIN INIT INFO
# Provides: fm-api
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 3 5
# Default-Stop: 0 1 2 6
# Short-Description: Fault Management REST API Service
# Description: Fault Management REST API Service
### END INIT INFO
. /etc/init.d/functions
# Linux Standard Base (LSB) Error Codes
RETVAL=0
GENERIC_ERROR=1
INVALID_ARGS=2
UNSUPPORTED_FEATURE=3
NOT_INSTALLED=5
NOT_RUNNING=7
NAME="fm-api"
DAEMON="/usr/bin/${NAME}"
PIDFILE="/var/run/${NAME}.pid"
CONFIGFILE="/etc/fm/fm.conf"
if ! [ -x ${DAEMON} ] ; then
logger "${DAEMON} is missing"
exit ${NOT_INSTALLED}
fi
PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin
export PATH
status()
{
pid=`cat $PIDFILE 2>/dev/null`
if [ -n "$pid" ]; then
if ps -p $pid | grep $NAME &> /dev/null ; then
echo "$NAME is running"
return 0
fi
fi
echo "$NAME is not running"
return 1
}
start ()
{
status >/dev/null
if [ $? -eq 0 ]; then
echo "$NAME is already running"
return 0
fi
# Delete stale pidfile, if any
rm -f $PIDFILE
start-stop-daemon --start -b --make-pidfile --pidfile $PIDFILE -x ${DAEMON} -- --config-file=${CONFIGFILE}
RETVAL=$?
if [ ${RETVAL} -eq 0 ]; then
status >/dev/null
if [ $? -eq 0 ]; then
logger -t $NAME "start OK"
echo "OK"
return 0
fi
logger -t $NAME "start-stop-daemon returned 0, but status fails"
rm -f $PIDFILE
fi
logger -t $NAME "start failed"
return ${GENERIC_ERROR}
}
confirm_stop()
{
local my_processes=`pgrep -l -f "^(python|/usr/bin/python|/usr/bin/python2|/usr/bin/python3|/usr/libexec/platform-python) ${DAEMON}([^\w-]|$)"`
if [ -n "${my_processes}" ]
then
logger -t $NAME "About to SIGKILL the following: ${my_processes}"
pkill -KILL -f "^(python|/usr/bin/python|/usr/bin/python2|/usr/bin/python3|/usr/libexec/platform-python) ${DAEMON}([^\w-]|$)"
fi
}
stop ()
{
status >/dev/null
if [ $? -ne 0 ]; then
echo "$NAME is not running"
return 0
fi
echo -n "Stopping ${NAME}: "
if [ -f $PIDFILE ]; then
start-stop-daemon --stop --quiet --retry 3 --oknodo --pidfile $PIDFILE
fi
confirm_stop
rm -f $PIDFILE
# Confirm status
status >/dev/null
if [ $? -ne 0 ]; then
echo "Stopped"
return 0
else
echo "Failed"
return ${GENERIC_ERROR}
fi
}
rc=0
case "$1" in
start)
start
rc=$?
;;
stop)
stop
rc=$?
;;
restart|force-reload|reload)
stop
start
rc=$?
;;
status)
status
rc=$?
;;
*)
echo "Usage: $0 {start|stop|force-reload|restart|reload|status}"
exit 1
;;
esac
exit $rc