#!/bin/sh

### BEGIN INIT INFO
# Provides:        spiceproxy
# Required-Start:  $remote_fs $network $syslog pveproxy
# Required-Stop:   $remote_fs $network $syslog pveproxy
# Default-Start:   2 3 4 5
# Default-Stop:    0 1 6
# Short-Description: PVE SPICE Proxy Server
### END INIT INFO

. /lib/lsb/init-functions

PATH=/sbin:/bin:/usr/bin:/usr/sbin
DAEMON=/usr/bin/spiceproxy
NAME=spiceproxy
DESC="PVE SPICE Proxy Server"
RUNDIR=/var/run/pveproxy
PIDFILE=${RUNDIR}/spiceproxy.pid

test -f $DAEMON || exit 0

# avoid warnings about uninstalled locales when pveproxy executes commands
export LC_ALL="C"

mkdir -p ${RUNDIR} || true
chmod 0700 ${RUNDIR} || true
chown www-data:www-data ${RUNDIR} || true

DAEMON_OPTS=""

# Include defaults if available
if [ -f /etc/default/$NAME ] ; then
    . /etc/default/$NAME
fi
 
case "$1" in
    start)
	log_daemon_msg "Starting $DESC" "$NAME"
	$DAEMON start
 	log_end_msg $?
  	;;
    stop)
	log_daemon_msg "Stopping $DESC" "$NAME"
	$DAEMON stop
	log_end_msg $?
  	;;
    restart|force-reload)
	log_daemon_msg "Restarting $DESC" "$NAME"
	$DAEMON restart
	log_end_msg $?
  	;;
    *)
	N=/etc/init.d/$NAME
  	echo "Usage: $N {start|stop|restart|force-reload}"
  	exit 1
	;;
esac

exit 0
