c8159ea6cb
Create fault management REST API service Create fault management client and CLI shell Add a python extension for fault management application APIs Update fault management python APIs to use the python extension Update fault manager to retrieve the SNMP configuration from the config file Story: 2002828 Task: 22747 Depends-On: https://review.openstack.org/#/c/592176/ Change-Id: I888d8d23edf75d05d51594ccca55570ae366c848 Signed-off-by: Tao Liu <tao.liu@windriver.com>
148 lines
3.0 KiB
Bash
148 lines
3.0 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()
|
|
{
|
|
# Status function has a standard set of return codes to indicate daemon status
|
|
# http://refspecs.linuxbase.org/LSB_3.1.0/LSB-Core-generic/LSB-Core-generic/iniscrptact.html
|
|
|
|
local my_processes=`pgrep -l -f "^(python|/usr/bin/python|/usr/bin/python2) ${DAEMON}([^\w-]|$)"`
|
|
|
|
if [ -z "${my_processes}" ]; then
|
|
echo "$NAME is not running"
|
|
return 1
|
|
fi
|
|
|
|
echo "$NAME is running"
|
|
return 0
|
|
}
|
|
|
|
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) ${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) ${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
|