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