]> git.proxmox.com Git - mirror_ifupdown2.git/blob - sbin/start-networking
Update README.rst (#11)
[mirror_ifupdown2.git] / sbin / start-networking
1 #!/bin/bash
2
3 # This replaces the old init.d script, and is run from the networking.service
4 # Only has start, stop, reload, because that's all systemd has.
5 # restart is implemented in systemd by stop then start.
6
7 PATH="/sbin:/bin"
8 RUN_DIR="/run/network"
9 IFSTATE_LOCKFILE="${RUN_DIR}/ifstatelock"
10
11 STATE_DIR="/var/tmp/network"
12 IFSTATE_FILE="${STATE_DIR}/ifstatenew"
13
14 NAME=networking
15
16 [ -x /sbin/ifup ] || exit 0
17 [ -x /sbin/ifdown ] || exit 0
18
19 CONFIGURE_INTERFACES=yes
20
21 EXTRA_ARGS=
22
23 [ -f /etc/default/networking ] && . /etc/default/networking
24
25 [ "$VERBOSE" = yes ] && EXTRA_ARGS=-v
26 [ "$DEBUG" = yes ] && EXTRA_ARGS="$EXTRA_ARGS -d"
27 [ "$SYSLOG" = yes ] && EXTRA_ARGS="$EXTRA_ARGS --syslog"
28
29 perf_options() {
30 # At bootup lets set perfmode
31 [ -f ${IFSTATE_LOCKFILE} ] && echo -n "" && return
32
33 echo -n "--perfmode"
34 }
35
36 process_exclusions() {
37 set -- $EXCLUDE_INTERFACES
38 exclusions=""
39 for d
40 do
41 exclusions="-X $d $exclusions"
42 done
43 echo $exclusions
44 }
45
46 check_network_file_systems() {
47 [ -e /proc/mounts ] || return 0
48
49 if [ -e /etc/iscsi/iscsi.initramfs ]; then
50 echo ${NAME}':' "not deconfiguring network interfaces: iSCSI root is mounted."
51 exit 0
52 fi
53
54 while read DEV MTPT FSTYPE REST; do
55 case $DEV in
56 /dev/nbd*|/dev/nd[a-z]*|/dev/etherd/e*)
57 echo ${NAME}':' "not deconfiguring network interfaces: network devices still mounted."
58 exit 0
59 ;;
60 esac
61 case $FSTYPE in
62 nfs|nfs4|smbfs|ncp|ncpfs|cifs|coda|ocfs2|gfs|pvfs|pvfs2|fuse.httpfs|fuse.curlftpfs)
63 echo ${NAME}':' "not deconfiguring network interfaces: network file systems still mounted."
64 exit 0
65 ;;
66 esac
67 done < /proc/mounts
68 }
69
70 check_network_swap() {
71 [ -e /proc/swaps ] || return 0
72
73 while read DEV MTPT FSTYPE REST; do
74 case $DEV in
75 /dev/nbd*|/dev/nd[a-z]*|/dev/etherd/e*)
76 echo ${NAME}':' "not deconfiguring network interfaces: network swap still mounted."
77 exit 0
78 ;;
79 esac
80 done < /proc/swaps
81 }
82
83 ifup_hotplug () {
84 if [ -d /sys/class/net ]
85 then
86 ifaces=$(for iface in $(ifquery --list --allow=hotplug 2>/dev/null)
87 do
88 link=${iface##:*}
89 link=${link##.*}
90 if [ -e "/sys/class/net/$link" ]
91 then
92 echo "$iface"
93 fi
94 done)
95 if [ -n "$ifaces" ]
96 then
97 ifup $ifaces "$@" || true
98 fi
99 fi
100 }
101
102 ifup_mgmt () {
103 ifaces=$(ifquery --list --allow=mgmt 2>/dev/null)
104 if [ -n "$ifaces" ]; then
105 echo "bringing up mgmt class interfaces"
106 ifup --allow=mgmt
107 fi
108 }
109
110 ifupdown_init() {
111 # remove state file at boot
112 [ ! -e ${IFSTATE_LOCKFILE} ] && rm -f ${IFSTATE_FILE}
113
114 [ ! -e /run/network ] && mkdir -p /run/network &>/dev/null
115 [ ! -e /etc/network/run ] && \
116 ln -sf /run/network /etc/network/run &>/dev/null
117 }
118
119 case "$1" in
120 start)
121 ifupdown_init
122 if [ "$CONFIGURE_INTERFACES" = no ]
123 then
124 echo ${NAME}':' "Not configuring network interfaces, see /etc/default/networking"
125 exit 0
126 fi
127 set -f
128 exclusions=$(process_exclusions)
129 perfoptions=$(perf_options)
130 echo ${NAME}':' "Configuring network interfaces"
131 ifup_mgmt
132 ifup -a $EXTRA_ARGS $exclusions $perfoptions
133 ifup_hotplug $HOTPLUG_ARGS $EXTRA_ARGS $exclusions
134 ;;
135 stop)
136 if [ "$SKIP_DOWN_AT_SYSRESET" = "yes" ]; then
137 SYSRESET=0
138 systemctl list-jobs | egrep -q '(shutdown|reboot|halt|poweroff)\.target'
139 [ $? -eq 0 ] && SYSRESET=1
140 if [ $SYSRESET -eq 1 ]; then
141 echo ${NAME}':' "Skipping deconfiguring network interfaces"
142 exit 0
143 fi
144 fi
145 ifupdown_init
146 check_network_file_systems
147 check_network_swap
148 exclusions=$(process_exclusions)
149
150 echo ${NAME}':' "Deconfiguring network interfaces"
151 ifdown -a $EXTRA_ARGS $exclusions
152 ;;
153
154 reload)
155
156 ifupdown_init
157 exclusions=$(process_exclusions)
158
159 echo ${NAME}':' "Reloading network interfaces configuration"
160 ifreload -a $EXTRA_ARGS $exclusions
161 ;;
162
163 *)
164 echo ${NAME}':' "Usage: $0 {start|stop|reload}"
165 exit 1
166 ;;
167 esac
168
169 exit 0