upstream/openstack/python-gnocchi/centos/files/scripts/gnocchi-api.init

110 lines
2.3 KiB
Bash

#!/bin/sh
#
# Copyright (c) 2018 Wind River Systems, Inc.
#
# The right to copy, distribute, modify, or otherwise make use
# of this software may be licensed only pursuant to the terms
# of an applicable Wind River license agreement.
#
### BEGIN INIT INFO
# Provides: Gnocchi API
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Gnocchi REST API daemon
### END INIT INFO
RETVAL=0
DESC="gnocchi-api"
PIDFILE="/var/run/$DESC.pid"
PYTHON=`which python`
EXEC="/usr/bin/gunicorn"
CONFIGFILE="/usr/share/gnocchi/gnocchi-api.conf"
LOGFILE="/var/log/gnocchi/api.log"
start()
{
if [ -e $PIDFILE ]; then
PIDDIR=/proc/$(cat $PIDFILE)
if [ -d ${PIDDIR} ]; then
echo "$DESC already running."
return
else
echo "Removing stale PID file $PIDFILE"
rm -f $PIDFILE
fi
fi
echo -n "Starting $DESC..."
start-stop-daemon --start --quiet --background --pidfile ${PIDFILE} \
--make-pidfile --exec ${PYTHON} -- ${EXEC} --config ${CONFIGFILE} \
--pythonpath '/usr/share/gnocchi' gnocchi-api --log-file ${LOGFILE}
RETVAL=$?
if [ $RETVAL -eq 0 ]; then
echo "Gnocchi API started."
else
echo "Gnocchi API start failed."
fi
}
stop()
{
if [ ! -e $PIDFILE ]; then
echo "Gnocchi API already stopped."
return
fi
echo -n "Stopping $DESC..."
start-stop-daemon --stop --quiet --pidfile $PIDFILE
RETVAL=$?
if [ $RETVAL -eq 0 ]; then
echo "Gnocchi API stopped."
else
echo "Gnocchi API stop failed."
fi
rm -f $PIDFILE
}
status()
{
pid=`cat $PIDFILE 2>/dev/null`
if [ -n "$pid" ]; then
if ps -p $pid &> /dev/null ; then
echo "$DESC is running"
RETVAL=0
return
else
echo "$DESC is not running but has pid file"
RETVAL=1
fi
fi
echo "$DESC is not running"
RETVAL=3
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart|force-reload|reload)
stop
start
;;
status)
status
;;
*)
echo "Usage: $0 {start|stop|force-reload|restart|reload|status}"
RETVAL=1
;;
esac
exit $RETVAL