#!/bin/bash
#
# openstack-heat-api: Openstack Heat API Service
#
# chkconfig:   - 98 02
# description: The Heat API provides an OpenStack-native
#              ReST API to the Heat Engine for starting
#              AWS CloudFormation templates on OpenStack.
# pidfile: /var/run/heat/openstack-heat-api.pid
# config:  /etc/heat/heat.conf
#
### BEGIN INIT INFO
# Provides: openstack-heat-api
# Required-Start: $remote_fs $network $syslog
# Required-Stop: $remote_fs $syslog
# Default-Stop: 0 1 6
# Short-Description: OpenStack Heat API Server
# Description: The Heat API provides an OpenStack-native
#              ReST API to the Heat Engine for starting
#              AWS CloudFormation templates on OpenStack.
### END INIT INFO

# Do not load RH compatibility interface.
WITHOUT_RC_COMPAT=1

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

DAEMON=heat-api
PIDFILE=/var/run/heat/openstack-$DAEMON.pid
LOCKFILE=/var/lock/subsys/openstack-$DAEMON
LOGFILE=/var/log/heat/api.log

RETVAL=0
NAME="Heat API"

start() {
	start_daemon --user heat --make-pidfile --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --displayname "$NAME" -- $DAEMON --log-file "$LOGFILE"
	RETVAL=$?
	return $RETVAL
}

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

restart() {
	stop
	start
}

reload() {
	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
			reload
		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
