New ifup/ifdown and modified network script. Changed comments on cleanfs scritp as well.

git-svn-id: http://svn.linuxfromscratch.org/LFS/trunk/BOOK@9543 4aa44e1e-78dd-0310-a6d2-fbcd4c07a689
This commit is contained in:
DJ Lucas 2011-05-18 17:18:30 +00:00
parent 499ce32dd4
commit c2db0877b0
5 changed files with 363 additions and 204 deletions

View File

@ -1,3 +1,7 @@
2011-05-18 DJ Lucas <dj@linuxfromscratch.org>
* /sbin/ifup, /sbin/ifdown: Complete rewrite for use as standalone tools
* etc/init.d/network: Rewrote script to account for new ifup and ifdown
2011-05-14 DJ Lucas <dj@linuxfromscratch.org> 2011-05-14 DJ Lucas <dj@linuxfromscratch.org>
* etc/default/rc.site: Added FAILURE_ACTION variable for use in remote * etc/default/rc.site: Added FAILURE_ACTION variable for use in remote
systems where user input is not appropriate in the event of a failure. systems where user input is not appropriate in the event of a failure.

View File

@ -9,10 +9,10 @@
# Should-Stop: # Should-Stop:
# Default-Start: S # Default-Start: S
# Default-Stop: # Default-Stop:
# Short-Description: Cleans temporary directories early in the boot process. # Short-Description: Cleans and prepares the temporary directory.
# Description: Cleans temporary directories /var/run, /var/lock, and # Description: Cleans the temporary directory /tmp and creates the
# /tmp. cleanfs also creates /var/run/utmp and any files # /var/run/utmp file and any other files defined in
# defined in /etc/default/createfiles. # /etc/default/createfiles.
# X-LFS-Provided-By: LFS # X-LFS-Provided-By: LFS
### END INIT INFO ### END INIT INFO

View File

@ -17,54 +17,68 @@
. /lib/lsb/init-functions . /lib/lsb/init-functions
case "${1}" in case "${1}" in
start) start)
# Start all network interfaces # Start all network interfaces
for file in ${NETWORK_DEVICES}/ifconfig.* for dir in ${NETWORK_DEVICES}/ifconfig.*
do do
interface=${file##*/ifconfig.} interface=${dir##*/ifconfig.}
# skip if $dir is * (because nothing was found)
if [ "${interface}" = "*" ]; then
continue
fi
# Process individual configuration files
for file in "${dir}"/* ; do
ONBOOT=`grep "ONBOOT" "${file}" | sed 's@^ONBOOT=@@'`
case "${ONBOOT}" in
Y* | y* | 0)
/sbin/ifup -c "${file}" "${interface}"
;;
esac
done
done
;;
# skip if $file is * (because nothing was found) stop)
if [ "${interface}" = "*" ] # Reverse list
then DIRS=""
continue for dir in /run/network/ifconfig.*
fi do
IN_BOOT=1 /sbin/ifup ${interface} DIRS="${dir} ${DIRS}"
done done
;;
stop) # Stop all network interfaces
# Reverse list for dir in ${DIRS}; do
FILES="" interface=${dir##*/ifconfig.}
for file in /run/network/ifconfig.* # skip if $dir is * (because nothing was found)
do if [ "${interface}" = "*" ]; then
FILES="${file} ${FILES}" continue
done fi
# Process individual configuration files
for file in "${dir}"/* ; do
# No checking necessary if it is in /run/network
/sbin/ifdown -c "${file}" "${interface}"
done
link_status=`/sbin/ip link show "${interface}" | \
grep -o "state DOWN"`
if [ "${link_status}" != "state DOWN" ]; then
message="Shutting down the ${interface} interface..."
/sbin/ip addr flush "${interface}" &&
/sbin/ip link set "${interface}" down
evaluate_retval standard
fi
done
;;
# Stop all network interfaces restart)
for file in ${FILES} ${0} stop
do sleep 1
interface=${file##*/ifconfig.} ${0} start
;;
# skip if $file is * (because nothing was found) *)
if [ "${interface}" = "*" ] echo "Usage: ${0} {start|stop|restart}"
then exit 1
continue ;;
fi
IN_BOOT=1 /sbin/ifdown ${interface}
done
;;
restart)
${0} stop
sleep 1
${0} start
;;
*)
echo "Usage: ${0} {start|stop|restart}"
exit 1
;;
esac esac
# End /etc/init.d/network # End /etc/init.d/network

View File

@ -1,98 +1,176 @@
#!/bin/sh #!/bin/sh
######################################################################## ########################################################################
# Begin $NETWORK_DEVICES/ifdown # Begin /sbin/ifdown
# #
# Description : Interface Down # Description : Interface Down
# #
# Authors : Nathan Coulson - nathan@linuxfromscratch.org # Authors : DJ Lucas - dj@linuxfromscratch.org
# Kevin P. Fleming - kpfleming@linuxfromscratch.org
# #
# Version : 00.01 # Version : 00.02
#
# Notes : the IFCONFIG variable is passed to the scripts found
# in the services directory, to indicate what file the
# service should source to get environmental variables.
# #
######################################################################## ########################################################################
. /lib/lsb/init-functions . /lib/lsb/init-functions
# Collect a list of configuration files for our interface function get_args()
if [ -n "${2}" ]; then {
for file in ${@#$1}; do # All parameters except $1 if test -z "${1}" ; then
FILES="${FILES} /run/network/ifconfig.${1}/${file}" showhelp
done exit 1
elif [ -d "/run/network/ifconfig.${1}" ]; then fi
FILES=`echo /run/network/ifconfig.${1}/*`
while test -n "${1}" ; do
case "${1}" in
-c | --configfile)
check_arg $1 $2
CONFIGFILE="${2}"
shift 2
;;
-f | --force)
FORCE="1"
shift 1
;;
eth* | iw* | wlan*)
INTERFACE="${1}"
shift 1
;;
-h | --help)
showhelp
exit 0
;;
*)
showhelp
echo "ERROR: '${1}' unknown argument"
echo ""
exit 2
;;
esac
done
}
function check_arg()
{
echo "${2}" | grep -v "^-" > /dev/null
if [ -z "${?}" -o ! -n "${2}" ]; then
echo "Error: ${1} requires a valid argument."
exit 2
fi
}
function showhelp()
{
echo ""
echo "`/usr/bin/basename ${0}` brings down a valid network interface."
echo ""
echo "Options:"
echo " -c --configfile The path to an interface configuration file"
echo " If no configuration file is given, all files"
echo " listed in /etc/network/ifconfig.<int> will"
echo " be processed, regarless of the value of ONBOOT"
echo " -f --force Flush all IPs and force the interface down."
echo " -h --help Show this help message and exit."
echo ""
echo "Examples:"
echo " `/usr/bin/basename ${0}` eth0 -c /run/network/ifconfig.eth0/ipv4"
echo " `/usr/bin/basename ${0}` eth0 --force -c /run/network/ifconfig.eth0/ipv4"
echo " `/usr/bin/basename ${0}` eth0 --force"
echo " `/usr/bin/basename ${0}` eth0"
echo ""
echo ""
}
# Intialize empty variables so that the shell does not polute the script
CONFIGFILE=""
CONFIGDIR=""
INTERFACE=""
FORCE=""
failed=0
# Process command line arguments
get_args ${@}
# Handle common errors - No need to account for bootscripts, this should not
# happen during boot or shutdown.
if [ "${CONFIGFILE}x" != "x" -a ! -f "${CONFIGFILE}" ]; then
echo "ERROR: ${CONFIGFILE} is not a valid network configuration file."
echo ""
exit 2
fi
if [ "${INTERFACE}x" == "x" ]; then
echo "ERROR: No interface was given"
echo ""
exit 2
else else
FILES="/run/network/ifconfig.${1}" if ! grep "${INTERFACE}" /proc/net/dev 2>&1 > /dev/null; then
echo "ERROR: ${INTERFACE} is not a valid network interface."
echo ""
exit 2
fi
fi fi
# Reverse the order configuration files are processed in # If a configuration file is present, use it
for file in ${FILES}; do if [ "${CONFIGFILE}x" != "x" ]; then
FILES2="${file} ${FILES2}" . "${CONFIGFILE}"
done if [ -x "/lib/network-services/${SERVICE}" ]; then
FILES=${FILES2} # do the work
if IFCONFIG=${CONFIGFILE} \
# Process each configuration file /lib/network-services/${SERVICE} ${INTERFACE} down; then
for file in ${FILES}; do rm "${CONFIGFILE}"
# skip backup files fi
if [ "${file}" != "${file%""~""}" ]; then else
continue echo "ERROR: Service '${SERVICE}' is not a valid service."
echo ""
exit 2
fi fi
# No interface configuration file was given
if [ ! -f "${file}" ]; then else
message="${file} is not a network configuration file or directory." # Process all running interface configuration files
log_warning_msg CONFIGDIR="/run/network/ifconfig.${INTERFACE}"
fi if [ -d "${CONFIGDIR}" ]; then
( FILES=`ls "${CONFIGDIR}"`
if [ ! -d "${file}" ]; then for CONFIGFILE in ${FILES}
. ${file} do
fi (
. "${CONFIGDIR}/${CONFIGFILE}"
# Will not process this service if started by boot, and ONBOOT # No error checking necessary if they are in /run
# is not set to yes if IFCONFIG="${CONFIGDIR}/${CONFIGFILE}" \
if [ "${IN_BOOT}" = "1" -a "${ONBOOT}" != "yes" ]; then /lib/network-services/${SERVICE} ${INTERFACE} down; then
continue rm "${CONFIGDIR}/${CONFIGFILE}"
fi
# Will not process this service if started by hotplug, and
# ONHOTPLUG is not set to yes
if [ "${IN_HOTPLUG}" = "1" -a "${ONHOTPLUG}" != "yes" ]; then
continue
fi
# This will run the service script, if SERVICE is set
if [ -n "${SERVICE}" -a -x "/lib/network-services/${SERVICE}" ]; then
if ip link show ${1} > /dev/null 2>&1
then
IFCONFIG=${file} /lib/network-services/${SERVICE} ${1} down &&
if [ -f "${file}" ]; then
rm ${file}
fi fi
else )
message="Interface ${1} doesn't exist." done
log_warning_msg # all running config files processes, set the link down
fi message="Setting interface ${INTERFACE} down..."
else /sbin/ip link set "${INTERFACE}" down
echo -e "${FAILURE}Unable to process ${file}. Either" evaluate_retval standard
echo -e "${FAILURE}the SERVICE variable was not set," else
echo -e "${FAILURE}or the specified service cannot be executed." if [ "${FORCE}" != "1" ]; then
message="" echo "ERROR: No configuration files found for ${INTERFACE}."
log_failure_msg echo ""
fi exit 2
)
done
if [ -z "${2}" ]; then
link_status=`ip link show $1`
if [ -n "${link_status}" ]; then
if echo "${link_status}" | grep -q UP; then
message="Bringing down the ${1} interface..."
ip link set ${1} down
evaluate_retval standard
fi fi
fi fi
fi fi
if [ "${FORCE}" == "1" ]; then
/sbin/ip addr flush dev "${INTERFACE}" 2>&1 > /dev/null || failed=1
if [ "${failed}" == "1" ]; then
log_failure_msg "Flushing IP addresses from interface ${INTERFACE}..."
echo ""
exit 1
else
log_success_msg "Flushing IP addresses from interface ${INTERFACE}..."
fi
/sbin/ip link set dev "${INTERFACE}" down 2>&1 > /dev/null || failed=1
if [ "${failed}" == "1" ]; then
log_failure_msg "Setting link down for interface ${INTERFACE}..."
echo ""
exit 1
else
log_success_msg "Setting link down for interface ${INTERFACE}..."
fi
fi
exit "${failed}"
# End $NETWORK_DEVICES/ifdown

View File

@ -1,97 +1,160 @@
#!/bin/sh #!/bin/sh
######################################################################## ########################################################################
# Begin $NETWORK_DEVICES/ifup # Begin /sbin/ifdown
# #
# Description : Interface Up # Description : Interface Up
# #
# Authors : Nathan Coulson - nathan@linuxfromscratch.org # Authors : DJ Lucas - dj@linuxfromscratch.org
# Kevin P. Fleming - kpfleming@linuxfromscratch.org
# #
# Version : 00.00 # Version : 00.02
#
# Notes : the IFCONFIG variable is passed to the scripts found
# in the services directory, to indicate what file the
# service should source to get environmental variables.
# #
######################################################################## ########################################################################
. /lib/lsb/init-functions . /lib/lsb/init-functions
# Collect a list of configuration files for our interface function get_args()
if [ -n "${2}" ]; then {
for file in ${@#$1} # All parameters except $1 if test -z "${1}" ; then
do showhelp
FILES="${FILES} ${NETWORK_DEVICES}/ifconfig.${1}/${file}" exit 1
done fi
elif [ -d "${NETWORK_DEVICES}/ifconfig.${1}" ]; then
FILES=`echo ${NETWORK_DEVICES}/ifconfig.${1}/*` while test -n "${1}" ; do
else case "${1}" in
FILES="${NETWORK_DEVICES}/ifconfig.${1}" -c | --configfile)
check_arg $1 $2
CONFIGFILE="${2}"
shift 2
;;
eth* | iw* | wlan*)
INTERFACE="${1}"
shift 1
;;
-h | --help)
showhelp
exit 0
;;
*)
showhelp
echo "ERROR: '${1}' unknown argument"
echo ""
exit 2
;;
esac
done
}
function check_arg()
{
echo "${2}" | grep -v "^-" > /dev/null
if [ -z "${?}" -o ! -n "${2}" ]; then
echo "Error: ${1} requires a valid argument."
exit 2
fi
}
function showhelp()
{
echo "`/usr/bin/basename ${0}` brings up a valid network interface."
echo ""
echo "Options:"
echo " -c --configfile The path to an interface configuration file"
echo " If no configuration file is given, all files"
echo " listed in ${NETWORK_DEVICES}/ifconfig.<int> will"
echo " be processed, regarless of the value of ONBOOT"
echo " -h --help Show this help message and exit."
echo ""
echo "Examples:"
echo " `/usr/bin/basename ${0}` eth0 -c ${NETWORK_DEVICES}/ifconfig.eth0/ipv4"
echo " `/usr/bin/basename ${0}` eth0"
echo ""
echo ""
}
# Intialize empty variables so that the shell does not polute the script
CONFIGFILE=""
CONFIGDIR=""
INTERFACE=""
# Process command line arguments
get_args ${@}
# Handle common errors - No need to account for bootscripts, this should not
# happen during boot or shutdown.
if [ "${CONFIGFILE}x" != "x" -a ! -f "${CONFIGFILE}" ]; then
echo "ERROR: ${CONFIGFILE} is not a valid network configuration file."
echo ""
exit 2
fi fi
message="Bringing up the ${1} interface..." if [ "${INTERFACE}x" == "x" ]; then
echo "ERROR: No interface was given"
# Process each configruation file echo ""
for file in ${FILES}; do exit 2
# skip backup files else
if [ "${file}" != "${file%""~""}" ]; then if ! grep "${INTERFACE}" /proc/net/dev 2>&1 > /dev/null; then
continue echo "ERROR: ${INTERFACE} is not a valid network interface."
echo ""
exit 2
fi fi
fi
if [ ! -f "${file}" ]; then # If a configuration file is present, use it
log_warning_msg if [ "${CONFIGFILE}x" != "x" ]; then
message="${file} is not a network configuration file or directory." . "${CONFIGFILE}"
log_warning_msg if [ -x "/lib/network-services/${SERVICE}" ]; then
# do the work
# Check to make sure the interface is up
link_status=`/sbin/ip link show "${INTERFACE}" | \
grep -o "state UP"`
if [ "${link_status}" != "state UP" ]; then
message="Bringing up the ${INTERFACE} interface..."
/sbin/ip link set ${INTERFACE} up
evaluate_retval standard
fi
if IFCONFIG=${CONFIGFILE} \
/lib/network-services/${SERVICE} ${INTERFACE} up; then
mkdir -p "/run/network/ifconfig.${INTERFACE}"
cp "${CONFIGFILE}" "/run/network/ifconfig.${INTERFACE}/"
fi
else
echo "ERROR: Service '${SERVICE}' is not a valid service."
echo ""
exit 2
fi fi
# No interface configuration file was given
( else
if [ ! -d "${file}" ]; then # Process all available interface configuration files
. ${file} CONFIGDIR="/etc/network/ifconfig.${INTERFACE}"
fi if [ -d "${CONFIGDIR}" ]; then
FILES=`ls "${CONFIGDIR}"`
# Will not process this service if started by boot, and ONBOOT for CONFIGFILE in ${FILES}
# is not set to yes do
if [ "${IN_BOOT}" = "1" -a "${ONBOOT}" != "yes" ]; then (
continue . "${CONFIGDIR}/${CONFIGFILE}"
fi if [ -x "/lib/network-services/${SERVICE}" ]; then
# Will not process this service if started by hotplug, and # Check to make sure the interface is up
# ONHOTPLUG is not set to yes link_status=`/sbin/ip link show "${INTERFACE}" | \
if [ "${IN_HOTPLUG}" = "1" -a "${ONHOTPLUG}" != "yes" -a "${HOSTNAME}" != "(none)" ]; then grep -o "state UP"`
continue if [ "${link_status}" != "state UP" ]; then
fi message="Bringing up the ${INTERFACE} interface..."
/sbin/ip link set ${INTERFACE} up
if [ -n "${SERVICE}" -a -x "/lib/network-services/${SERVICE}" ]; then evaluate_retval standard
if [ -z "${CHECK_LINK}" -o "${CHECK_LINK}" = "y" -o "${CHECK_LINK}" = "yes" -o "${CHECK_LINK}" = "1" ]; then fi
if ip link show ${1} > /dev/null 2>&1; then if IFCONFIG="${CONFIGDIR}/${CONFIGFILE}" \
link_status=`ip link show ${1}` /lib/network-services/${SERVICE} ${INTERFACE} up; then
if [ -n "${link_status}" ]; then mkdir -p "/run/network/ifconfig.${INTERFACE}"
if ! echo "${link_status}" | grep -q UP; then cp "${CONFIGDIR}/${CONFIGFILE}" \
ip link set ${1} up "/run/network/ifconfig.${INTERFACE}/"
evaluate_retval standard
fi
fi fi
else else
message="${message}Interface ${1} doesn't exist." echo "ERROR: Service '${SERVICE}' is not a valid service."
log_warning_msg echo ""
exit 2
fi fi
fi
IFCONFIG=${file} /lib/network-services/${SERVICE} ${1} up
if [ "${?}" -eq "0" ]; then
if [ ! -d "${file}" -a "${file}" != "${NETWORK_DEVICES}/ifconfig.${1}" ]; then
mkdir -p "/run/network/ifconfig.${1}"
cp "${file}" "/run/network/ifconfig.${1}"
elif [ ! -d "${file}" ]; then
cp "${file}" "/run/network/"
fi
fi
else
echo -e "${FAILURE}Unable to process ${file}. Either"
echo -e "${FAILURE}the SERVICE variable was not set,"
echo -e "${FAILURE}or the specified service cannot be executed."
message=""
log_failure_msg
fi
)
done
# End $NETWORK_DEVICES/ifup )
done
fi
fi