#!/bin/sh

# controll all local daemons [start|stop|restart|status]
# usefull after a port update to make sure everything is runnig
# 2010-01 olli hauer

SERVICE=/usr/sbin/service
RCPATH=/usr/local/etc/rc.d

_dcontrol(){
for PROG in $(${SERVICE} -re | grep ${RCPATH}); do
    ${PROG} status 1>/dev/null
    _ret=$?
    case ${1} in
        start)   [ $_ret -eq 1 ] && ${PROG} start ;;
        stop)    [ $_ret -eq 0 ] && ${PROG} stop  ;;
        restart) ${PROG} restart ;;
        status)  ${PROG} status ;;
    esac
done
}

case ${1} in
    start)      _dcontrol start ;;
    stop)       _dcontrol stop ;;
    restart)    _dcontrol restart ;;
    *|status)   _dcontrol status ;;
esac
