#!/bin/sh
#
# spice-vdagentd Agent daemon for Spice guests
#
# chkconfig:   345 70 30
# description: Together with a per X-session agent process the spice agent \
#              daemon enhances the spice guest user experience with client \
#              mouse mode, guest <-> client copy and paste support and more.

### BEGIN INIT INFO
# Provides: spice-vdagentd
# Required-Start: $local_fs messagebus
# Required-Stop: $local_fs messagebus
# Should-Start: $local_fs messagebus
# Should-Stop: $local_fs messagebus
# Default-Start: 5
# Default-Stop: 0 1 2 3 4 6
# Short-Description: Agent daemon for Spice guests
# Description: Together with a per X-session agent process the spice agent
#	daemon enhances the spice guest user experience with client
#	mouse mode, guest <-> client copy and paste support and more.
### END INIT INFO

# Do not load RH compatibility interface.
WITHOUT_RC_COMPAT=1

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

EXEC=spice-vdagentd
PORT=/dev/virtio-ports/com.redhat.spice.0
PIDFILE=/var/run/spice-vdagentd/spice-vdagentd.pid

SourceIfNotEmpty /etc/sysconfig/$EXEC

LOCKFILE=/var/lock/subsys/$EXEC
RETVAL=0

start() {
	modprobe uinput > /dev/null 2>&1
	start_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --expect-user root -- $EXEC $SPICE_VDAGENTD_EXTRA_ARGS
	RETVAL=$?
	return $RETVAL
}

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

restart() {
    stop
    start
}

# See how we were called.
case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	status)
		status --pidfile "$PIDFILE" --expect-user root -- $EXEC
		RETVAL=$?
		;;
	reload)
		restart
		;;
	restart)
		restart
		;;
	condstop)
		if [ -e "$LOCKFILE" ]; then
			stop
		fi
		;;
	condreload)
		if [ -e "$LOCKFILE" ]; then
			reload
		fi
		;;
	condrestart)
		if [ -e "$LOCKFILE" ]; then
			restart
		fi
		;;
	*)
		msg_usage "${0##*/} {start|stop|status|reload|restart|condstop|condrestart|condreload}"
		RETVAL=1
esac

exit $RETVAL
