]> git.proxmox.com Git - mirror_ifupdown2.git/blame - init.d/networking
python-ifupdown initial checkin
[mirror_ifupdown2.git] / init.d / networking
CommitLineData
a6f80f0e 1#!/bin/sh -e
2### BEGIN INIT INFO
3# Provides: networking ifupdown
4# Required-Start: mountkernfs $local_fs urandom
5# Required-Stop: $local_fs
6# Default-Start: S
7# Default-Stop: 0 6
8# Short-Description: Raise network interfaces.
9# Description: Prepare /run/network directory, ifstate file and raise network interfaces, or take them down.
10### END INIT INFO
11
12PATH="/sbin:/bin"
13RUN_DIR="/run/network"
14IFSTATE="$RUN_DIR/ifstate"
15
16[ -x /sbin/ifup ] || exit 0
17[ -x /sbin/ifdown ] || exit 0
18
19. /lib/lsb/init-functions
20
21CONFIGURE_INTERFACES=yes
22EXCLUDE_INTERFACES=
23VERBOSE=no
24
25[ -f /etc/default/networking ] && . /etc/default/networking
26
27[ "$VERBOSE" = yes ] && verbose=-v
28
29process_exclusions() {
30 set -- $EXCLUDE_INTERFACES
31 exclusions=""
32 for d
33 do
34 exclusions="-X $d $exclusions"
35 done
36 echo $exclusions
37}
38
39process_options() {
40 [ -e /etc/network/options ] || return 0
41 log_warning_msg "/etc/network/options still exists and it will be IGNORED! Please use /etc/sysctl.conf instead."
42}
43
44check_ifstate() {
45 if [ ! -d "$RUN_DIR" ] ; then
46 if ! mkdir -p "$RUN_DIR" ; then
47 log_failure_msg "can't create $RUN_DIR"
48 exit 1
49 fi
50 fi
51 if [ ! -r "$IFSTATE" ] ; then
52 if ! :> "$IFSTATE" ; then
53 log_failure_msg "can't initialise $IFSTATE"
54 exit 1
55 fi
56 fi
57}
58
59check_network_file_systems() {
60 [ -e /proc/mounts ] || return 0
61
62 if [ -e /etc/iscsi/iscsi.initramfs ]; then
63 log_warning_msg "not deconfiguring network interfaces: iSCSI root is mounted."
64 exit 0
65 fi
66
67 while read DEV MTPT FSTYPE REST; do
68 case $DEV in
69 /dev/nbd*|/dev/nd[a-z]*|/dev/etherd/e*)
70 log_warning_msg "not deconfiguring network interfaces: network devices still mounted."
71 exit 0
72 ;;
73 esac
74 case $FSTYPE in
75 nfs|nfs4|smbfs|ncp|ncpfs|cifs|coda|ocfs2|gfs|pvfs|pvfs2|fuse.httpfs|fuse.curlftpfs)
76 log_warning_msg "not deconfiguring network interfaces: network file systems still mounted."
77 exit 0
78 ;;
79 esac
80 done < /proc/mounts
81}
82
83check_network_swap() {
84 [ -e /proc/swaps ] || return 0
85
86 while read DEV MTPT FSTYPE REST; do
87 case $DEV in
88 /dev/nbd*|/dev/nd[a-z]*|/dev/etherd/e*)
89 log_warning_msg "not deconfiguring network interfaces: network swap still mounted."
90 exit 0
91 ;;
92 esac
93 done < /proc/swaps
94}
95
96ifup_hotplug () {
97 if [ -d /sys/class/net ]
98 then
99 ifaces=$(for iface in $(ifquery --list --allow=hotplug)
100 do
101 link=${iface##:*}
102 link=${link##.*}
103 if [ -e "/sys/class/net/$link" ] && [ "$(cat /sys/class/net/$link/operstate)" = up ]
104 then
105 echo "$iface"
106 fi
107 done)
108 if [ -n "$ifaces" ]
109 then
110 ifup $ifaces "$@" || true
111 fi
112 fi
113}
114
115case "$1" in
116start)
117 if init_is_upstart; then
118 exit 1
119 fi
120 process_options
121 check_ifstate
122
123 if [ "$CONFIGURE_INTERFACES" = no ]
124 then
125 log_action_msg "Not configuring network interfaces, see /etc/default/networking"
126 exit 0
127 fi
128 set -f
129 exclusions=$(process_exclusions)
130 log_action_begin_msg "Configuring network interfaces"
131 if ifup -a $exclusions $verbose && ifup_hotplug $exclusions $verbose
132 then
133 log_action_end_msg $?
134 else
135 log_action_end_msg $?
136 fi
137 ;;
138
139stop)
140 if init_is_upstart; then
141 exit 0
142 fi
143 check_network_file_systems
144 check_network_swap
145
146 log_action_begin_msg "Deconfiguring network interfaces"
147 if ifdown -a --exclude=lo $verbose; then
148 log_action_end_msg $?
149 else
150 log_action_end_msg $?
151 fi
152 ;;
153
154reload)
155 process_options
156
157 log_action_begin_msg "Reloading network interfaces configuration"
158 state=$(cat /run/network/ifstate)
159 ifdown -a --exclude=lo $verbose || true
160 if ifup --exclude=lo $state $verbose ; then
161 log_action_end_msg $?
162 else
163 log_action_end_msg $?
164 fi
165 ;;
166
167force-reload|restart)
168 if init_is_upstart; then
169 exit 1
170 fi
171 process_options
172
173 log_warning_msg "Running $0 $1 is deprecated because it may not re-enable some interfaces"
174 log_action_begin_msg "Reconfiguring network interfaces"
175 ifdown -a --exclude=lo $verbose || true
176 set -f
177 exclusions=$(process_exclusions)
178 if ifup -a --exclude=lo $exclusions $verbose && ifup_hotplug $exclusions $verbose
179 then
180 log_action_end_msg $?
181 else
182 log_action_end_msg $?
183 fi
184 ;;
185
186*)
187 echo "Usage: /etc/init.d/networking {start|stop|reload|restart|force-reload}"
188 exit 1
189 ;;
190esac
191
192exit 0
193
194# vim: noet ts=8