#!/bin/sh
##
##  consul-openpkg-service -- Consul utility for checking OpenPKG package "active" status
##

#   sanity check usage
if [ $# -ne 1 ]; then
    echo "USAGE: consul-openpkg-service <package>" 1>&2
    exit 1
fi

#   query package status
package="$1"
eval `@l_prefix@/bin/openpkg rc -s "$package" status`
if [ $? -ne 0 ]; then
    exit 1
fi

#   translate OpenPKG "active" status to Consul check script exit code
var=`echo "$package" | sed -e 's;-;_;g'`
var="${var}_active"
eval "val=\$$var"
if [ ".$val" = .yes ]; then
    code=0
else
    code=2
fi

#   die gracefully with Consul check script exit code
exit $code

