#!/bin/sh
#
# spice-webdavd:   Webdav daemon for Spice guests
#
# chkconfig: - 90 10
# description:   The spice-webdavd package contains a daemon to proxy WebDAV request to \
#                the Spice virtio channel.
# processname: spice-webdavd
# config: /etc/sysconfig/spice-webdavd
# pidfile: /var/run/spice-webdavd.pid
### BEGIN INIT INFO
# Provides: spice-webdavd
# Required-Start: messagebus avahi-daemon
# Should-Start: messagebus avahi-daemon
# Should-Stop: $null
# Required-Stop: $null
# Default-Stop: 0 1 6
# Short-Description: Webdav daemon for Spice guests
# Description: The spice-webdavd package contains a daemon to proxy WebDAV request to \
#              the Spice virtio channel.
### END INIT INFO

# Do not load RH compatibility interface.
WITHOUT_RC_COMPAT=1

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

PIDFILE=/var/run/spice-webdavd.pid
LOCKFILE=/var/lock/subsys/spice-webdavd
RETVAL=0

start()
{
	start_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --expect-user root -- spice-webdavd
	RETVAL=$?
	return $RETVAL
}

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

restart()
{
	stop
	start
}

reload()
{
	msg_reloading spice-webdavd
	stop_daemon --pidfile "$PIDFILE" --expect-user root -HUP -- spice-webdavd
	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 -- spice-webdavd
		RETVAL=$?
		;;
	*)
		msg_usage "${0##*/} {start|stop|reload|restart|condstop|condrestart|condreload|status}"
		RETVAL=1
esac

exit $RETVAL
