#!/bin/sh
# chkconfig: 2345 12 88
### BEGIN INIT INFO
# Provides:          acpid
# Required-Start:    $local_fs
# Required-Stop:
# Should-Start:      $network
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start acpid at boot time
# Description:       Enable service provided by acpid.
# X-Start-Before:
# X-Stop-After:
# X-Timesys-Start-Number:  12
# X-Timesys-Stop-Number:   88
### END INIT INFO

PATH=/usr/bin:/bin:/usr/sbin:/sbin

case "$1" in

    start)
        echo -n "Starting acpid: "

        if [ -n "$(pidof acpid)" ]; then
            echo "acpid is already running."
            exit 1
        fi

        /usr/sbin/acpid -n
        if [ $? -ne 0 ]; then
            echo "[FAIL]"
            exit 1
        fi

        echo "[OK]"
        ;;

    stop)
        echo -n "Stopping acpid: "

        PID=$(pidof acpid)
        if [ -z "$PID" ]; then
            echo "acpid is not running."
            exit 1
        fi

        for pid in $PID; do kill $pid >/dev/null 2>&1; done

        echo "[OK]"
        ;;

    restart)
        $0 stop
        sleep 1
        $0 start
        ;;

    *)
        echo "Usage: $0 [start|stop|restart]"
        exit 1
        ;;

esac

