Difference between revisions of "Code/tp-fancontrol.init"

From ThinkWiki
Jump to: navigation, search
m (Undo corruption)
(Put script in <pre> block, so it can be copy-pasted)
 
Line 1: Line 1:
 +
<pre>
 
#! /bin/sh
 
#! /bin/sh
 
### BEGIN INIT INFO
 
### BEGIN INIT INFO
Line 95: Line 96:
  
 
exit 0
 
exit 0
 +
</pre>

Latest revision as of 09:28, 11 April 2025

#! /bin/sh
### BEGIN INIT INFO
# Provides:             tp-fancontrol
# Default-Start:        2 3 4 5
# Default-Stop:         S 0 1 6
### END INIT INFO
# Copyright (c) 2006 Ronald Aigner <ra3@os.inf.tu-dresden.de>

set -e

DAEMON=/usr/bin/tp-fancontrol
NAME=tp-fancontrol
DAEMONUSER=root
PIDDIR=/var/run
PIDFILE=$PIDDIR/tp-fancontrol.pid
DESC="Thinkpad CPU fan control"

test -x $DAEMON || exit 0

# source config file; edit that file to configure this script
TEMP_SHIFT=0
LOG_SYSLOG=1
QUIET=1
if [ -e /etc/tp-fancontrol.conf ]; then
  . /etc/tp-fancontrol.conf
fi
 
start_it()
{
  PARAMS=-d
  if [ -e $PIDFILE ]; then
    echo "$DESC already running. Stop first."
    exit 1
  fi
  if [ "$TEMP_SHIFT" != "0" ]; then
    PARAMS=$PARAMS" -s $TEMP_SHIFT"
  fi
  if [ "$LOG_SYSLOG" = "1" ]; then
    PARAMS=$PARAMS" -l"
  else
    if [ "$QUIET" = "1" ]; then
      PARAMS=$PARAMS" -q"
    fi
  fi
  PARAMS=$PARAMS" -p $PIDFILE"

  echo -n "Starting $DESC: $NAME ... "
  $DAEMON $PARAMS
  if [ "$?" = "0" ]; then
    echo "Success."
  else
    echo "Error while starting: $?"
  fi
}
 
stop_it()
{
  if [ -e $PIDFILE ]; then
    echo -n "Stopping $DESC ... "
    $DAEMON -k
    if [ "$?" = "0" ]; then
      echo "Success."
    else
      echo "Error while stopping: $?"
    fi
  else
    echo "$DESC not running."
  fi
}

restart_it()
{
  if [ -e $PIDFILE ]; then
    stop_it
    sleep 2
  fi
  start_it
}

case "$1" in
  start)
    start_it
  ;;
  stop)
    stop_it
  ;;
  reload|force-reload|restart)
    restart_it
  ;;
  *)
    echo "Usage: /etc/init.d/$NAME {start|stop|reload|restart|force-reload}" >&2
    exit 1
  ;;
esac

exit 0