~upstart-devel/upstart/upstart-jobs

« back to all changes in this revision

Viewing changes to utopic/etc/init.d/ifplugd

  • Committer: Dimitri John Ledkov
  • Date: 2014-11-19 12:58:41 UTC
  • Revision ID: dimitri.j.ledkov@intel.com-20141119125841-98dr37roy8dvcv3b
auto update

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/bin/sh
2
 
# $Id: ifplugd.init.in 43 2003-09-13 11:25:11Z lennart $
3
 
 
4
 
# This file is part of ifplugd.
5
 
#
6
 
# ifplugd is free software; you can redistribute it and/or modify it under
7
 
# the terms of the GNU General Public License as published by the Free
8
 
# Software Foundation; either version 2 of the License, or (at your
9
 
# option) any later version.
10
 
#
11
 
# ifplugd is distributed in the hope that it will be useful, but WITHOUT
12
 
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
 
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
 
# for more details.
15
 
#
16
 
# You should have received a copy of the GNU General Public License
17
 
# along with ifplugd; if not, write to the Free Software Foundation,
18
 
# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
19
 
 
20
 
### BEGIN INIT INFO
21
 
# Provides:          ifplugd
22
 
# Required-Start:    $network $remote_fs
23
 
# Required-Stop:     $network $remote_fs
24
 
# Default-Start:     2 3 4 5
25
 
# Default-Stop:      0 1 6
26
 
# Short-Description: Brings up/down network automatically
27
 
# Description:       Brings networks interfaces up and down automatically when
28
 
#                    the cable is removed / inserted
29
 
### END INIT INFO
30
 
 
31
 
DAEMON_NAME=ifplugd
32
 
CFG=/etc/default/$DAEMON_NAME
33
 
DESC="Network Interface Plugging Daemon"
34
 
IFPLUGD=/usr/sbin/$DAEMON_NAME
35
 
test -x $IFPLUGD || exit 0
36
 
 
37
 
if [ `id -u` != "0" ] && [ "$1" = "start" -o "$1" = "stop" ] ; then
38
 
  echo "You must be root to start, stop or restart ifplugd."
39
 
  exit 1
40
 
fi
41
 
 
42
 
[ -f $CFG ] && . $CFG
43
 
 
44
 
VERB="$1"
45
 
shift
46
 
 
47
 
[ $# -ne 0 ] && INTERFACES="$@"
48
 
 
49
 
all_interfaces () {
50
 
    for IFPATH in /sys/class/net/* ; do
51
 
        IFNAME="${IFPATH#/sys/class/net/}"
52
 
 
53
 
        [ -e "$IFPATH/device" ] || continue
54
 
 
55
 
        if [ -f "$IFPATH/type" ] ; then
56
 
            grep --quiet '^1$' "$IFPATH/type" || continue
57
 
        fi
58
 
 
59
 
        case "$IFNAME" in
60
 
            eth*|wlan*)
61
 
                echo $IFNAME
62
 
                ;;
63
 
        esac
64
 
    done
65
 
}
66
 
 
67
 
[ "x$INTERFACES" = "xauto" -o "x$INTERFACES" = "xall" ] && INTERFACES="$(all_interfaces)"
68
 
 
69
 
. /lib/lsb/init-functions
70
 
 
71
 
case "$VERB" in
72
 
    start)
73
 
        [ "$INTERFACES" ] || exit 0
74
 
        log_action_begin_msg "$DESC"
75
 
        for IF in $INTERFACES ; do
76
 
            if [ ! -e /sys/class/net/$IF ] || \
77
 
               $IFPLUGD -c -i $IF >/dev/null ; then
78
 
                log_action_cont_msg "skip $IF"
79
 
                continue
80
 
            fi
81
 
            log_action_cont_msg "start $IF"
82
 
            IF1=$(echo $IF | sed "s/-/_/")
83
 
            A=$(eval echo \$\{ARGS_${IF1}\})
84
 
            [ -z "$A" ] && A="$ARGS"
85
 
            $IFPLUGD -i $IF $A
86
 
        done
87
 
        log_action_end_msg 0
88
 
        ;;
89
 
    stop)
90
 
        [ "$INTERFACES" ] || exit 0
91
 
        log_action_begin_msg "$DESC"
92
 
        for IF in $INTERFACES ; do 
93
 
            if [ ! -e /sys/class/net/$IF ] || \
94
 
               ! $IFPLUGD -c -i $IF >/dev/null ; then
95
 
                log_action_cont_msg "skip $IF"
96
 
                continue
97
 
            fi
98
 
            log_action_cont_msg "stop $IF"
99
 
            $IFPLUGD -k --wait-on-kill -i $IF
100
 
        done
101
 
        log_action_end_msg 0
102
 
        ;;
103
 
    status)
104
 
        [ "$INTERFACES" -o "$HOTPLUG_INTERFACES" ] || exit 0
105
 
        for IF in $INTERFACES $HOTPLUG_INTERFACES ; do
106
 
            if [ ! -e /sys/class/net/$IF ] ; then
107
 
                log_action_msg "$IF: device $IF is either not present or not functional"
108
 
                continue
109
 
            fi
110
 
            log_begin_msg "$IF: "
111
 
            $IFPLUGD -c -i $IF
112
 
        done
113
 
        ;;
114
 
    suspend)
115
 
        [ "$INTERFACES" -o "$HOTPLUG_INTERFACES" ] || exit 0
116
 
        log_action_begin_msg "$DESC"
117
 
        for IF in $INTERFACES $HOTPLUG_INTERFACES ; do
118
 
            if [ ! -e /sys/class/net/$IF ] || \
119
 
               ! $IFPLUGD -c -i $IF >/dev/null ; then
120
 
                log_action_cont_msg "skip $IF"
121
 
                continue
122
 
            fi
123
 
            log_action_cont_msg "suspend $IF"
124
 
            $IFPLUGD -S -i $IF
125
 
        done
126
 
        log_action_end_msg 0
127
 
        ;;
128
 
    resume)
129
 
        [ "$INTERFACES" -o "$HOTPLUG_INTERFACES" ] || exit 0
130
 
        log_action_begin_msg "$DESC"
131
 
        for IF in $INTERFACES $HOTPLUG_INTERFACES ; do
132
 
            if [ ! -e /sys/class/net/$IF ] || \
133
 
               ! $IFPLUGD -c -i $IF >/dev/null ; then
134
 
                log_action_cont_msg "skip $IF"
135
 
                continue
136
 
            fi
137
 
            log_action_cont_msg "resume $IF"
138
 
            $IFPLUGD -R -i $IF
139
 
        done
140
 
        log_action_end_msg 0
141
 
        ;;
142
 
    force-reload|restart)
143
 
        [ "$INTERFACES" ] || exit 0
144
 
        $0 stop $INTERFACES
145
 
        sleep 3
146
 
        $0 start $INTERFACES
147
 
        ;;
148
 
    *)
149
 
        echo "Usage: $0 {start|stop|restart|force-reload|status|suspend|resume}"
150
 
        exit 1
151
 
esac
152
 
 
153
 
exit 0