mumudvb.init 3.43 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
#!/bin/sh
### BEGIN INIT INFO
# Provides:          mumudvb
# Required-Start:    $remote_fs $network $syslog
# Required-Stop:     $remote_fs $network $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: mumudvb
# Description:       Digital television streaming program
### END INIT INFO

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/bin/mumudvb
PIDDIR=/var/run/mumudvb
DEFAULT_FILE=/etc/default/mumudvb
NAME=mumudvb
DESC="television streaming program"

#Reading of the config file
if [ -f "$DEFAULT_FILE" ] ; then
        . "$DEFAULT_FILE"
fi

if [ "$DONTSTARTMUMU" = "true" ]; then exit 0; fi

. /lib/lsb/init-functions

test -x $DAEMON || exit 5

set -e

do_start() {
        if [ ! -d $PIDDIR ]; then
                mkdir -p $PIDDIR
        fi
        chown $DAEMONUSER $PIDDIR
	if [ -x "$LAUNCH_BEFORE_MUMU" ]; then
		log_daemon_msg "Launching pre script ..."
		eval $LAUNCH_BEFORE_MUMU
		log_daemon_msg "Done."
	fi
	if test -z "$2" ; then
		RET=1
		for ADAPTER in $ADAPTERS; do
			log_daemon_msg " Starting card $ADAPTER"
			eval CONFIG_FILE=\$MUMUDVB_CONF_$ADAPTER
			if [ ! -f $CONFIG_FILE ]; then
                	   log_warning_msg " Card $ADAPTER: Config file $CONFIG_FILE not found."
			else
			   start-stop-daemon --start --oknodo --pidfile "$PIDDIR/mumudvb_carte$ADAPTER.pid"\
               			 --chuid $DAEMONUSER --exec $DAEMON -- $DAEMON_OPTS --card $ADAPTER -c $CONFIG_FILE
			   RET=$(($RET * $?))
			fi
		done
		return $RET
	else
		ADAPTER=$2
		log_daemon_msg " Starting card $ADAPTER"
		eval CONFIG_FILE=\$MUMUDVB_CONF_$ADAPTER
		if [ ! -z $CONFIG_FILE ]; then
			if [ ! -f $CONFIG_FILE ]; then
			    log_warning_msg " Card $ADAPTER: Config file $CONFIG_FILE not found."
			else
			    start-stop-daemon --start --oknodo --pidfile "$PIDDIR/mumudvb_adapter${ADAPTER}_tuner0.pid"\
                                 --chuid $DAEMONUSER --exec $DAEMON -- $DAEMON_OPTS --card $ADAPTER -c $CONFIG_FILE
			   return $?
			fi
		else
			log_failure_msg " MUMUDVB_CONF_$ADAPTER not set."
			return 1
		fi
	fi
}

do_stop() {
	if test -z "$2" ; then
		RET=1
		for PIDFILE in `ls $PIDDIR/mumudvb_adapter*.pid 2> /dev/null`; do
		        start-stop-daemon --stop --oknodo --pidfile "$PIDFILE" \
        		        --exec $DAEMON
			RET=$(($RET * $?))
		done
			return $RET
	else
		ADAPTER=$2
		log_daemon_msg " Stopping card $ADAPTER"
		if [ -f "$PIDDIR/mumudvb_adapter${ADAPTER}_tuner0.pid" ]; then
			start-stop-daemon --stop --oknodo --pidfile "$PIDDIR/mumudvb_adapter${ADAPTER}_tuner0.pid" \
                                --exec $DAEMON
			return $?
		else
			log_warning_msg " $PIDDIR/mumudvb_adapter${ADAPTER}_tuner0.pid not found"
			return 1
		fi
	fi
}

case "$1" in
  start)
        if [ ! -f "$DEFAULT_FILE" ]; then
                log_failure_msg "$DEFAULT_FILE not found, Can't start $NAME"
                exit 6
        fi

        log_daemon_msg "Starting $DESC: $NAME"
        do_start $@
        log_end_msg $?
        ;;
  stop)
        log_daemon_msg "Stopping $DESC: $NAME"
        do_stop $@
        log_end_msg $?
        ;;
  restart|force-reload)
        log_daemon_msg "Restarting $DESC: $NAME"
        do_stop $@
        sleep 1
        do_start $@
        log_end_msg $?
        ;;
  status)
        status_of_proc "$DAEMON" "$DESC: $NAME" && exit 0 || exit $?
        ;;
  *)
        log_success_msg "Usage: $0 {start|stop|restart|force-reload|status} [adaptater number]" >&2
        exit 1
        ;;
esac

exit 0