# script to controll all local daemons



## ohauer (May 8, 2010)

Hi,

maybe someone can use this small script during a large port update.

I wrote the script since it is easy to forget start/restart a prog during/after a large port update.

daemon_control

```
#!/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


_dcontrol(){
for PROG in `find /usr/local/etc/rc.d/ -type f`; do
    _RCVAR=`${PROG} rcvar | grep -v ^# | awk -F\= '{print $2}'`
    if [ "${_RCVAR}" = "YES" ]; then
        ${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
    fi
done
}

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


----------



## DutchDaemon (May 8, 2010)

It's probably wise to incorporate rcorder(8) into this. E.g.: you want to start/restart MySQL before Apache, but in your script it would be the other way around (alphabetically).


----------

