]> git.pld-linux.org Git - packages/ifplugd.git/blob - ifplugd.init
- use functions to avoid reexec for restart
[packages/ifplugd.git] / ifplugd.init
1 #!/bin/sh
2 #
3 # ifplugd               ifplugd
4 #
5 # chkconfig:    345 16 84
6 #
7 # description:  ifplugd
8
9
10 # Source function library
11 . /etc/rc.d/init.d/functions
12
13 # Get network config
14 . /etc/sysconfig/network
15
16 # Get service config
17 [ -f /etc/sysconfig/ifplugd ] && . /etc/sysconfig/ifplugd
18
19 # Check that networking is up.
20 if is_yes "${NETWORKING}"; then
21         if [ ! -f /var/lock/subsys/network -a "$1" != stop -a "$1" != status -a "$1" != init ]; then
22                 msg_network_down ifplugd
23                 exit 1
24         fi
25 else
26         exit 0
27 fi
28
29 start() {
30         # Check if the service is already running?
31         for iface in $INTERFACES; do
32                 if [ ! -f /var/lock/subsys/ifplugd.${iface} ]; then
33                         msg_starting "Network Interface Plugging Daemon ($iface)"
34                         args=$(eval echo \$\{ARGS_${IF}\})
35                         [ -z "$args" ] && args="${ARGS}"
36                         daemon /sbin/ifplugd -i ${iface} ${args}
37                         RETVAL=$?
38                         [ $RETVAL -eq 0 ] && touch /var/lock/subsys/ifplugd.${iface}
39                 else
40                         msg_already_running "ifplugd ($iface)"
41                 fi
42         done
43 }
44
45 stop() {
46         for iface in $INTERFACES; do
47                 if [ -f /var/lock/subsys/ifplugd.${iface} ]; then
48                         msg_stopping "Network Interface Plugging Daemon ($iface)"
49                         daemon /sbin/ifplugd -k -i ${iface}
50                         RETVAL=$?
51                 else
52                         msg_not_running "ifplugd ($iface)"
53                 fi
54         done
55         rm -f /var/run/ifplugd.pid /var/lock/subsys/ifplugd.* >/dev/null 2>&1
56 }
57
58 suspend() {
59         for iface in $INTERFACES; do
60                 if [ -f /var/lock/subsys/ifplugd.${iface} ]; then
61                         msg_stopping "Network Interface Plugging Daemon (suspending $iface)"
62                         daemon /sbin/ifplugd -S -i ${iface}
63                         RETVAL=$?
64                 else
65                         msg_not_running "ifplugd ($iface)"
66                 fi
67         done
68 }
69
70 resume() {
71         for iface in $INTERFACES; do
72                 if [ -f /var/lock/subsys/ifplugd.${iface} ]; then
73                         msg_starting "Network Interface Plugging Daemon (resuming $iface)"
74                         daemon /sbin/ifplugd -R -i ${iface}
75                         RETVAL=$?
76                 else
77                         msg_not_running "ifplugd ($iface)"
78                 fi
79         done
80 }
81
82 reload() {
83         if [ -f /var/lock/subsys/ifplugd ]; then
84                 $0 stop
85                 sleep 2
86                 $0 start
87                 RETVAL=$?
88         else
89                 msg_not_running ifplugd
90                 exit 7
91         fi
92 }
93
94 [ -n "$2" ] && INTERFACES="$2"
95
96 [ -z "$INTERFACES" -o "$INTERFACES" = "auto" ] && INTERFACES=$(awk -F: '/(eth|wlan)/ { print $1 }' /proc/net/dev | xargs)
97
98 RETVAL=0
99 # See how we were called.
100 case "$1" in
101   start)
102         start
103         ;;
104   stop)
105         stop
106         ;;
107   suspend)
108         suspend
109         ;;
110   resume)
111         resume
112         ;;
113   restart)
114         stop
115         start
116         exit $?
117         ;;
118   status)
119         status /sbin/ifplugd
120         RETVAL=$?
121         for iface in $INTERFACES; do
122                 /sbin/ifplugd -c -i $iface
123                 ret=$?
124                 [ $ret -gt 0 ] && RETVAL=$ret
125         done
126         ;;
127   reload|force-reload)
128         reload
129         ;;
130   *)
131         msg_usage "$0 {start|stop|restart|reload|force-reload|status}"
132         exit 3
133 esac
134
135 exit $RETVAL
This page took 0.034136 seconds and 3 git commands to generate.