2 # /etc/init.d/arpwatch: v9 2004/08/14 KELEMEN Peter <fuji@debian.org>
3 # Based on /etc/init.d/skeleton (1.8 03-Mar-1998 miquels@cistron.nl)
4 # 2001/10/26 fuji@debian.org Support multiple instances.
5 # 2001/11/24 fuji@debian.org Use POSIX-style functions.
6 # 2001/12/17 fuji@debian.org Use --pidfile on startup, fix restart.
7 # 2004/08/10 fuji@debian.org Source /etc/default/arwpatch .
8 # Create datafile if it doesn't exist.
9 # Run daemon only if executable.
11 PATH=/sbin:/bin:/usr/sbin:/usr/bin
13 DAEMON=/usr/sbin/$NAME
14 DESC="Ethernet/FDDI station monitor daemon"
15 DATADIR=/var/lib/$NAME
17 test -x $DAEMON || exit 0
19 ### You shouldn't touch anything below unless you know what you are doing.
21 [ -f /etc/default/arpwatch ] && . /etc/default/arpwatch
23 # Decide whether we have to deal with multiple interfaces.
24 CONF=/etc/arpwatch.conf
27 grep -c '^[a-z]' $CONF 2>&1 >/dev/null && MULTIPLE=1
30 # Check whether we have to drop privileges.
31 if [ -n "$RUNAS" ]; then
32 if getent passwd "$RUNAS" >/dev/null; then
33 ARGS="-u ${RUNAS} $ARGS"
41 INSTANCE=${NAME}-${IFACE}
42 IFACE_OPTS="-i ${IFACE} -f ${IFACE}.dat $2"
43 DATAFILE=$DATADIR/${IFACE}.dat
45 echo -n "Starting $DESC: "
46 if [ ! -f $DATAFILE ]; then
47 echo -n "(creating $DATAFILE) "
50 if [ -n "$RUNAS" ]; then
51 echo -n "(chown $RUNAS $DATAFILE) "
52 chown $RUNAS $DATAFILE
54 start-stop-daemon --start --quiet \
55 --pidfile /var/run/${INSTANCE}.pid \
56 --exec $DAEMON -- $IFACE_OPTS $ARGS
58 ps h -C $NAME -o pid,args | \
59 awk "/$IFACE/ { print \$1 }" > /var/run/${INSTANCE}.pid
64 INSTANCE=${NAME}-${IFACE}
65 [ -f /var/run/${INSTANCE}.pid ] || return 0
66 echo -n "Stopping $DESC: "
67 start-stop-daemon --stop --quiet --oknodo \
68 --pidfile /var/run/${INSTANCE}.pid
70 rm -f /var/run/${INSTANCE}.pid
73 process_loop_break_line () {
81 grep '^[a-z]' $CONF 2>/dev/null | \
84 process_loop_break_line $LINE
87 $OPERATION $I "$I_OPTS"
92 echo -n "Starting $DESC: "
93 if [ ! -f $DATADIR/arp.dat ]; then
94 echo -n "(creating $DATADIR/arp.dat) "
97 if [ -n "$RUNAS" ]; then
98 echo -n "(chown $RUNAS $DATADIR/arp.dat) "
99 chown $RUNAS $DATADIR/arp.dat
101 start-stop-daemon --start --quiet \
102 --exec $DAEMON -- $ARGS
107 echo -n "Stopping $DESC: "
108 start-stop-daemon --stop --quiet --oknodo \
111 rm -f /var/run/$NAME.pid
115 if [ "$MULTIPLE" -gt 0 ]; then
116 process_loop start_instance
123 if [ "$MULTIPLE" -gt 0 ]; then
124 process_loop stop_instance
138 echo "Reload operation not supported -- use restart."
141 restart|force-reload)
143 # If the "reload" option is implemented, move the "force-reload"
144 # option to the "reload" entry above. If not, "force-reload" is
145 # just the same as "restart".
153 # echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2
154 echo "Usage: $N {start|stop|restart|force-reload}" >&2