File: linux-igd.init

package info (click to toggle)
linux-igd 1.0%2Bcvs20070630-4
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 460 kB
  • sloc: ansic: 1,951; xml: 593; sh: 135; makefile: 42
file content (108 lines) | stat: -rw-r--r-- 2,678 bytes parent folder | download | duplicates (2)
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
#! /bin/sh
### BEGIN INIT INFO
# Provides:          linux-igd
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: UPnP Internet Gateway Device
# Description:       Daemon that emulates Microsoft's Internet Connection Service (ICS)
#                    and implements the UPnP Internet Gateway Device specification (IGD).
### END INIT INFO

PATH=/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/sbin/upnpd
NAME=linux-igd
PIDFILE=/var/run/$NAME.pid
DESC="Linux IGD Daemon"

test -x $DAEMON || exit 0

# Include upnpd defaults if available
if [ -f /etc/default/$NAME ] ; then
	. /etc/default/$NAME
fi

# Check if defaults configured (don't fail on first installation).
if [ -z "$EXTIFACE" -a -z "$INTIFACE" ] ; then
	echo "/etc/default/$NAME not configured: $NAME not running" >&2
	exit 0
fi

# Verify options
if [ -z "$EXTIFACE" ] ; then
	echo "External interface not specified in /etc/default/$NAME" >&2
	exit 1
fi
if [ -z "$INTIFACE" ] ; then
	echo "Internal interface not specified in /etc/default/$NAME" >&2
	exit 1
fi

if [ "$CHROOT_DIR" ]; then
	RUN_OPTS="$RUN_OPTS --chroot $CHROOT_DIR"
fi

if [ "$UPNPD_USER" ]; then
	RUN_OPTS="$RUN_OPTS --chuid $UPNPD_USER"
fi
if [ "$UPNPD_GROUP" ]; then
	RUN_OPTS="$RUN_OPTS --group $UPNPD_GROUP"
fi

set -e

start () {
	# Don't abort if we merely failed to setup routing, maybe something
	# else is handling it after all.
	# In any case, "RT_NETLINK answers: File exists" is a poor diagnostic.
	[ "$ALLOW_MULTICAST" != "yes" ] || ip route add 224.0.0.0/4 dev $INTIFACE >/dev/null 2>&1 || true
	start-stop-daemon --start --quiet --oknodo $RUN_OPTS \
		--exec $DAEMON -- "$EXTIFACE" "$INTIFACE"  \
         && pidof `basename $DAEMON` > $PIDFILE
}

stop () {
	start-stop-daemon --stop --quiet --pidfile $PIDFILE --retry 30 --oknodo $RUN_OPTS \
		--exec $DAEMON
	# Don't abort if we merely failed to delete routing, maybe we're
	# restarting when it's not setup yet anyway.
	# Also suppress "RT_NETLINK answers: No such process" message
	[ "$ALLOW_MULTICAST" != "yes" ] || ip route del 224.0.0.0/4 dev $INTIFACE >/dev/null 2>&1 || true
}

signal () {
	start-stop-daemon --stop --quiet --pidfile $PIDFILE --signal "$1" $RUN_OPTS \
		--exec $DAEMON
}


case "$1" in
  start)
	echo -n "Starting $DESC: "
	start
	echo "$NAME."
	;;
  stop)
	echo -n "Stopping $DESC: "
	stop
	echo "$NAME."
	;;
  reset)
	echo "Resetting $DESC port mappings."
	signal USR1
	;;
  restart|force-reload)
	echo -n "Restarting $DESC: "
	stop
	sleep 1
	start
	echo "$NAME."
	;;
  *)
	echo "Usage: $0 {start|stop|restart|reset|force-reload}" >&2
	exit 1
	;;
esac

exit 0