#!@l_prefix@/bin/openpkg rc
##
##  rc.dss -- Run-Commands
##

%config
    dss_enable="$openpkg_rc_def"
    dss_admin="no"

%common
    dss_daemon_pidfile="@l_prefix@/var/dss/dssdaemon.pid"
    dss_admin_pidfile="@l_prefix@/var/dss/dssadmin.pid"
    dss_signal () {
        if [ ".$2" = ".daemon" ]; then
            [ -f $dss_daemon_pidfile ] && kill -$1 `cat $dss_daemon_pidfile`
        elif [ ".$2" = ".admin" ]; then
            [ -f $dss_admin_pidfile ] && kill -$1 `cat $dss_admin_pidfile`
        else
            [ -f $dss_daemon_pidfile ] && kill -$1 `cat $dss_daemon_pidfile`
            local rc=$?
            [ -f $dss_admin_pidfile ] && kill -$1 `cat $dss_admin_pidfile` && [ $rc -eq 0 ]
            [ $? -eq 0 ]
        fi
    }

%status -u @l_susr@ -o
    dss_usable="unknown"
    dss_active="no"
    rcService dss enable yes && \
        dss_signal 0 daemon && dss_active="yes"
    rcService dss enable yes && \
        dss_signal 0 admin && dss_active="yes"
    echo "dss_enable=\"$dss_enable\""
    echo "dss_usable=\"$dss_usable\""
    echo "dss_active=\"$dss_active\""

%start -u @l_susr@
    rcService dss enable yes || exit 0
    rcService dss active yes && exit 0
    @l_prefix@/sbin/DarwinStreamingServer
    if rcVarIsYes dss_admin; then
        @l_prefix@/sbin/streamingadminserver
    fi

%stop -u @l_susr@
    rcService dss enable yes || exit 0
    rcService dss active no && exit 0
    dss_signal TERM daemon
    if rcVarIsYes dss_admin; then
        dss_signal TERM admin
        rm -f $dss_admin_pidfile >/dev/null 2>&1 || true
    fi

%restart -u @l_susr@
    rcService dss enable yes || exit 0
    rcService dss active no && exit 0
    rc dss stop
    sleep 2
    rc dss start

