#!/bin/sh
#
# pmcd "plugin" for pmcheck
#

. $PCP_DIR/etc/pcp.env || exit 1
. $PCP_SHARE_DIR/lib/checkproc.sh

_do_args "$@"

if $sflag
then
    if [ -f "$PCP_RUN_DIR/pmcd.pid" ]
    then
	pid=`cat "$PCP_RUN_DIR/pmcd.pid"`
	if [ -n "$pid" ]
	then
	    found=`$PCP_PS_PROG $PCP_PS_ALL_FLAGS | $PCP_AWK_PROG '$2 == '"$pid"' { print "found"; exit }'`
	    if [ -n "$found" ]
	    then
		# pmcd is alive and well
		#
		[ "$verbose" -gt 0 ] && echo "PID $pid"
		exit
	    fi
	fi
    fi
    # not running, but provided there is a pmcd executable, we could
    # be activated
    #
    if which pmcd >/dev/null
    then
	status=1
    else
	status=2
	[ "$verbose" -gt 0 ] && echo "no pmcd executable"
    fi
elif $lflag
then
    [ "$verbose" -gt 0 ] && echo "Performance Metrics Collection Daemon - local source of performance data"
elif $aflag
then
    _ctl_svc activate pmcd || status=1
elif $dflag
then
    _ctl_svc deactivate pmcd || status=1
else
    [ $verbose -gt 0 ] && echo "botch sflag=$sflag aflag=$aflag dflag=$dflag show_me=$show_me verbose=$verbose"
    status=99
fi

exit
