]> git.proxmox.com Git - mirror_ifupdown2.git/blame - sbin/start-networking
Merge pull request #80 from BarbarossaTM/tunnel-fixes-master
[mirror_ifupdown2.git] / 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
7PATH="/sbin:/bin"
8RUN_DIR="/run/network"
09b1b7fb
RP
9IFSTATE_LOCKFILE="${RUN_DIR}/ifstatelock"
10
11STATE_DIR="/var/tmp/network"
12IFSTATE_FILE="${STATE_DIR}/ifstatenew"
07678ee4
DO
13
14NAME=networking
15
16[ -x /sbin/ifup ] || exit 0
17[ -x /sbin/ifdown ] || exit 0
18
19CONFIGURE_INTERFACES=yes
20
21EXTRA_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
29perf_options() {
30 # At bootup lets set perfmode
09b1b7fb 31 [ -f ${IFSTATE_LOCKFILE} ] && echo -n "" && return
07678ee4
DO
32
33 echo -n "--perfmode"
34}
35
36process_exclusions() {
37 set -- $EXCLUDE_INTERFACES
38 exclusions=""
39 for d
40 do
41 exclusions="-X $d $exclusions"
42 done
43 echo $exclusions
44}
45
46check_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
70check_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
83ifup_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##.*}
bfec7d13
JF
90
91 ip link set "$iface" up || true
92 if [ "$(cat /sys/class/net/$link/operstate)" = up ]
07678ee4 93 then
6a5a7c6b 94 echo "$iface"
07678ee4
DO
95 fi
96 done)
97 if [ -n "$ifaces" ]
98 then
99 ifup $ifaces "$@" || true
100 fi
101 fi
102}
103
6642399f
RP
104ifup_mgmt () {
105 ifaces=$(ifquery --list --allow=mgmt 2>/dev/null)
106 if [ -n "$ifaces" ]; then
107 echo "bringing up mgmt class interfaces"
108 ifup --allow=mgmt
109 fi
110}
111
07678ee4 112ifupdown_init() {
09b1b7fb
RP
113 # remove state file at boot
114 [ ! -e ${IFSTATE_LOCKFILE} ] && rm -f ${IFSTATE_FILE}
115
07678ee4
DO
116 [ ! -e /run/network ] && mkdir -p /run/network &>/dev/null
117 [ ! -e /etc/network/run ] && \
118 ln -sf /run/network /etc/network/run &>/dev/null
119}
120
121case "$1" in
122start)
123 ifupdown_init
124 if [ "$CONFIGURE_INTERFACES" = no ]
125 then
126 echo ${NAME}':' "Not configuring network interfaces, see /etc/default/networking"
127 exit 0
128 fi
129 set -f
130 exclusions=$(process_exclusions)
131 perfoptions=$(perf_options)
132 echo ${NAME}':' "Configuring network interfaces"
6642399f 133 ifup_mgmt
07678ee4 134 ifup -a $EXTRA_ARGS $exclusions $perfoptions
d02acd02 135 ifup_hotplug $HOTPLUG_ARGS $EXTRA_ARGS $exclusions
07678ee4 136 ;;
07678ee4 137stop)
d74c20e9
RP
138 if [ "$SKIP_DOWN_AT_SYSRESET" = "yes" ]; then
139 SYSRESET=0
140 systemctl list-jobs | egrep -q '(shutdown|reboot|halt|poweroff)\.target'
141 [ $? -eq 0 ] && SYSRESET=1
142 if [ $SYSRESET -eq 1 ]; then
143 echo ${NAME}':' "Skipping deconfiguring network interfaces"
144 exit 0
145 fi
146 fi
07678ee4
DO
147 ifupdown_init
148 check_network_file_systems
149 check_network_swap
150 exclusions=$(process_exclusions)
151
152 echo ${NAME}':' "Deconfiguring network interfaces"
d521f1f0 153 ifdown -a $EXTRA_ARGS $exclusions
07678ee4
DO
154 ;;
155
156reload)
157
158 ifupdown_init
d521f1f0 159 exclusions=$(process_exclusions)
07678ee4 160
d521f1f0
RP
161 echo ${NAME}':' "Reloading network interfaces configuration"
162 ifreload -a $EXTRA_ARGS $exclusions
07678ee4
DO
163 ;;
164
165*)
166 echo ${NAME}':' "Usage: $0 {start|stop|reload}"
167 exit 1
168 ;;
169esac
170
171exit 0