#!/bin/sh
#
# spacenavd	 free driver for 3Dconnexion 6dof devices
#
# chkconfig: 2345 99 99
# description: A free user space driver for 3Dconnexion input devices,\
#	       compatible with the proprietary 3dxsrv daemon.
### BEGIN INIT INFO
# Provides:	     spacenavd
# 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: start spacenavd daemon
# Description:	     free user space driver for 3Dconnexion input devices
### END INIT INFO


DAEMON=/usr/sbin/spacenavd

[ -x "$DAEMON" ] || exit 0

case "$1" in
start)
	echo 'Starting spacenavd daemon'
	$DAEMON -v
	;;

stop)
	echo 'Stopping spacenavd daemon'
	# detect daemon's process id
	pid=`cat /var/run/spnavd.pid 2>/dev/null`
	if [ $? != 0 ]; then
		pid=`ps -e | grep spacenavd | awk '{ print $1 }'`
		if [ -z "$pid" ]; then
			echo 'spacenavd daemon is not running, nothing to do.'
			exit 1
		fi
	fi
	kill $pid
	;;

reload|restart|force-reload)
	$0 stop && sleep 1 && $0 start
	;;

status)
	pid=`cat /var/run/spnavd.pid 2>/dev/null`
	if [ $? != 0 ]; then
		echo 'spacenavd daemon is not running.'
		exit 3
	else
		echo 'spacenavd daemon is running.'
		exit 0
	fi
	;;
esac
