]> git.proxmox.com Git - mirror_ifupdown2.git/blame - ifupdown2/sbin/start-networking
Update xfrm.py
[mirror_ifupdown2.git] / ifupdown2 / sbin / start-networking
CommitLineData
07678ee4
DO
1#!/bin/bash
2
9a7878c6 3# This replaces the old init.d script, and is run from the networking.service
07678ee4
DO
4# Only has start, stop, reload, because that's all systemd has.
5# restart is implemented in systemd by stop then start.
6
07678ee4 7RUN_DIR="/run/network"
09b1b7fb
RP
8IFSTATE_LOCKFILE="${RUN_DIR}/ifstatelock"
9
10STATE_DIR="/var/tmp/network"
11IFSTATE_FILE="${STATE_DIR}/ifstatenew"
07678ee4
DO
12
13NAME=networking
14
15[ -x /sbin/ifup ] || exit 0
16[ -x /sbin/ifdown ] || exit 0
17
18CONFIGURE_INTERFACES=yes
19
20EXTRA_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
28perf_options() {
29 # At bootup lets set perfmode
09b1b7fb 30 [ -f ${IFSTATE_LOCKFILE} ] && echo -n "" && return
07678ee4
DO
31
32 echo -n "--perfmode"
33}
34
35process_exclusions() {
36 set -- $EXCLUDE_INTERFACES
37 exclusions=""
38 for d
39 do
40 exclusions="-X $d $exclusions"
41 done
42 echo $exclusions
43}
44
45check_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
69check_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
82ifup_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##.*}
d486dd0d 89 if [ -e "/sys/class/net/$link" ]
07678ee4 90 then
6a5a7c6b 91 echo "$iface"
07678ee4
DO
92 fi
93 done)
94 if [ -n "$ifaces" ]
95 then
96 ifup $ifaces "$@" || true
97 fi
98 fi
99}
100
6642399f
RP
101ifup_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
07678ee4 109ifupdown_init() {
09b1b7fb
RP
110 # remove state file at boot
111 [ ! -e ${IFSTATE_LOCKFILE} ] && rm -f ${IFSTATE_FILE}
112
07678ee4
DO
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
118case "$1" in
119start)
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"
6642399f 130 ifup_mgmt
07678ee4 131 ifup -a $EXTRA_ARGS $exclusions $perfoptions
d02acd02 132 ifup_hotplug $HOTPLUG_ARGS $EXTRA_ARGS $exclusions
07678ee4 133 ;;
07678ee4 134stop)
d74c20e9
RP
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
07678ee4
DO
144 ifupdown_init
145 check_network_file_systems
146 check_network_swap
147 exclusions=$(process_exclusions)
148
149 echo ${NAME}':' "Deconfiguring network interfaces"
d521f1f0 150 ifdown -a $EXTRA_ARGS $exclusions
07678ee4
DO
151 ;;
152
153reload)
154
155 ifupdown_init
d521f1f0 156 exclusions=$(process_exclusions)
07678ee4 157
d521f1f0
RP
158 echo ${NAME}':' "Reloading network interfaces configuration"
159 ifreload -a $EXTRA_ARGS $exclusions
07678ee4
DO
160 ;;
161
162*)
163 echo ${NAME}':' "Usage: $0 {start|stop|reload}"
164 exit 1
165 ;;
166esac
167
168exit 0