#!/bin/bash

# Start and stop pwrkap service
# (C) Copyright IBM Corp. 2008-2009
# Licensed under the GPLv2.

### BEGIN INIT INFO
# Provides:          pwrkap
# Required-Start:    
# Required-Stop:     
# Default-Start:     S
# Default-Stop:      
# Short-Description: start pwrkap
### END INIT INFO

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

[ -x /usr/bin/pwrkap_main ] || exit 0

. /lib/lsb/init-functions

case "$1" in
start)
    /usr/bin/pwrkap_main
    ;;
stop)
    ps ax | grep -v grep | grep pwrkap_main.py | while read pid junk; do kill $pid; done
    ;;
restart|force-reload)
    $0 stop
    $0 start
    ;;
status)
    PWRKAPS=`ps ax | grep -v grep | grep pwrkap_main.py -c`
    if [ $PWRKAPS -lt 1 ]; then
        echo "pwrkap is not running."
    elif [ $PWRKAPS -gt 1 ]; then
        echo "Multiple copies of pwrkap are running.  Turn some of them off."
    else
        echo "pwrkap is running."
    fi
    ;;
*)
    echo "Usage: $0 {start|stop|restart|force-reload|status}"
    exit 1
    ;;
esac

exit 0

