#!/bin/sh
#
# xenconsoled	Script to start and stop xenconsoled
#
# chkconfig:	2345 70 10
# description:	Starts and stops xenconsoled
#

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

# Read in configuration options.
XENCONSOLED_ARGS=
XENCONSOLED_LOG=none
XENCONSOLED_LOG_DIR=/var/log/xen/console
[ -f /etc/sysconfig/xenconsoled ] && . /etc/sysconfig/xenconsoled

if [ "$1" = "start" -a -d /proc/xen -a ! -f /proc/xen/capabilities ] && \
		! grep -qs '^xenfs ' /proc/mounts >/dev/null; then
	mount -t xenfs xenfs /proc/xen
fi

grep -qs "control_d" /proc/xen/capabilities || exit 0

start() {
	if [ -f /var/lock/subsys/xenconsoled ]; then
		msg_already_running xenconsoled
		return
	fi
	msg_starting xenconsoled
	daemon /usr/sbin/xenconsoled --pid-file=/var/run/xenconsoled.pid --log=${XENCONSOLED_LOG} --log-dir=${XENCONSOLED_LOG_DIR} $XENCONSOLED_ARGS
	RETVAL=$?
	[ $RETVAL -eq 0 ] && touch /var/lock/subsys/xenconsoled
}

stop() {
	if [ ! -f /var/lock/subsys/xenconsoled ]; then
		msg_not_running xenconsoled
		return
	fi
	msg_stopping xenconsoled
	killproc --pidfile /var/run/xenconsoled.pid xenconsoled
	RETVAL=$?
	rm -f /var/run/xenconsoled.pid >/dev/null 2>&1
	rm -f /var/lock/subsys/xenconsoled >/dev/null 2>&1
}

RETVAL=0
# See how we were called.
case "$1" in
  start)
	start
	;;
  status)
        status xenconsoled
	;;
  stop)
	stop
	;;
  force-reload|restart)
        stop
	start
	;;
  *)
	msg_usage "$0 {start|stop|status|restart|force-reload}"
	exit 3
esac

exit $RETVAL
