#!/bin/sh
#
# chkconfig: - 91 35
# description: Starts and stops the OpenStack Keystone daemon \
#              used to provide Identity Service.
#
# pidfile: /var/run/keystone/keystone.pid
# config:  /etc/keystone/keystone.conf
#
### BEGIN INIT INFO
# Provides:          openstack-keystone
# Required-Start:    $network $local_fs $remote_fs
# Required-Stop:     $remote_fs
# Should-Start:      mysql postgresql slapd rabbitmq
# Should-Stop:       mysql postgresql
# Default-Start:     3 5
# Default-Stop:      0 1 2 6
# Short-Description: OpenStack cloud identity service (Keystone)
# Description:       This is the identity service used by OpenStack for
#                    authentication (authN) and high-level authorization (authZ).
### END INIT INFO

# Do not load RH compatibility interface.
WITHOUT_RC_COMPAT=1

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

DAEMON="keystone-all"
PIDFILE="/var/run/keystone/keystone.pid"
LOCKFILE="/var/lock/subsys/keystone"
CONFIG="/etc/keystone/keystone.conf"

RETVAL=0
NAME="Keystone"

start() {
	start_daemon --user keystone --make-pidfile --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --displayname "$NAME" -- $DAEMON --config-file=$CONFIG
	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
