#!/bin/bash
### BEGIN INIT INFO
# Provides:          folding@home
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start folding@home at boot
### END INIT INFO

DESC='Folding @ Home Client'
USER=fah
GROUP=nogroup
WORKING=/var/cache/fah
BIN=fah6
MYPID=/var/run/fah.pid
OPTS='-verbosity 9 -smp'

case "$1" in
	start)
		echo -n "Starting Folding@home "
		start-stop-daemon --start --quiet --background --chuid ${USER}:${GROUP} --user ${USER} --group ${GROUP} --chdir ${WORKING} --make-pidfile --pidfile ${MYPID} --exec ${WORKING}/${BIN} -- ${OPTS}
		echo "."
	;;
	stop)
		echo -n "Stopping Folding@home "
		start-stop-daemon --stop --signal 3 --quiet --user ${USER} --group ${GROUP} --chdir ${WORKING} --oknodo --pidfile ${MYPID}
		echo "."
	;;
	restart | force-reload)
		$0 stop
		sleep 2
		$0 start
		exit $?
	;;
	status)
		echo -n "Status of $DESC: "
		ps aux | grep Core_
	;;
	*)
		log_success_msg "Usage: $0 {start|stop|restart|force-reload|status}"
		exit 1 
esac

exit 0
