Blob Blame History Raw
#!/bin/bash
#
# xenstored	Script to start and stop the Xen control daemon.
#
# Author:       Daniel Berrange <berrange@redhat.com
#
# chkconfig: 2345 96 01
# description: Starts and stops the Xen xenstored daemon.
### BEGIN INIT INFO
# Provides:          xenstored
# Required-Start:    $syslog $remote_fs
# Should-Start:
# Required-Stop:     $syslog $remote_fs
# Should-Stop:
# Default-Start:     3 4 5
# Default-Stop:      0 1 2 6
# Default-Enabled:   yes
# Short-Description: Start/stop xenstored
# Description:       Starts and stops the Xen xenstored daemon.
### END INIT INFO

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

if [ ! -d /proc/xen ]; then
	exit 0
fi
if [ ! -f /proc/xen/capabilities ]; then
	mount -t xenfs xen /proc/xen
fi
if ! grep -q "control_d" /proc/xen/capabilities ; then
	exit 0
fi

# Default config params
XENSTORED_PID="/var/run/xenstore.pid"
XENSTORED_ARGS=

# User customized params
test -f /etc/sysconfig/xenstored && . /etc/sysconfig/xenstored

start() {
	echo -n $"Starting xenstored daemon: "
	grep -q '/var/lib/xenstored' /proc/mounts
	if test "$?" = "1"; then
		mount -t tmpfs xenstore /var/lib/xenstored
		restorecon -R /var/lib/xenstored
	fi
        /usr/sbin/xenstored --pid-file $XENSTORED_PID $XENSTORED_ARGS
	RETVAL=$?
	test $RETVAL = 0 && echo_success || echo_failure
        echo
        [ $RETVAL -eq 0 ] && touch /var/lock/subsys/xenstored
}

stop() {
	echo -n $"Stopping xenstored daemon: "
	# xenstored is not restartable.  So we refuse to stop it
	# unless the machine is being shutdown or rebooted anyway.
	if test "$runlevel" = "0" -o "$runlevel" = "6"; then
		killproc xenstored > /dev/null
		RETVAL=$?
	else
		RETVAL=1
	fi
	test $RETVAL = 0 && echo_success || echo_failure
        echo
        [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/xenstored
}

rcstatus() {
        status xenstored
        RETVAL=$?
	test $RETVAL = 0 && echo_success || echo_failure
	echo
}

RETVAL=0
case "$1" in
  start)
        start
	;;
  stop)
        stop
	;;
  status)
        rcstatus
	;;
  *)
	echo $"Usage: $0 {start|stop|status}"
	exit 1
esac

exit $RETVAL