#!/bin/sh
#
# hypervfcopyd	provides info to the host
#
# chkconfig: - 90 10
# description:	Start hypervfcopyd to allow the host to query this guest
# processname: hypervfcopyd
# pidfile: /var/run/hypervfcopyd.pid
#
### BEGIN INIT INFO
# Provides:          hypervfcopyd
# Required-Start:    $null
# Should-Start:      $syslog $remote_fs $time
# Required-Stop:     $null
# Should-Stop:       $syslog $remote_fs $time
# Default-Start:     3 5
# Default-Stop:      0 1 2 6
# Short-Description: hypervfcopyd provides info to the host
# Description:       Start hypervfcopyd to allow the host to query this guest
### END INIT INFO

# Do not load RH compatibility interface.
WITHOUT_RC_COMPAT=1

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

PIDFILE=/var/run/hypervfcopyd.pid
LOCKFILE=/var/lock/subsys/hypervfcopyd
RETVAL=0

start()
{
	start_daemon --pidfile "$PIDFILE" --make-pidfile --lockfile "$LOCKFILE" --expect-user root -- hypervfcopyd
	RETVAL=$?
	# fix pid
	pidof hypervfcopyd > "$PIDFILE"
	return $RETVAL
}

stop()
{
	stop_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --expect-user root -- hypervfcopyd
	RETVAL=$?
	return $RETVAL
}

restart()
{
	stop
	start
}

reload()
{
	msg_reloading hypervfcopyd
	stop_daemon --pidfile "$PIDFILE" --expect-user root -HUP -- hypervfcopyd
	RETVAL=$?
	return $RETVAL
}

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

exit $RETVAL
