source: bootscripts/lfs/init.d/network

trunk
Last change on this file was ed6ffcb, checked in by Pierre Labastie <pierre.labastie@…>, 2 years ago

network bootscript: Don't run ifup if route already set

Otherwise, warnings are issued when changing runlevel. "ip route"
is a good test of whether network is already up. If users want to
change some config, they should use ifup/down, not the network
bootscript.

  • Property mode set to 100644
File size: 2.4 KB
Line 
1#!/bin/sh
2########################################################################
3# Begin network
4#
5# Description : Network Control Script
6#
7# Authors : Gerard Beekmans - gerard@linuxfromscratch.org
8# Nathan Coulson - nathan@linuxfromscratch.org
9# Kevin P. Fleming - kpfleming@linuxfromscratch.org
10# DJ Lucas - dj@linuxfromscratch.org
11# Update : Bruce Dubbs - bdubbs@linuxfromscratch.org
12#
13# Version : LFS 7.0
14#
15########################################################################
16
17### BEGIN INIT INFO
18# Provides: $network
19# Required-Start: $local_fs localnet swap
20# Should-Start: $syslog firewalld iptables nftables
21# Required-Stop: $local_fs localnet swap
22# Should-Stop: $syslog firewalld iptables nftables
23# Default-Start: 2 3 4 5
24# Default-Stop: 0 1 6
25# Short-Description: Starts and configures network interfaces.
26# Description: Starts and configures network interfaces.
27# X-LFS-Provided-By: LFS
28### END INIT INFO
29
30case "${1}" in
31 start)
32 # if the default route exists, network is already configured
33 if ip route | grep -q "^default"; then return 0; fi
34 # Start all network interfaces
35 for file in /etc/sysconfig/ifconfig.*
36 do
37 interface=${file##*/ifconfig.}
38
39 # Skip if $file is * (because nothing was found)
40 if [ "${interface}" = "*" ]; then continue; fi
41
42 /sbin/ifup ${interface}
43 done
44 ;;
45
46 stop)
47 # Unmount any network mounted file systems
48 umount --all --force --types nfs,cifs,nfs4
49
50 # Reverse list
51 net_files=""
52 for file in /etc/sysconfig/ifconfig.*
53 do
54 net_files="${file} ${net_files}"
55 done
56
57 # Stop all network interfaces
58 for file in ${net_files}
59 do
60 interface=${file##*/ifconfig.}
61
62 # Skip if $file is * (because nothing was found)
63 if [ "${interface}" = "*" ]; then continue; fi
64
65 # See if interface exists
66 if [ ! -e /sys/class/net/$interface ]; then continue; fi
67
68 # Is interface UP?
69 ip link show $interface 2>/dev/null | grep -q "state UP"
70 if [ $? -ne 0 ]; then continue; fi
71
72 /sbin/ifdown ${interface}
73 done
74 ;;
75
76 restart)
77 ${0} stop
78 sleep 1
79 ${0} start
80 ;;
81
82 *)
83 echo "Usage: ${0} {start|stop|restart}"
84 exit 1
85 ;;
86esac
87
88exit 0
89
90# End network
Note: See TracBrowser for help on using the repository browser.