#!@l_prefix@/lib/openpkg/bash @l_prefix@/etc/rc
##
##  rc.mico -- Run-Commands for MICO Daemons
##

%config
    mico_enable="no"
    mico_micod="no"
    mico_nsd="no"
    micod_args="-ORBIIOPAddr inet:`uname -n`:8912"
    nsd_args="-ORBIIOPAddr inet:`uname -n`:8914"

%start -p 200 -u @l_musr@
    opServiceEnabled mico || exit 0
    #   run the object adapter daemon for dynamic object activation
    if opVarIsYes mico_micod; then
        @l_prefix@/bin/micod ${micod_args} &
        echo $! > @l_prefix@/var/mico/micod.pid
    fi
    #   run the name service daemon for flexible object indexing
    if opVarIsYes mico_nsd; then
        @l_prefix@/bin/nsd ${nsd_args} &
        echo $! > @l_prefix@/var/mico/nsd.pid
    fi

%stop -p 200 -u @l_musr@
    opServiceEnabled mico || exit 0
    if opVarIsYes mico_micod; then
        #   first test if object adapter daemon is running
        if [ -f @l_prefix@/var/mico/micod.pid ]; then
            kill -TERM `cat @l_prefix@/var/mico/micod.pid`
            rm @l_prefix@/var/mico/micod.pid
        fi
    fi
    if opVarIsYes mico_nsd; then
        #   first test if name service daemon is running
        if [ -f @l_prefix@/var/mico/nsd.pid ]; then
            kill -TERM `cat @l_prefix@/var/mico/nsd.pid`
            rm @l_prefix@/var/mico/nsd.pid
        fi
    fi

%restart -u @l_musr@
    opServiceEnabled mico || exit 0
    #   first test if object adapter daemon is running
    if [ -f @l_prefix@/var/mico/micod.pid ]; then
        kill -TERM `cat @l_prefix@/var/mico/micod.pid`
        sleep 2
    fi
    #   run the object adapter daemon for dynamic object activation
    @l_prefix@/bin/micod ${micod_args} &
    echo $! > @l_prefix@/var/mico/micod.pid
    #   first test if name service daemon is running
    if [ -f @l_prefix@/var/mico/nsd.pid ]; then
        kill -TERM `cat @l_prefix@/var/mico/nsd.pid`
        sleep 2
    fi
    #   run the name service daemon for flexible object indexing
    @l_prefix@/bin/nsd ${nsd_args} &
    echo $! > @l_prefix@/var/mico/nsd.pid
