diff options
Diffstat (limited to 'xi/init.d')
-rw-r--r-- | xi/init.d/checkfs | 149 | ||||
-rw-r--r-- | xi/init.d/cleanfs | 122 | ||||
-rw-r--r-- | xi/init.d/console | 107 | ||||
-rw-r--r-- | xi/init.d/halt | 43 | ||||
-rw-r--r-- | xi/init.d/localnet | 70 | ||||
-rw-r--r-- | xi/init.d/modules | 82 | ||||
-rw-r--r-- | xi/init.d/mountfs | 78 | ||||
-rw-r--r-- | xi/init.d/mountvirtfs | 74 | ||||
-rw-r--r-- | xi/init.d/network | 90 | ||||
-rw-r--r-- | xi/init.d/rc | 227 | ||||
-rw-r--r-- | xi/init.d/reboot | 47 | ||||
-rw-r--r-- | xi/init.d/sendsignals | 69 | ||||
-rw-r--r-- | xi/init.d/setclock | 63 | ||||
-rw-r--r-- | xi/init.d/swap | 63 | ||||
-rw-r--r-- | xi/init.d/sysctl | 54 | ||||
-rw-r--r-- | xi/init.d/sysklogd | 79 | ||||
-rw-r--r-- | xi/init.d/template | 69 | ||||
-rw-r--r-- | xi/init.d/udev | 76 | ||||
-rw-r--r-- | xi/init.d/udev_retry | 75 |
19 files changed, 1637 insertions, 0 deletions
diff --git a/xi/init.d/checkfs b/xi/init.d/checkfs new file mode 100644 index 0000000..5849219 --- /dev/null +++ b/xi/init.d/checkfs @@ -0,0 +1,149 @@ +#!/bin/sh +######################################################################## +# Begin checkfs +# +# Description : File System Check +# +# Authors : Gerard Beekmans - gerard@linuxfromscratch.org +# A. Luebke - luebke@users.sourceforge.net +# DJ Lucas - dj@linuxfromscratch.org +# Update : Bruce Dubbs - bdubbs@linuxfromscratch.org +# +# Version : LFS 7.0 +# +# Based on checkfs script from LFS-3.1 and earlier. +# +# From man fsck +# 0 - No errors +# 1 - File system errors corrected +# 2 - System should be rebooted +# 4 - File system errors left uncorrected +# 8 - Operational error +# 16 - Usage or syntax error +# 32 - Fsck canceled by user request +# 128 - Shared library error +# +######################################################################### + +### BEGIN INIT INFO +# Provides: checkfs +# Required-Start: udev swap +# Should-Start: +# Required-Stop: +# Should-Stop: +# Default-Start: S +# Default-Stop: +# Short-Description: Checks local filesystems before mounting. +# Description: Checks local filesystmes before mounting. +# X-LFS-Provided-By: LFS +### END INIT INFO + +. /lib/lsb/init-functions + +case "${1}" in + start) + if [ -f /fastboot ]; then + msg="/fastboot found, will omit " + msg="${msg} file system checks as requested.\n" + log_info_msg "${msg}" + exit 0 + fi + + log_info_msg "Mounting root file system in read-only mode... " + mount -n -o remount,ro / >/dev/null + + if [ ${?} != 0 ]; then + log_failure_msg2 + msg="\n\nCannot check root " + msg="${msg}filesystem because it could not be mounted " + msg="${msg}in read-only mode.\n\n" + msg="${msg}After you press Enter, this system will be " + msg="${msg}halted and powered off.\n\n" + log_failure_msg "${msg}" + + log_info_msg "Press Enter to continue..." + wait_for_user + /etc/rc.d/init.d/halt stop + else + log_success_msg2 + fi + + if [ -f /forcefsck ]; then + msg="/forcefsck found, forcing file" + msg="${msg} system checks as requested." + log_success_msg "$msg" + options="-f" + else + options="" + fi + + log_info_msg "Checking file systems..." + # Note: -a option used to be -p; but this fails e.g. on fsck.minix + if is_true "$VERBOSE_FSCK"; then + fsck ${options} -a -A -C -T + else + fsck ${options} -a -A -C -T >/dev/null + fi + + error_value=${?} + + if [ "${error_value}" = 0 ]; then + log_success_msg2 + fi + + if [ "${error_value}" = 1 ]; then + msg="\nWARNING:\n\nFile system errors " + msg="${msg}were found and have been corrected.\n" + msg="${msg} You may want to double-check that " + msg="${msg}everything was fixed properly." + log_warning_msg "$msg" + fi + + if [ "${error_value}" = 2 -o "${error_value}" = 3 ]; then + msg="\nWARNING:\n\nFile system errors " + msg="${msg}were found and have been been " + msg="${msg}corrected, but the nature of the " + msg="${msg}errors require this system to be rebooted.\n\n" + msg="${msg}After you press enter, " + msg="${msg}this system will be rebooted\n\n" + log_failure_msg "$msg" + + log_info_msg "Press Enter to continue..." + wait_for_user + reboot -f + fi + + if [ "${error_value}" -gt 3 -a "${error_value}" -lt 16 ]; then + msg="\nFAILURE:\n\nFile system errors " + msg="${msg}were encountered that could not be " + msg="${msg}fixed automatically.\nThis system " + msg="${msg}cannot continue to boot and will " + msg="${msg}therefore be halted until those " + msg="${msg}errors are fixed manually by a " + msg="${msg}System Administrator.\n\n" + msg="${msg}After you press Enter, this system will be " + msg="${msg}halted and powered off.\n\n" + log_failure_msg "$msg" + + log_info_msg "Press Enter to continue..." + wait_for_user + /etc/rc.d/init.d/halt stop + fi + + if [ "${error_value}" -ge 16 ]; then + msg="FAILURE:\n\nUnexpected failure " + msg="${msg}running fsck. Exited with error " + msg="${msg} code: ${error_value}.\n" + log_info_msg $msg + exit ${error_value} + fi + + exit 0 + ;; + *) + echo "Usage: ${0} {start}" + exit 1 + ;; +esac + +# End checkfs diff --git a/xi/init.d/cleanfs b/xi/init.d/cleanfs new file mode 100644 index 0000000..c75923c --- /dev/null +++ b/xi/init.d/cleanfs @@ -0,0 +1,122 @@ +#!/bin/sh +######################################################################## +# Begin cleanfs +# +# Description : Clean file system +# +# Authors : Gerard Beekmans - gerard@linuxfromscratch.org +# DJ Lucas - dj@linuxfromscratch.org +# Update : Bruce Dubbs - bdubbs@linuxfromscratch.org +# +# Version : LFS 7.0 +# +######################################################################## + +### BEGIN INIT INFO +# Provides: cleanfs +# Required-Start: $local_fs +# Should-Start: +# Required-Stop: +# Should-Stop: +# Default-Start: S +# Default-Stop: +# Short-Description: Cleans temporary directories early in the boot process. +# Description: Cleans temporary directories /run, /var/lock, and +# optionally, /tmp. cleanfs also creates /run/utmp +# and any files defined in /etc/sysconfig/createfiles. +# X-LFS-Provided-By: LFS +### END INIT INFO + +. /lib/lsb/init-functions + +# Function to create files/directory on boot. +create_files() +{ + # Input to file descriptor 9 and output to stdin (redirection) + exec 9>&0 < /etc/sysconfig/createfiles + + while read name type perm usr grp dtype maj min junk + do + # Ignore comments and blank lines. + case "${name}" in + ""|\#*) continue ;; + esac + + # Ignore existing files. + if [ ! -e "${name}" ]; then + # Create stuff based on its type. + case "${type}" in + dir) + mkdir "${name}" + ;; + file) + :> "${name}" + ;; + dev) + case "${dtype}" in + char) + mknod "${name}" c ${maj} ${min} + ;; + block) + mknod "${name}" b ${maj} ${min} + ;; + pipe) + mknod "${name}" p + ;; + *) + log_warning_msg "\nUnknown device type: ${dtype}" + ;; + esac + ;; + *) + log_warning_msg "\nUnknown type: ${type}" + continue + ;; + esac + + # Set up the permissions, too. + chown ${usr}:${grp} "${name}" + chmod ${perm} "${name}" + fi + done + + # Close file descriptor 9 (end redirection) + exec 0>&9 9>&- + return 0 +} + +case "${1}" in + start) + log_info_msg "Cleaning file systems:" + + if [ "${SKIPTMPCLEAN}" = "" ]; then + log_info_msg2 " /tmp" + cd /tmp && + find . -xdev -mindepth 1 ! -name lost+found -delete || failed=1 + fi + + > /run/utmp + + if grep -q '^utmp:' /etc/group ; then + chmod 664 /run/utmp + chgrp utmp /run/utmp + fi + + (exit ${failed}) + evaluate_retval + + if egrep -qv '^(#|$)' /etc/sysconfig/createfiles 2>/dev/null; then + log_info_msg "Creating files and directories... " + create_files # Always returns 0 + evaluate_retval + fi + + exit $failed + ;; + *) + echo "Usage: ${0} {start}" + exit 1 + ;; +esac + +# End cleanfs diff --git a/xi/init.d/console b/xi/init.d/console new file mode 100644 index 0000000..a5338cc --- /dev/null +++ b/xi/init.d/console @@ -0,0 +1,107 @@ +#!/bin/sh +######################################################################## +# Begin console +# +# Description : Sets keymap and screen font +# +# Authors : Gerard Beekmans - gerard@linuxfromscratch.org +# Alexander E. Patrakov +# DJ Lucas - dj@linuxfromscratch.org +# Update : Bruce Dubbs - bdubbs@linuxfromscratch.org +# +# Version : LFS 7.0 +# +######################################################################## + +### BEGIN INIT INFO +# Provides: console +# Required-Start: $local_fs +# Should-Start: udev_retry +# Required-Stop: +# Should-Stop: +# Default-Start: S +# Default-Stop: +# Short-Description: Sets up a localised console. +# Description: Sets up fonts and language settings for the user's +# local as defined by /etc/sysconfig/console. +# X-LFS-Provided-By: LFS +### END INIT INFO + +. /lib/lsb/init-functions + +# Native English speakers probably don't have /etc/sysconfig/console at all +[ -r /etc/sysconfig/console ] && . /etc/sysconfig/console + +failed=0 + +case "${1}" in + start) + # See if we need to do anything + if [ -z "${KEYMAP}" ] && [ -z "${KEYMAP_CORRECTIONS}" ] && + [ -z "${FONT}" ] && [ -z "${LEGACY_CHARSET}" ] && + ! is_true "${UNICODE}"; then + exit 0 + fi + + # There should be no bogus failures below this line! + log_info_msg "Setting up Linux console..." + + # Figure out if a framebuffer console is used + [ -d /sys/class/graphics/fb0 ] && use_fb=1 || use_fb=0 + + # Figure out the command to set the console into the + # desired mode + is_true "${UNICODE}" && + MODE_COMMAND="echo -en '\033%G' && kbd_mode -u" || + MODE_COMMAND="echo -en '\033%@\033(K' && kbd_mode -a" + + # On framebuffer consoles, font has to be set for each vt in + # UTF-8 mode. This doesn't hurt in non-UTF-8 mode also. + + ! is_true "${use_fb}" || [ -z "${FONT}" ] || + MODE_COMMAND="${MODE_COMMAND} && setfont ${FONT}" + + # Apply that command to all consoles mentioned in + # /etc/inittab. Important: in the UTF-8 mode this should + # happen before setfont, otherwise a kernel bug will + # show up and the unicode map of the font will not be + # used. + + for TTY in `grep '^[^#].*respawn:/sbin/agetty' /etc/inittab | + grep -o '\btty[[:digit:]]*\b'` + do + openvt -f -w -c ${TTY#tty} -- \ + /bin/sh -c "${MODE_COMMAND}" || failed=1 + done + + # Set the font (if not already set above) and the keymap + [ "${use_fb}" == "1" ] || [ -z "${FONT}" ] || setfont $FONT || failed=1 + + [ -z "${KEYMAP}" ] || + loadkeys ${KEYMAP} >/dev/null 2>&1 || + failed=1 + + [ -z "${KEYMAP_CORRECTIONS}" ] || + loadkeys ${KEYMAP_CORRECTIONS} >/dev/null 2>&1 || + failed=1 + + # Convert the keymap from $LEGACY_CHARSET to UTF-8 + [ -z "$LEGACY_CHARSET" ] || + dumpkeys -c "$LEGACY_CHARSET" | loadkeys -u >/dev/null 2>&1 || + failed=1 + + # If any of the commands above failed, the trap at the + # top would set $failed to 1 + ( exit $failed ) + evaluate_retval + + exit $failed + ;; + + *) + echo "Usage: ${0} {start}" + exit 1 + ;; +esac + +# End console diff --git a/xi/init.d/halt b/xi/init.d/halt new file mode 100644 index 0000000..46ccecf --- /dev/null +++ b/xi/init.d/halt @@ -0,0 +1,43 @@ +#!/bin/sh +######################################################################## +# Begin halt +# +# Description : Halt Script +# +# Authors : Gerard Beekmans - gerard@linuxfromscratch.org +# DJ Lucas - dj@linuxfromscratch.org +# Update : Bruce Dubbs - bdubbs@linuxfromscratch.org +# : Pierre Labastie - pierre@linuxfromscratch.org +# +# Version : LFS 7.0 +# +# Notes : Update March 24th, 2022: change "stop" to "start". +# Add the $last facility to Required-start +# +######################################################################## + +### BEGIN INIT INFO +# Provides: halt +# Required-Start: $last +# Should-Start: +# Required-Stop: +# Should-Stop: +# Default-Start: 0 +# Default-Stop: +# Short-Description: Halts the system. +# Description: Halts the System. +# X-LFS-Provided-By: LFS +### END INIT INFO + +case "${1}" in + start) + halt -d -f -i -p + ;; + + *) + echo "Usage: {start}" + exit 1 + ;; +esac + +# End halt diff --git a/xi/init.d/localnet b/xi/init.d/localnet new file mode 100644 index 0000000..83d63a0 --- /dev/null +++ b/xi/init.d/localnet @@ -0,0 +1,70 @@ +#!/bin/sh +######################################################################## +# Begin localnet +# +# Description : Loopback device +# +# Authors : Gerard Beekmans - gerard@linuxfromscratch.org +# DJ Lucas - dj@linuxfromscratch.org +# Update : Bruce Dubbs - bdubbs@linuxfromscratch.org +# +# Version : LFS 7.0 +# +######################################################################## + +### BEGIN INIT INFO +# Provides: localnet +# Required-Start: mountvirtfs +# Should-Start: modules +# Required-Stop: +# Should-Stop: +# Default-Start: S +# Default-Stop: 0 6 +# Short-Description: Starts the local network. +# Description: Sets the hostname of the machine and starts the +# loopback interface. +# X-LFS-Provided-By: LFS +### END INIT INFO + +. /lib/lsb/init-functions +[ -r /etc/sysconfig/network ] && . /etc/sysconfig/network +[ -r /etc/hostname ] && HOSTNAME=`cat /etc/hostname` + +case "${1}" in + start) + log_info_msg "Bringing up the loopback interface..." + ip addr add 127.0.0.1/8 label lo dev lo + ip link set lo up + evaluate_retval + + log_info_msg "Setting hostname to ${HOSTNAME}..." + hostname ${HOSTNAME} + evaluate_retval + ;; + + stop) + log_info_msg "Bringing down the loopback interface..." + ip link set lo down + evaluate_retval + ;; + + restart) + ${0} stop + sleep 1 + ${0} start + ;; + + status) + echo "Hostname is: $(hostname)" + ip link show lo + ;; + + *) + echo "Usage: ${0} {start|stop|restart|status}" + exit 1 + ;; +esac + +exit 0 + +# End localnet diff --git a/xi/init.d/modules b/xi/init.d/modules new file mode 100644 index 0000000..3ef4cec --- /dev/null +++ b/xi/init.d/modules @@ -0,0 +1,82 @@ +#!/bin/sh +######################################################################## +# Begin modules +# +# Description : Module auto-loading script +# +# Authors : Zack Winkles +# DJ Lucas - dj@linuxfromscratch.org +# Update : Bruce Dubbs - bdubbs@linuxfromscratch.org +# +# Version : LFS 7.0 +# +######################################################################## + +### BEGIN INIT INFO +# Provides: modules +# Required-Start: mountvirtfs +# Should-Start: +# Required-Stop: +# Should-Stop: +# Default-Start: S +# Default-Stop: +# Short-Description: Loads required modules. +# Description: Loads modules listed in /etc/sysconfig/modules. +# X-LFS-Provided-By: LFS +### END INIT INFO + +# Assure that the kernel has module support. +[ -e /proc/modules ] || exit 0 + +. /lib/lsb/init-functions + +case "${1}" in + start) + # Exit if there's no modules file or there are no + # valid entries + [ -r /etc/sysconfig/modules ] || exit 0 + egrep -qv '^($|#)' /etc/sysconfig/modules || exit 0 + + log_info_msg "Loading modules:" + + # Only try to load modules if the user has actually given us + # some modules to load. + + while read module args; do + + # Ignore comments and blank lines. + case "$module" in + ""|"#"*) continue ;; + esac + + # Attempt to load the module, passing any arguments provided. + modprobe ${module} ${args} >/dev/null + + # Print the module name if successful, otherwise take note. + if [ $? -eq 0 ]; then + log_info_msg2 " ${module}" + else + failedmod="${failedmod} ${module}" + fi + done < /etc/sysconfig/modules + + # Print a message about successfully loaded modules on the correct line. + log_success_msg2 + + # Print a failure message with a list of any modules that + # may have failed to load. + if [ -n "${failedmod}" ]; then + log_failure_msg "Failed to load modules:${failedmod}" + exit 1 + fi + ;; + + *) + echo "Usage: ${0} {start}" + exit 1 + ;; +esac + +exit 0 + +# End modules diff --git a/xi/init.d/mountfs b/xi/init.d/mountfs new file mode 100644 index 0000000..6bf2d6f --- /dev/null +++ b/xi/init.d/mountfs @@ -0,0 +1,78 @@ +#!/bin/sh +######################################################################## +# Begin mountfs +# +# Description : File System Mount Script +# +# Authors : Gerard Beekmans - gerard@linuxfromscratch.org +# DJ Lucas - dj@linuxfromscratch.org +# Update : Bruce Dubbs - bdubbs@linuxfromscratch.org +# +# Version : LFS 7.0 +# +######################################################################## + +### BEGIN INIT INFO +# Provides: $local_fs +# Required-Start: udev checkfs +# Should-Start: modules +# Required-Stop: localnet +# Should-Stop: +# Default-Start: S +# Default-Stop: 0 6 +# Short-Description: Mounts/unmounts local filesystems defined in /etc/fstab. +# Description: Remounts root filesystem read/write and mounts all +# remaining local filesystems defined in /etc/fstab on +# start. Remounts root filesystem read-only and unmounts +# remaining filesystems on stop. +# X-LFS-Provided-By: LFS +### END INIT INFO + +. /lib/lsb/init-functions + +case "${1}" in + start) + log_info_msg "Remounting root file system in read-write mode..." + mount --options remount,rw / >/dev/null + evaluate_retval + + # Remove fsck-related file system watermarks. + rm -f /fastboot /forcefsck + + # Make sure /dev/pts exists + mkdir -p /dev/pts + + # This will mount all filesystems that do not have _netdev in + # their option list. _netdev denotes a network filesystem. + + log_info_msg "Mounting remaining file systems..." + failed=0 + mount --all --test-opts no_netdev >/dev/null || failed=1 + evaluate_retval + exit $failed + ;; + + stop) + # Don't unmount virtual file systems like /run + log_info_msg "Unmounting all other currently mounted file systems..." + # Ensure any loop devies are removed + losetup -D + umount --all --detach-loop --read-only \ + --types notmpfs,nosysfs,nodevtmpfs,noproc,nodevpts >/dev/null + evaluate_retval + + # Make sure / is mounted read only (umount bug) + mount --options remount,ro / + + # Make all LVM volume groups unavailable, if appropriate + # This fails if swap or / are on an LVM partition + #if [ -x /sbin/vgchange ]; then /sbin/vgchange -an > /dev/null; fi + ;; + + *) + echo "Usage: ${0} {start|stop}" + exit 1 + ;; +esac + +# End mountfs diff --git a/xi/init.d/mountvirtfs b/xi/init.d/mountvirtfs new file mode 100644 index 0000000..6396343 --- /dev/null +++ b/xi/init.d/mountvirtfs @@ -0,0 +1,74 @@ +#!/bin/sh +######################################################################## +# Begin mountvirtfs +# +# Description : Ensure proc, sysfs, run, and dev are mounted +# +# Authors : Gerard Beekmans - gerard@linuxfromscratch.org +# DJ Lucas - dj@linuxfromscratch.org +# Update : Bruce Dubbs - bdubbs@linuxfromscratch.org +# +# Version : LFS 7.0 +# +######################################################################## + +### BEGIN INIT INFO +# Provides: mountvirtfs +# Required-Start: $first +# Should-Start: +# Required-Stop: +# Should-Stop: +# Default-Start: S +# Default-Stop: +# Short-Description: Mounts various special fs needed at start +# Description: Mounts /sys and /proc virtual (kernel) filesystems. +# Mounts /run (tmpfs) and /dev (devtmpfs). +# This is done only if they are not already mounted. +# with the kernel config proposed in the book, dev +# should be automatically mounted by the kernel. +# X-LFS-Provided-By: LFS +### END INIT INFO + +. /lib/lsb/init-functions + +case "${1}" in + start) + # Make sure /run is available before logging any messages + if ! mountpoint /run >/dev/null; then + mount /run || failed=1 + fi + + mkdir -p /run/lock /run/shm + chmod 1777 /run/shm /run/lock + + log_info_msg "Mounting virtual file systems: ${INFO}/run" + + if ! mountpoint /proc >/dev/null; then + log_info_msg2 " ${INFO}/proc" + mount -o nosuid,noexec,nodev /proc || failed=1 + fi + + if ! mountpoint /sys >/dev/null; then + log_info_msg2 " ${INFO}/sys" + mount -o nosuid,noexec,nodev /sys || failed=1 + fi + + if ! mountpoint /dev >/dev/null; then + log_info_msg2 " ${INFO}/dev" + mount -o mode=0755,nosuid /dev || failed=1 + fi + + ln -sfn /run/shm /dev/shm + + (exit ${failed}) + evaluate_retval + exit $failed + ;; + + *) + echo "Usage: ${0} {start}" + exit 1 + ;; +esac + +# End mountvirtfs diff --git a/xi/init.d/network b/xi/init.d/network new file mode 100644 index 0000000..5b2dd9b --- /dev/null +++ b/xi/init.d/network @@ -0,0 +1,90 @@ +#!/bin/sh +######################################################################## +# Begin network +# +# Description : Network Control Script +# +# Authors : Gerard Beekmans - gerard@linuxfromscratch.org +# Nathan Coulson - nathan@linuxfromscratch.org +# Kevin P. Fleming - kpfleming@linuxfromscratch.org +# DJ Lucas - dj@linuxfromscratch.org +# Update : Bruce Dubbs - bdubbs@linuxfromscratch.org +# +# Version : LFS 7.0 +# +######################################################################## + +### BEGIN INIT INFO +# Provides: $network +# Required-Start: $local_fs localnet swap +# Should-Start: $syslog firewalld iptables nftables +# Required-Stop: $local_fs localnet swap +# Should-Stop: $syslog firewalld iptables nftables +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: Starts and configures network interfaces. +# Description: Starts and configures network interfaces. +# X-LFS-Provided-By: LFS +### END INIT INFO + +case "${1}" in + start) + # if the default route exists, network is already configured + if ip route | grep -q "^default"; then return 0; fi + # Start all network interfaces + for file in /etc/sysconfig/ifconfig.* + do + interface=${file##*/ifconfig.} + + # Skip if $file is * (because nothing was found) + if [ "${interface}" = "*" ]; then continue; fi + + /sbin/ifup ${interface} + done + ;; + + stop) + # Unmount any network mounted file systems + umount --all --force --types nfs,cifs,nfs4 + + # Reverse list + net_files="" + for file in /etc/sysconfig/ifconfig.* + do + net_files="${file} ${net_files}" + done + + # Stop all network interfaces + for file in ${net_files} + do + interface=${file##*/ifconfig.} + + # Skip if $file is * (because nothing was found) + if [ "${interface}" = "*" ]; then continue; fi + + # See if interface exists + if [ ! -e /sys/class/net/$interface ]; then continue; fi + + # Is interface UP? + ip link show $interface 2>/dev/null | grep -q "state UP" + if [ $? -ne 0 ]; then continue; fi + + /sbin/ifdown ${interface} + done + ;; + + restart) + ${0} stop + sleep 1 + ${0} start + ;; + + *) + echo "Usage: ${0} {start|stop|restart}" + exit 1 + ;; +esac + +exit 0 + +# End network diff --git a/xi/init.d/rc b/xi/init.d/rc new file mode 100644 index 0000000..7dd503a --- /dev/null +++ b/xi/init.d/rc @@ -0,0 +1,227 @@ +#!/bin/bash +######################################################################## +# Begin rc +# +# Description : Main Run Level Control Script +# +# Authors : Gerard Beekmans - gerard@linuxfromscratch.org +# : DJ Lucas - dj@linuxfromscratch.org +# Updates : Bruce Dubbs - bdubbs@linuxfromscratch.org +# : Pierre Labastie - pierre@linuxfromscratch.org +# +# Version : LFS 7.0 +# +# Notes : Updates March 24th, 2022: new semantics of S/K files +# - Instead of testing that S scripts were K scripts in the +# previous runlevel, test that they were not S scripts +# - Instead of testing that K scripts were S scripts in the +# previous runlevel, test that they were not K scripts +# - S scripts in runlevel 0 or 6 are now run with +# "script start" (was "script stop" previously). +######################################################################## + +. /lib/lsb/init-functions + +print_error_msg() +{ + log_failure_msg + # $i is set when called + MSG="FAILURE:\n\nYou should not be reading this error message.\n\n" + MSG="${MSG}It means that an unforeseen error took place in\n" + MSG="${MSG}${i},\n" + MSG="${MSG}which exited with a return value of ${error_value}.\n" + + MSG="${MSG}If you're able to track this error down to a bug in one of\n" + MSG="${MSG}the files provided by the ${DISTRO_MINI} book,\n" + MSG="${MSG}please be so kind to inform us at ${DISTRO_CONTACT}.\n" + log_failure_msg "${MSG}" + + log_info_msg "Press Enter to continue..." + wait_for_user +} + +check_script_status() +{ + # $i is set when called + if [ ! -f ${i} ]; then + log_warning_msg "${i} is not a valid symlink." + SCRIPT_STAT="1" + fi + + if [ ! -x ${i} ]; then + log_warning_msg "${i} is not executable, skipping." + SCRIPT_STAT="1" + fi +} + +run() +{ + if [ -z $interactive ]; then + ${1} ${2} + return $? + fi + + while true; do + read -p "Run ${1} ${2} (Yes/no/continue)? " -n 1 runit + echo + + case ${runit} in + c | C) + interactive="" + ${i} ${2} + ret=${?} + break; + ;; + + n | N) + return 0 + ;; + + y | Y) + ${i} ${2} + ret=${?} + break + ;; + esac + done + + return $ret +} + +# Read any local settings/overrides +[ -r /etc/sysconfig/rc.site ] && source /etc/sysconfig/rc.site + +DISTRO=${DISTRO:-"Linux From Scratch"} +DISTRO_CONTACT=${DISTRO_CONTACT:-"lfs-dev@lists.linuxfromscratch.org (Registration required)"} +DISTRO_MINI=${DISTRO_MINI:-"LFS"} +IPROMPT=${IPROMPT:-"no"} + +# These 3 signals will not cause our script to exit +trap "" INT QUIT TSTP + +[ "${1}" != "" ] && runlevel=${1} + +if [ "${runlevel}" == "" ]; then + echo "Usage: ${0} <runlevel>" >&2 + exit 1 +fi + +previous=${PREVLEVEL} +[ "${previous}" == "" ] && previous=N + +if [ ! -d /etc/rc.d/rc${runlevel}.d ]; then + log_info_msg "/etc/rc.d/rc${runlevel}.d does not exist.\n" + exit 1 +fi + +if [ "$runlevel" == "6" -o "$runlevel" == "0" ]; then IPROMPT="no"; fi + +# Note: In ${LOGLEVEL:-7}, it is ':' 'dash' '7', not minus 7 +if [ "$runlevel" == "S" ]; then + [ -r /etc/sysconfig/console ] && source /etc/sysconfig/console + dmesg -n "${LOGLEVEL:-7}" +fi + +if [ "${IPROMPT}" == "yes" -a "${runlevel}" == "S" ]; then + # The total length of the distro welcome string, without escape codes + wlen=${wlen:-$(echo "Welcome to ${DISTRO}" | wc -c )} + welcome_message=${welcome_message:-"Welcome to ${INFO}${DISTRO}${NORMAL}"} + + # The total length of the interactive string, without escape codes + ilen=${ilen:-$(echo "Press 'I' to enter interactive startup" | wc -c )} + i_message=${i_message:-"Press '${FAILURE}I${NORMAL}' to enter interactive startup"} + + + # dcol and icol are spaces before the message to center the message + # on screen. itime is the amount of wait time for the user to press a key + wcol=$(( ( ${COLUMNS} - ${wlen} ) / 2 )) + icol=$(( ( ${COLUMNS} - ${ilen} ) / 2 )) + itime=${itime:-"3"} + + echo -e "\n\n" + echo -e "\\033[${wcol}G${welcome_message}" + echo -e "\\033[${icol}G${i_message}${NORMAL}" + echo "" + read -t "${itime}" -n 1 interactive 2>&1 > /dev/null +fi + +# Make lower case +[ "${interactive}" == "I" ] && interactive="i" +[ "${interactive}" != "i" ] && interactive="" + +# Read the state file if it exists from runlevel S +[ -r /run/interactive ] && source /run/interactive + +# Stop all services marked as K, except if marked as K in the previous +# runlevel: it is the responsibility of the script to not try to kill +# a non running service +if [ "${previous}" != "N" ]; then + for i in $(ls -v /etc/rc.d/rc${runlevel}.d/K* 2> /dev/null) + do + check_script_status + if [ "${SCRIPT_STAT}" == "1" ]; then + SCRIPT_STAT="0" + continue + fi + + suffix=${i#/etc/rc.d/rc${runlevel}.d/K[0-9][0-9]} + [ -e /etc/rc.d/rc${previous}.d/K[0-9][0-9]$suffix ] && continue + + run ${i} stop + error_value=${?} + + if [ "${error_value}" != "0" ]; then print_error_msg; fi + done +fi + +if [ "${previous}" == "N" ]; then export IN_BOOT=1; fi + +if [ "$runlevel" == "6" -a -n "${FASTBOOT}" ]; then + touch /fastboot +fi + + +# Start all services marked as S in this runlevel, except if marked as +# S in the previous runlevel +# it is the responsabily of the script to not try to start an already running +# service +for i in $( ls -v /etc/rc.d/rc${runlevel}.d/S* 2> /dev/null) +do + + if [ "${previous}" != "N" ]; then + suffix=${i#/etc/rc.d/rc${runlevel}.d/S[0-9][0-9]} + [ -e /etc/rc.d/rc${previous}.d/S[0-9][0-9]$suffix ] && continue + fi + + check_script_status + if [ "${SCRIPT_STAT}" == "1" ]; then + SCRIPT_STAT="0" + continue + fi + + run ${i} start + + error_value=${?} + + if [ "${error_value}" != "0" ]; then print_error_msg; fi +done + +# Store interactive variable on switch from runlevel S and remove if not +if [ "${runlevel}" == "S" -a "${interactive}" == "i" ]; then + echo "interactive=\"i\"" > /run/interactive +else + rm -f /run/interactive 2> /dev/null +fi + +# Copy the boot log on initial boot only +if [ "${previous}" == "N" -a "${runlevel}" != "S" ]; then + cat $BOOTLOG >> /var/log/boot.log + + # Mark the end of boot + echo "--------" >> /var/log/boot.log + + # Remove the temporary file + rm -f $BOOTLOG 2> /dev/null +fi + +# End rc diff --git a/xi/init.d/reboot b/xi/init.d/reboot new file mode 100644 index 0000000..b41b033 --- /dev/null +++ b/xi/init.d/reboot @@ -0,0 +1,47 @@ +#!/bin/sh +######################################################################## +# Begin reboot +# +# Description : Reboot Scripts +# +# Authors : Gerard Beekmans - gerard@linuxfromscratch.org +# DJ Lucas - dj@linuxfromscratch.org +# Updates : Bruce Dubbs - bdubbs@linuxfromscratch.org +# : Pierre Labastie - pierre@linuxfromscratch.org +# +# Version : LFS 7.0 +# +# Notes : Update March 24th, 2022: change "stop" to "start". +# Add the $last facility to Required-start +# +######################################################################## + +### BEGIN INIT INFO +# Provides: reboot +# Required-Start: $last +# Should-Start: +# Required-Stop: +# Should-Stop: +# Default-Start: 6 +# Default-Stop: +# Short-Description: Reboots the system. +# Description: Reboots the System. +# X-LFS-Provided-By: LFS +### END INIT INFO + +. /lib/lsb/init-functions + +case "${1}" in + start) + log_info_msg "Restarting system..." + reboot -d -f -i + ;; + + *) + echo "Usage: ${0} {start}" + exit 1 + ;; + +esac + +# End reboot diff --git a/xi/init.d/sendsignals b/xi/init.d/sendsignals new file mode 100644 index 0000000..d2c80eb --- /dev/null +++ b/xi/init.d/sendsignals @@ -0,0 +1,69 @@ +#!/bin/sh +######################################################################## +# Begin sendsignals +# +# Description : Sendsignals Script +# +# Authors : Gerard Beekmans - gerard@linuxfromscratch.org +# DJ Lucas - dj@linuxfromscratch.org +# Update : Bruce Dubbs - bdubbs@linuxfromscratch.org +# +# Version : LFS 7.0 +# +######################################################################## + +### BEGIN INIT INFO +# Provides: sendsignals +# Required-Start: +# Should-Start: +# Required-Stop: $local_fs swap localnet +# Should-Stop: +# Default-Start: +# Default-Stop: 0 6 +# Short-Description: Attempts to kill remaining processes. +# Description: Attempts to kill remaining processes. +# X-LFS-Provided-By: LFS +### END INIT INFO + +. /lib/lsb/init-functions + +case "${1}" in + stop) + omit=$(pidof mdmon) + [ -n "$omit" ] && omit="-o $omit" + + log_info_msg "Sending all processes the TERM signal..." + killall5 -15 $omit + error_value=${?} + + sleep ${KILLDELAY} + + if [ "${error_value}" = 0 -o "${error_value}" = 2 ]; then + log_success_msg + else + log_failure_msg + fi + + log_info_msg "Sending all processes the KILL signal..." + killall5 -9 $omit + error_value=${?} + + sleep ${KILLDELAY} + + if [ "${error_value}" = 0 -o "${error_value}" = 2 ]; then + log_success_msg + else + log_failure_msg + fi + ;; + + *) + echo "Usage: ${0} {stop}" + exit 1 + ;; + +esac + +exit 0 + +# End sendsignals diff --git a/xi/init.d/setclock b/xi/init.d/setclock new file mode 100644 index 0000000..cd4f617 --- /dev/null +++ b/xi/init.d/setclock @@ -0,0 +1,63 @@ +#!/bin/sh +######################################################################## +# Begin setclock +# +# Description : Setting Linux Clock +# +# Authors : Gerard Beekmans - gerard@linuxfromscratch.org +# DJ Lucas - dj@linuxfromscratch.org +# Update : Bruce Dubbs - bdubbs@linuxfromscratch.org +# +# Version : LFS 7.0 +# +######################################################################## + +### BEGIN INIT INFO +# Provides: +# Required-Start: +# Should-Start: modules +# Required-Stop: +# Should-Stop: $syslog +# Default-Start: S +# Default-Stop: +# Short-Description: Stores and restores time from the hardware clock +# Description: On boot, system time is obtained from hwclock. The +# hardware clock can also be set on shutdown. +# X-LFS-Provided-By: LFS +### END INIT INFO + +. /lib/lsb/init-functions + +[ -r /etc/sysconfig/clock ] && . /etc/sysconfig/clock + + +case "${UTC}" in + yes|true|1) + CLOCKPARAMS="${CLOCKPARAMS} --utc" + ;; + + no|false|0) + CLOCKPARAMS="${CLOCKPARAMS} --localtime" + ;; + +esac + +case ${1} in + start) + hwclock --hctosys ${CLOCKPARAMS} >/dev/null + ;; + + stop) + log_info_msg "Setting hardware clock..." + hwclock --systohc ${CLOCKPARAMS} >/dev/null + evaluate_retval + ;; + + *) + echo "Usage: ${0} {start|stop}" + exit 1 + ;; + +esac + +exit 0 diff --git a/xi/init.d/swap b/xi/init.d/swap new file mode 100644 index 0000000..9747024 --- /dev/null +++ b/xi/init.d/swap @@ -0,0 +1,63 @@ +#!/bin/sh +######################################################################## +# Begin swap +# +# Description : Swap Control Script +# +# Authors : Gerard Beekmans - gerard@linuxfromscratch.org +# DJ Lucas - dj@linuxfromscratch.org +# Update : Bruce Dubbs - bdubbs@linuxfromscratch.org +# +# Version : LFS 7.0 +# +######################################################################## + +### BEGIN INIT INFO +# Provides: swap +# Required-Start: udev +# Should-Start: modules +# Required-Stop: localnet +# Should-Stop: $local_fs +# Default-Start: S +# Default-Stop: 0 6 +# Short-Description: Mounts and unmounts swap partitions. +# Description: Mounts and unmounts swap partitions defined in +# /etc/fstab. +# X-LFS-Provided-By: LFS +### END INIT INFO + +. /lib/lsb/init-functions + +case "${1}" in + start) + log_info_msg "Activating all swap files/partitions..." + swapon -a + evaluate_retval + ;; + + stop) + log_info_msg "Deactivating all swap files/partitions..." + swapoff -a + evaluate_retval + ;; + + restart) + ${0} stop + sleep 1 + ${0} start + ;; + + status) + log_success_msg "Retrieving swap status." + swapon -s + ;; + + *) + echo "Usage: ${0} {start|stop|restart|status}" + exit 1 + ;; +esac + +exit 0 + +# End swap diff --git a/xi/init.d/sysctl b/xi/init.d/sysctl new file mode 100644 index 0000000..c90da9d --- /dev/null +++ b/xi/init.d/sysctl @@ -0,0 +1,54 @@ +#!/bin/sh +######################################################################## +# Begin sysctl +# +# Description : File uses /etc/sysctl.conf to set kernel runtime +# parameters +# +# Authors : Nathan Coulson (nathan@linuxfromscratch.org) +# Matthew Burgress (matthew@linuxfromscratch.org) +# DJ Lucas - dj@linuxfromscratch.org +# Update : Bruce Dubbs - bdubbs@linuxfromscratch.org +# +# Version : LFS 7.0 +# +######################################################################## + +### BEGIN INIT INFO +# Provides: sysctl +# Required-Start: mountvirtfs +# Should-Start: console +# Required-Stop: +# Should-Stop: +# Default-Start: S +# Default-Stop: +# Short-Description: Makes changes to the proc filesystem +# Description: Makes changes to the proc filesystem as defined in +# /etc/sysctl.conf. See 'man sysctl(8)'. +# X-LFS-Provided-By: LFS +### END INIT INFO + +. /lib/lsb/init-functions + +case "${1}" in + start) + if [ -f "/etc/sysctl.conf" ]; then + log_info_msg "Setting kernel runtime parameters..." + sysctl -q -p + evaluate_retval + fi + ;; + + status) + sysctl -a + ;; + + *) + echo "Usage: ${0} {start|status}" + exit 1 + ;; +esac + +exit 0 + +# End sysctl diff --git a/xi/init.d/sysklogd b/xi/init.d/sysklogd new file mode 100644 index 0000000..e86b87b --- /dev/null +++ b/xi/init.d/sysklogd @@ -0,0 +1,79 @@ +#!/bin/sh +######################################################################## +# Begin sysklogd +# +# Description : Sysklogd loader +# +# Authors : Gerard Beekmans - gerard@linuxfromscratch.org +# DJ Lucas - dj@linuxfromscratch.org +# Update : Bruce Dubbs - bdubbs@linuxfromscratch.org +# +# Version : LFS 7.0 +# +######################################################################## + +### BEGIN INIT INFO +# Provides: $syslog +# Required-Start: $first localnet +# Should-Start: +# Required-Stop: $local_fs +# Should-Stop: sendsignals +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: Starts kernel and system log daemons. +# Description: Starts kernel and system log daemons. +# /etc/fstab. +# X-LFS-Provided-By: LFS +### END INIT INFO + +. /lib/lsb/init-functions + +case "${1}" in + start) + log_info_msg "Starting system log daemon..." + parms=${SYSKLOGD_PARMS-'-m 0'} + start_daemon /sbin/syslogd $parms + evaluate_retval + + log_info_msg "Starting kernel log daemon..." + start_daemon /sbin/klogd + evaluate_retval + ;; + + stop) + log_info_msg "Stopping kernel log daemon..." + killproc /sbin/klogd + evaluate_retval + + log_info_msg "Stopping system log daemon..." + killproc /sbin/syslogd + evaluate_retval + ;; + + reload) + log_info_msg "Reloading system log daemon config file..." + pid=`pidofproc syslogd` + kill -HUP "${pid}" + evaluate_retval + ;; + + restart) + ${0} stop + sleep 1 + ${0} start + ;; + + status) + statusproc /sbin/syslogd + statusproc klogd + ;; + + *) + echo "Usage: ${0} {start|stop|reload|restart|status}" + exit 1 + ;; +esac + +exit 0 + +# End sysklogd diff --git a/xi/init.d/template b/xi/init.d/template new file mode 100644 index 0000000..0a7872d --- /dev/null +++ b/xi/init.d/template @@ -0,0 +1,69 @@ +#!/bin/sh +######################################################################## +# Begin scriptname +# +# Description : +# +# Authors : +# +# Version : LFS x.x +# +# Notes : +# +######################################################################## + +### BEGIN INIT INFO +# Provides: template +# Required-Start: +# Should-Start: +# Required-Stop: +# Should-Stop: +# Default-Start: +# Default-Stop: +# Short-Description: +# Description: +# X-LFS-Provided-By: +### END INIT INFO + +. /lib/lsb/init-functions + +case "${1}" in + start) + log_info_msg "Starting..." + # if it is possible to use start_daemon + start_daemon fully_qualified_path + # if it is not possible to use start_daemon + # (command to start the daemon is not simple enough) + if ! pidofproc daemon_name_as_reported_by_ps >/dev/null; then + command_to_start_the_service + fi + evaluate_retval + ;; + + stop) + log_info_msg "Stopping..." + # if it is possible to use killproc + killproc fully_qualified_path + # if it is not possible to use killproc + # (the daemon shoudn't be stopped by killing it) + if pidofproc daemon_name_as_reported_by_ps >/dev/null; then + command_to_stop_the_service + fi + evaluate_retval + ;; + + restart) + ${0} stop + sleep 1 + ${0} start + ;; + + *) + echo "Usage: ${0} {start|stop|restart}" + exit 1 + ;; +esac + +exit 0 + +# End scriptname diff --git a/xi/init.d/udev b/xi/init.d/udev new file mode 100644 index 0000000..c74c8e1 --- /dev/null +++ b/xi/init.d/udev @@ -0,0 +1,76 @@ +#!/bin/sh +######################################################################## +# Begin udev +# +# Description : Udev cold-plugging script +# +# Authors : Zack Winkles, Alexander E. Patrakov +# DJ Lucas - dj@linuxfromscratch.org +# Update : Bruce Dubbs - bdubbs@linuxfromscratch.org +# +# Version : LFS 7.0 +# +######################################################################## + +### BEGIN INIT INFO +# Provides: udev $time +# Required-Start: localnet +# Should-Start: modules +# Required-Stop: +# Should-Stop: +# Default-Start: S +# Default-Stop: +# Short-Description: Populates /dev with device nodes. +# Description: Mounts a tempfs on /dev and starts the udevd daemon. +# Device nodes are created as defined by udev. +# X-LFS-Provided-By: LFS +### END INIT INFO + +. /lib/lsb/init-functions + +case "${1}" in + start) + log_info_msg "Populating /dev with device nodes... " + if ! grep -q '[[:space:]]sysfs' /proc/mounts; then + log_failure_msg2 + msg="FAILURE:\n\nUnable to create " + msg="${msg}devices without a SysFS filesystem\n\n" + msg="${msg}After you press Enter, this system " + msg="${msg}will be halted and powered off.\n\n" + log_info_msg "$msg" + log_info_msg "Press Enter to continue..." + wait_for_user + /etc/rc.d/init.d/halt stop + fi + + # Start the udev daemon to continually watch for, and act on, + # uevents + /sbin/udevd --daemon + + # Now traverse /sys in order to "coldplug" devices that have + # already been discovered + /sbin/udevadm trigger --action=add --type=subsystems + /sbin/udevadm trigger --action=add --type=devices + /sbin/udevadm trigger --action=change --type=devices + + # Now wait for udevd to process the uevents we triggered + if ! is_true "$OMIT_UDEV_SETTLE"; then + /sbin/udevadm settle + fi + + # If any LVM based partitions are on the system, ensure they + # are activated so they can be used. + if [ -x /sbin/vgchange ]; then /sbin/vgchange -a y >/dev/null; fi + + log_success_msg2 + ;; + + *) + echo "Usage ${0} {start}" + exit 1 + ;; +esac + +exit 0 + +# End udev diff --git a/xi/init.d/udev_retry b/xi/init.d/udev_retry new file mode 100644 index 0000000..112846a --- /dev/null +++ b/xi/init.d/udev_retry @@ -0,0 +1,75 @@ +#!/bin/sh +######################################################################## +# Begin udev_retry +# +# Description : Udev cold-plugging script (retry) +# +# Authors : Alexander E. Patrakov +# DJ Lucas - dj@linuxfromscratch.org +# Update : Bruce Dubbs - bdubbs@linuxfromscratch.org +# Bryan Kadzban - +# +# Version : LFS 7.0 +# +######################################################################## + +### BEGIN INIT INFO +# Provides: udev_retry +# Required-Start: udev +# Should-Start: $local_fs cleanfs +# Required-Stop: +# Should-Stop: +# Default-Start: S +# Default-Stop: +# Short-Description: Replays failed uevents and creates additional devices. +# Description: Replays any failed uevents that were skipped due to +# slow hardware initialization, and creates those needed +# device nodes +# X-LFS-Provided-By: LFS +### END INIT INFO + +. /lib/lsb/init-functions + +case "${1}" in + start) + log_info_msg "Retrying failed uevents, if any..." + + # As of udev-186, the --run option is no longer valid + #rundir=$(/sbin/udevadm info --run) + rundir=/run/udev + # From Debian: "copy the rules generated before / was mounted + # read-write": + + for file in ${rundir}/tmp-rules--*; do + dest=${file##*tmp-rules--} + [ "$dest" = '*' ] && break + cat $file >> /etc/udev/rules.d/$dest + rm -f $file + done + + # Re-trigger the uevents that may have failed, + # in hope they will succeed now + /bin/sed -e 's/#.*$//' /etc/sysconfig/udev_retry | /bin/grep -v '^$' | \ + while read line ; do + for subsystem in $line ; do + /sbin/udevadm trigger --subsystem-match=$subsystem --action=add + done + done + + # Now wait for udevd to process the uevents we triggered + if ! is_true "$OMIT_UDEV_RETRY_SETTLE"; then + /sbin/udevadm settle + fi + + evaluate_retval + ;; + + *) + echo "Usage ${0} {start}" + exit 1 + ;; +esac + +exit 0 + +# End udev_retry |