#!/sbin/runscript
PIDFILE=/var/run/driveclient.pid
DAEMON=driveclient
ARGS="--daemon"

depend() {
	# the daemon needs the internet to function
	need net
	# the daemon uses logger
	use logger
	# the daemon should run after domainname
	after domainname
}

start() {
	# display to the user what you're doing
	if [ -f $PIDFILE ]; then
		ebegin "Restarting driveclient"
		stop
	else
		ebegin "Starting driveclient"
	fi
	# Start the process as a daemon and record the pid number
	start-stop-daemon --start --background --pidfile ${PIDFILE} --exec ${DAEMON} -- ${ARGS}
	# output success or failure
	eend $?
}

stop() {
	# display a message to the user
	ebegin "Stopping driveclient"
	# stop the daemon using the pid recorded from the start() function
	if [ -f $PIDFILE ]; then
		start-stop-daemon --stop --pidfile ${PIDFILE} --name driveclient
		if [ $? -gt 0 ]; then
			ewarn "refused to stop, trying -9"
			start-stop-daemon --stop -s9 --pidfile ${PIDFILE} --name driveclient
		fi
	fi
	# output success or failure
	eend $?
}
