#!/bin/sh
#
# emifreq:   Emifreq applet daemon
#
# description:  This is a daemon for changing the cpu speed through the emifreq gnome applet.
#               See http://zzrough.free.fr
#
# processname: emifreqd
# pidfile: /var/run/emifreqd.pid
#

# Sanity checks.
[ -x /usr/sbin/emifreqd ] || exit 0

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

# so we can rearrange this easily
processname=emifreqd
servicename=emifreq

RETVAL=0

start() {
    gprintf "Starting EmiFreq daemon: "
    daemon --check $servicename $processname
    RETVAL=$?
    echo
    [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$servicename && echo `/sbin/pidof $processname` > /var/run/emifreqd.pid
}

stop() {
    gprintf "Stopping EmiFreq daemon: "

    killproc $processname -TERM
    RETVAL=$?
    echo
    if [ $RETVAL -eq 0 ]; then
        rm -f /var/lock/subsys/$servicename
        rm -f /var/run/emifreqd.pid
    fi
}

# See how we were called.
case "$1" in
    start)
        start
        ;;
    stop)
        stop
        ;;
    status)
        status $processname
        RETVAL=$?
        ;;
    restart)
        stop
        start
        ;;
    condrestart)
        if [ -f /var/lock/subsys/$servicename ]; then
            stop
            start
        fi
        ;;
    *)
        gprintf "Usage: %s {start|stop|status|restart|condrestart}\n" "$0"
        ;;
esac
exit $RETVAL
