#!/bin/sh
### BEGIN INIT INFO
# Provides:          razerd
# Required-Start:    $local_fs $remote_fs
# Required-Stop:     $local_fs $remote_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: razerd daemon
# Description:       Razer device state daemon
### END INIT INFO

export PATH="/usr/local/bin:$PATH"
NAME=razerd
DAEMON="$(which $NAME)"
PIDFILE="/run/razerd/razerd.pid"
DESC="Razer device state daemon"

. /lib/lsb/init-functions

case "$1" in
	start)
		log_begin_msg "Starting $DESC: $NAME"
		start-stop-daemon --start --quiet --pidfile $PIDFILE \
			--oknodo --exec "$DAEMON" -- \
			-f -B -P $PIDFILE
		log_end_msg $?
		;;
	stop)
		log_begin_msg "Stopping $DESC: $NAME"
		start-stop-daemon --stop --quiet --pidfile $PIDFILE \
			--name "$NAME"
		RES=$?
		rm -f $PIDFILE
		log_end_msg $RES
		;;
	restart|reload|force-reload)
		$0 stop
		sleep 1
		$0 start
		;;
	*)
		echo "Usage $0 [start|stop|restart|reload|force-reload]"
		exit 1
		;;
esac

exit 0
