#!/bin/sh
#
# opennebula-econe	OpenNebula ECONE Server.
#
# chkconfig: - 66 34
# description: OpenNebula ECONE Server
# processname: opennebula-econe
# config:  /etc/one/econe.conf
# pidfile: /var/run/one/econe-server.pid
#
### BEGIN INIT INFO
# Provides:          opennebula-econe
# Required-Start:    $remote_fs opennebula
# Required-Stop:     $remote_fs opennebula
# Default-Start:     3 4 5
# Default-Stop:      0 1 2 6
# Short-Description: ECONE Server init script
# Description:       OpenNebula ECONE service initialisation script
### END INIT INFO

# Do not load RH compatibility interface.
WITHOUT_RC_COMPAT=1

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

NAME=econe-server
PIDFILE=/var/run/one/$NAME.pid
LOCKFILE=/var/lock/subsys/$NAME
RETVAL=0

start()
{
	start_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --user oneadmin -- $NAME start
	RETVAL=$?
	return $RETVAL
}

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

restart()
{
	stop
	start
}

# See how we were called.
case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	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" --expect-user oneadmin -- ruby
		RETVAL=$?
		;;
	*)
		msg_usage "${0##*/} {start|stop|reload|restart|condstop|condrestart|condreload|status}"
		RETVAL=1
esac

exit $RETVAL
