#!/bin/sh

case "$1" in
  stop)
    PIDFILE=/tmp/zabbix_agentd.pid
    if [ -f ${PIDFILE} ]; then
      pid=`cat ${PIDFILE}`
      kill ${pid}
      sleep 5
    fi
    ;;
  start|restart)
    $0 stop
    # Bail if this is a dialup backchannel
    PPPFILE=/etc/ppp/ppp.conf.local
    if [ -f ${PPPFILE} ]; then
        exit 0
    fi
    # Not dialup backchannel, start her up!
    if [ "x$USER" != "xdgadmin" ]; then
        su - dgadmin -c "/usr/local/sbin/zabbix_agentd --config /usr/local/etc/zabbix_agentd.conf"
    else
        /usr/local/sbin/zabbix_agentd --config /usr/local/etc/zabbix_agentd.conf
    fi

    echo -n ' zabbix_agentd'
    ;;
esac
