#!/bin/bash

. /etc/profile

[ ! -d /var/state/ups ] && mkdir -p /var/state/ups

service_start() {
    /usr/bin/upsctl start
}

service_stop() {
    /usr/bin/upsctl stop
}

service_status() {
    #/usr/bin/upsctl status
    local pid=$(pidof upsd)
    if [ -z "$pid" ]; then
        echo "upsd stopped"
    else
        echo "upsd running"
    fi
}

case $1 in
start)
    service_start
    ;;
stop)
    service_stop
    ;;
status)
    service_status
    ;;
*)
    echo "$0 {start|stop|status}"
    exit 1
    ;;
esac

exit 0
