]> pilppa.org Git - familiar-h63xx-build.git/blob - org.handhelds.familiar/packages/arpwatch/files/init.d
OE tree imported from monotone branch org.openembedded.oz354fam083 at revision 8b12e3...
[familiar-h63xx-build.git] / org.handhelds.familiar / packages / arpwatch / files / init.d
1 #!/bin/sh
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.
10
11 PATH=/sbin:/bin:/usr/sbin:/usr/bin
12 NAME=arpwatch
13 DAEMON=/usr/sbin/$NAME
14 DESC="Ethernet/FDDI station monitor daemon"
15 DATADIR=/var/lib/$NAME
16
17 test -x $DAEMON || exit 0
18
19 ### You shouldn't touch anything below unless you know what you are doing.
20
21 [ -f /etc/default/arpwatch ] && . /etc/default/arpwatch
22
23 # Decide whether we have to deal with multiple interfaces.
24 CONF=/etc/arpwatch.conf
25 MULTIPLE=0
26 if [ -r $CONF ]; then
27         grep -c '^[a-z]' $CONF 2>&1 >/dev/null && MULTIPLE=1
28 fi
29
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"
34         else
35                 RUNAS=""
36         fi
37 fi
38
39 start_instance () {
40         IFACE=$1
41         INSTANCE=${NAME}-${IFACE}
42         IFACE_OPTS="-i ${IFACE} -f ${IFACE}.dat $2"
43         DATAFILE=$DATADIR/${IFACE}.dat
44
45         echo -n "Starting $DESC: "
46         if [ ! -f $DATAFILE ]; then
47                 echo -n "(creating $DATAFILE) "
48                 :> $DATAFILE
49         fi
50         if [ -n "$RUNAS" ]; then
51                 echo -n "(chown $RUNAS $DATAFILE) "
52                 chown $RUNAS $DATAFILE
53         fi
54         start-stop-daemon --start --quiet \
55                 --pidfile /var/run/${INSTANCE}.pid \
56                 --exec $DAEMON -- $IFACE_OPTS $ARGS
57         echo "${INSTANCE}."
58         ps h -C $NAME -o pid,args | \
59                 awk "/$IFACE/ { print \$1 }" > /var/run/${INSTANCE}.pid
60 }
61
62 stop_instance () {
63         IFACE=$1
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
69         echo "${INSTANCE}."
70         rm -f /var/run/${INSTANCE}.pid
71 }
72
73 process_loop_break_line () {
74         __IFACE=$1
75         shift
76         __IOPTS="$@"
77 }
78
79 process_loop () {
80         OPERATION=$1
81         grep '^[a-z]' $CONF 2>/dev/null | \
82         while read LINE
83         do
84                 process_loop_break_line $LINE
85                 I=$__IFACE
86                 I_OPTS="$__IOPTS"
87                 $OPERATION $I "$I_OPTS"
88         done
89 }
90
91 start_default () {
92         echo -n "Starting $DESC: "
93         if [ ! -f $DATADIR/arp.dat ]; then
94                 echo -n "(creating $DATADIR/arp.dat) "
95                 :> $DATADIR/arp.dat
96         fi
97         if [ -n "$RUNAS" ]; then
98                 echo -n "(chown $RUNAS $DATADIR/arp.dat) "
99                 chown $RUNAS $DATADIR/arp.dat
100         fi
101         start-stop-daemon --start --quiet \
102                 --exec $DAEMON -- $ARGS
103         echo "$NAME."
104 }
105
106 stop_default () {
107         echo -n "Stopping $DESC: "
108         start-stop-daemon --stop --quiet --oknodo \
109                 --exec $DAEMON
110         echo "$NAME."
111         rm -f /var/run/$NAME.pid
112 }
113
114 startup () {
115         if [ "$MULTIPLE" -gt 0 ]; then
116                 process_loop start_instance
117         else
118                 start_default
119         fi
120 }
121
122 shutdown () {
123         if [ "$MULTIPLE" -gt 0 ]; then
124                 process_loop stop_instance
125         else
126                 stop_default
127         fi
128 }
129
130 case "$1" in
131   start)
132         startup
133         ;;
134   stop)
135         shutdown
136         ;;
137   reload)
138         echo "Reload operation not supported -- use restart."
139         exit 1
140         ;;
141   restart|force-reload)
142         #
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".
146         #
147         shutdown
148         sleep 1
149         startup
150         ;;
151   *)
152         N=/etc/init.d/$NAME
153         # echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2
154         echo "Usage: $N {start|stop|restart|force-reload}" >&2
155         exit 1
156         ;;
157 esac
158
159 exit 0