#!/bin/sh
#
# thermald startup script for Slackware Linux

# Source function library.
. /etc/rc.d/init.d/functions

PIDFILE=/var/run/thermald/thermald.pid
PARAMS=""

# Load configuration
if [ -r /etc/default/thermald ]; then
  . /etc/default/thermald
fi

thermald_start() {
  if [ -s $PIDFILE ]; then
    echo "thermald appears to be already running?"
    exit 1
  fi

  echo -n "Starting thermald..."
  /usr/sbin/thermald $PARAMS &> /dev/null
  RETVAL=$?
  echo "ok"

  pidof thermald > $PIDFILE

  return $RETVAL
}

thermald_stop() {
  if [ ! -s $PIDFILE ]; then
    echo "$PIDFILE does not exist or is empty."
    exit 1
  fi

  echo -n "Stopping thermald..."
  killproc -p $PIDFILE thermald
  RETVAL=$?
  echo
  [ $RETVAL = 0 ] && rm -f $PIDFILE
}

thermald_restart() {
  thermald_stop
  sleep 3
  thermald_start
}

case "$1" in
  start)
    thermald_start
    ;;
  stop)
    thermald_stop
    ;;
  restart)
    thermald_restart
    ;;
  *)
    echo "Usage: $0 {start|stop|restart}"
    exit 1
esac
