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

%config
    icecast_enable="$openpkg_rc_def"

%common
    icecast_cfgfile="@l_prefix@/etc/icecast/icecast.xml"
    icecast_pidfile="@l_prefix@/var/icecast/icecast.pid"
    icecast_signal () {
        [ -f $icecast_pidfile ] && kill -$1 `cat $icecast_pidfile`
    }

%status -u @l_nusr@ -o
    icecast_usable="unknown"
    icecast_active="no"
    rcService icecast enable yes && \
        icecast_signal 0 && icecast_active="yes"
    echo "icecast_enable=\"$icecast_enable\""
    echo "icecast_usable=\"$icecast_usable\""
    echo "icecast_active=\"$icecast_active\""

%start -u @l_nusr@
    rcService icecast enable yes || exit 0
    rcService icecast active yes && exit 0
    @l_prefix@/bin/icecast -b -c $icecast_cfgfile

%stop -u @l_nusr@
    rcService icecast enable yes || exit 0
    rcService icecast active no  && exit 0
    icecast_signal TERM
    sleep 2
    rm -f $icecast_pidfile >/dev/null 2>&1 || true

%restart -u @l_nusr@
    rcService icecast enable yes || exit 0
    rcService icecast active no  && exit 0
    rc icecast stop start

