#!/bin/sh
#
# openstack-cinder-api  OpenStack cinder API Server
#
# chkconfig:   - 98 02
# description: At the heart of the cloud framework is an API Server. \
#              This API Server makes command and control of the      \
#              hypervisor, storage, and networking programmatically  \
#              available to users in realization of the definition   \
#              of cloud computing.
# pidfile: /var/run/cinder/cinder-api.pid
# config:  /etc/cinder/cinder.conf
### BEGIN INIT INFO
# Provides:
# Required-Start: $remote_fs $network $syslog
# Required-Stop: $remote_fs $syslog
# Default-Stop: 0 1 6
# Short-Description: OpenStack cinder API Server
# Description: At the heart of the cloud framework is an API Server.
#              This API Server makes command and control of the
#              hypervisor, storage, and networking programmatically
#              available to users in realization of the definition
#              of cloud computing.
### END INIT INFO

# Do not load RH compatibility interface.
WITHOUT_RC_COMPAT=1

# Source function library.
. /etc/init.d/functions


DAEMON=cinder-api
PIDFILE=/var/run/cinder/$DAEMON.pid
LOCKFILE=/var/lock/subsys/$DAEMON
CONFIG_DIST=/usr/share/cinder/cinder-dist.conf
CONFIG=/etc/cinder/cinder.conf
LOGFILE=/var/log/cinder/api.log

RETVAL=0
NAME="Cinder API"


start() {
	start_daemon --user cinder --make-pidfile --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --displayname "$NAME" -- \
		$DAEMON --config-file "$CONFIG_DIST" --config-file "$CONFIG"  --logfile "$LOGFILE"
	RETVAL=$?
	return $RETVAL
}

stop() {
	stop_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --displayname "$NAME"  -- $DAEMON
	RETVAL=$?
	return $RETVAL
}

restart() {
	stop
	start
}


case "$1" in
start)
	start
	;;
stop)
	stop
	;;
restart)
	restart
	;;
reload)
	restart
	;;
condstop)
	if [ -e "$LOCKFILE" ]; then
		stop
	fi
	;;
condrestart)
	if [ -e "$LOCKFILE" ]; then
		restart
	fi
	;;
condreload)
	if [ -e "$LOCKFILE" ]; then
		restart
	fi
	;;
status)
	status --pidfile "$PIDFILE" --displayname "$NAME" -- $DAEMON
	RETVAL=$?
	;;
*)
	msg_usage "${0##*/} {start|stop|reload|restart|condstop|condrestart|condreload|status}"
	RETVAL=1
esac

exit $RETVAL
