#!/bin/sh
#
# openstack-nova-compute:  OpenStack Nova Compute Worker
#
# chkconfig: - 98 02
# description: Starts and stops the Openstack Nova Compute daemon.
# pidfile: /var/run/nova/nova-compute.pid
# config:  /etc/nova/nova.conf
#
### BEGIN INIT INFO
# Provides: openstack-nova-compute
# Required-Start: $remote_fs $network $syslog
# Required-Stop: $remote_fs $syslog
# Default-Stop: 0 1 6
# Short-Description: OpenStack Nova Compute Worker
# Description: Compute workers manage computing instances on host
#               machines. Through the API, commands are dispatched
#               to compute workers to:
#               * Run instances
#               * Terminate instances
#               * Reboot instances
#               * Attach volumes
#               * Detach volumes
#               * Get console output
### END INIT INFO


# Do not load RH compatibility interface.
WITHOUT_RC_COMPAT=1

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

DAEMON=nova-compute
PIDFILE=/var/run/nova/$DAEMON.pid
LOCKFILE=/var/lock/subsys/$DAEMON

RETVAL=0
NAME="Nova Compute"

start() {
	export LIBGUESTFS_ATTACH_METHOD=appliance
	start_daemon --user nova --make-pidfile --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --displayname "$NAME" -- $DAEMON
	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
