#!/bin/sh
# Start/stop the ThinkPad fan control daemon.
#
### BEGIN INIT INFO
# Provides:          tpfand
# Required-Start:    $syslog $time
# Required-Stop:     $syslog $time
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: ThinkPad Fan Control daemon
# Description:       tpfand controls the fan speed of an IBM/Lenovo ThinkPad
#		     		 notebook. It can be configured by running tpfan-admin.
### END INIT INFO

test -f /usr/sbin/tpfand || exit 0

. /lib/lsb/init-functions

case "$1" in
start)	log_daemon_msg "Starting ThinkPad fan control daemon" "tpfand"
        start-stop-daemon --start --quiet --pidfile /var/run/tpfand.pid --name tpfand --startas /usr/sbin/tpfand -- $LSBNAMES --quiet
        log_end_msg $?
	;;
stop)	log_daemon_msg "Stopping ThinkPad fan control daemon" "tpfand"
        start-stop-daemon --stop --quiet --pidfile /var/run/tpfand.pid 
		rm -f /var/run/tpfand.pid 
        log_end_msg $?
        ;;
restart) log_daemon_msg "Restarting ThinkPad fan control daemon" "tpfand" 
        start-stop-daemon --stop --retry 5 --quiet --pidfile /var/run/tpfand.pid
		rm -f /var/run/tpfand.pid 
        start-stop-daemon --start --quiet --pidfile /var/run/tpfand.pid --name tpfand --startas /usr/sbin/tpfand -- $LSBNAMES
        log_end_msg $?
        ;;
*)	log_action_msg "Usage: /etc/init.d/tpfand {start|stop|restart}"
        exit 2
        ;;
esac
exit 0
