File rcscript of Package ntripcaster

#! /bin/sh
#
# System startup script for the Ntripcaster
#
### BEGIN INIT INFO
# Provides:          ntripcaster
# Required-Start:    $network $remote_fs
# Should-Start:
# Required-Stop:     $network $remote_fs
# Should-Stop:
# Default-Start:     3 5
# Default-Stop:      0 1 2 6
# Short-Description: Ntripcaster
# Description:       Start the ntripcaster daemon
### END INIT INFO

CASTER=/usr/sbin/ntripcaster
test -x $CASTER || exit 5

CASTER_CONFIG=/etc/ntripcaster/ntripcaster.conf
SOURCETABLE=/etc/ntripcaster/sourcetable.dat
test -f $CASTER_CONFIG || exit 6

CASTER_LOGBASE=/var/log/ntripcaster.log
CASTER_LOG=$(CASTER_LOGBASE).log

# Source SuSE config
. /etc/rc.status

rc_reset
case "$1" in
    start)
        b=`date +%Y-%m-%dT%H:%M`
        echo -n "Starting Ntripcaster daemon"
        mv $CASTER_LOG $(CASTER_LOGBASE)_$b.log 2>/dev/null >/dev/null
        startproc -f $CASTER 2>/dev/null >/dev/null
        rc_status -v
        ;;
    stop)
        echo -n "Shutting down Ntripcaster daemon"
        killproc -TERM $CASTER
        rc_status -v
        ;;
    try-restart)
        $0 status >/dev/null && $0 restart
        rc_status
        ;;
    restart)
        $0 stop
        $0 start
        rc_status
        ;;
    force-reload)
        $0 try-restart
        rc_status
        ;;
    reload)
        $0 try-restart
        rc_status
        ;;
    status)
        echo -n "Checking for Ntripcaster service"
        checkproc $CASTER
        rc_status -v
        if [ -f $CASTER_LOG ]; then
        perl -e '
          if(open CONF, "<'$CASTER_CONFIG'")
          {
            while(<CONF>)
            {
              if(/^(\/.*?)(:.*)$/) { $a{$1} = ""; $c{$1} = 1; $u{$1} = 0; }
            }
            close CONF;
          }
          if(open CONF, "<'$SOURCETABLE'")
          {
            while(<CONF>)
            {
              if(/^STR;(.*?);/) { $a{"/$1"} = ""; $s{"/$1"} = 1; $u{"/$1"} = 0; }
            }
            close CONF;
          }

          while(<>)
          {
            if(/([^ ]+) \[.*?\] Accepted encoder on mountpoint ([^ ]+)/)
            { $a{$2} = $1; $u{$2} = 1; }
            if(/([^ ]+) \[.*?\] Lost connection to source on mount ([^,]+)/)
            { $b{$2} = $1; $u{$2} = 0; }
            if(/([^ ]+) \[.*?\] Kicking source \d+ on mount ([^ ]+)/)
            { $b{$2} = $1; $u{$2} = 0; }
          }
          print "A Lost                   Activated              CS Stream\n";
          foreach my $x (sort keys %a)
          {
            printf "$u{$x} %22s %22s %s%s $x\n",($b{$x}&&!$u{$x}?$b{$x}:""),
            $u{$x}?$a{$x}:"",$c{$x}?"C":" ",$s{$x}?"S":" ";
          }
        ' $CASTER_LOG
        fi
        ;;
    *)
        echo "Usage: $0 {start|stop|status|try-restart|restart|force-reload|reload}"
        exit 1
        ;;
esac
rc_exit
openSUSE Build Service is sponsored by