From ced9dffda28f1ec2b060f3e419cf3c6b964b03a1 Mon Sep 17 00:00:00 2001 From: Erik Troan Date: Tue, 16 Sep 1997 14:12:05 +0000 Subject: Initial revision --- rc.d/init.d/functions | 139 +++++++++++++++++++++++++++++++++ rc.d/init.d/halt | 58 ++++++++++++++ rc.d/init.d/killall | 20 +++++ rc.d/init.d/network | 72 +++++++++++++++++ rc.d/init.d/nfsfs | 40 ++++++++++ rc.d/init.d/random | 37 +++++++++ rc.d/init.d/single | 29 +++++++ rc.d/init.d/skeleton | 27 +++++++ rc.d/rc | 54 +++++++++++++ rc.d/rc.local | 27 +++++++ rc.d/rc.sysinit | 212 ++++++++++++++++++++++++++++++++++++++++++++++++++ 11 files changed, 715 insertions(+) create mode 100755 rc.d/init.d/functions create mode 100755 rc.d/init.d/halt create mode 100755 rc.d/init.d/killall create mode 100755 rc.d/init.d/network create mode 100755 rc.d/init.d/nfsfs create mode 100755 rc.d/init.d/random create mode 100755 rc.d/init.d/single create mode 100755 rc.d/init.d/skeleton create mode 100755 rc.d/rc create mode 100755 rc.d/rc.local create mode 100755 rc.d/rc.sysinit (limited to 'rc.d') diff --git a/rc.d/init.d/functions b/rc.d/init.d/functions new file mode 100755 index 00000000..e3b1494e --- /dev/null +++ b/rc.d/init.d/functions @@ -0,0 +1,139 @@ +#! /bin/sh +# +# functions This file contains functions to be used by most or all +# shell scripts in the /etc/init.d directory. +# +# Version: @(#) /etc/init.d/functions 1.01 26-Oct-1993 +# +# Author: Miquel van Smoorenburg, +# Hacked by: Greg Galloway and Marc Ewing +# + +# First set up a default search path. +export PATH="/sbin:/usr/sbin:/bin:/usr/bin" + +# A function to start a program. +daemon() { + # Test syntax. + if [ $# = 0 ]; then + echo "Usage: daemon {program}" + return 1 + fi + + # Save basename. + base=`basename $1` + + # See if it's already running. + [ "`pidofproc $base`" != "" ] && return + + # echo basename of the program. + echo -n "$base " + + # And start it up. + $* +} + +# A function to stop a program. +killproc() { + # Test syntax. + if [ $# = 0 ]; then + echo "Usage: killproc {program} [signal]" + return 1 + fi + + notset=0 + # check for second arg to be kill level + if [ "$2" != "" ] ; then + killlevel=$2 + else + notset=1 + killlevel="-9" + fi + + # Save basename. + base=`basename $1` + + # Find pid. + pid=`pidofproc $base` + + # Kill it. + if [ "$pid" != "" ] ; then + echo -n "$base " + if [ "$notset" = 1 ] ; then + # TERM first, then KILL if not dead + kill -TERM $pid + usleep 10000 + dead=`ps aux | awk "{print $2}" | grep $pid` + if [ "$dead" != "" ]; then + sleep 4 + kill -KILL $pid + fi + # use specified level only + else + kill $killlevel $pid + fi + fi + + # Remove pid file if any. + rm -f /var/run/$base.pid +} + +# A function to find the pid of a program. +pidofproc() { + # Test syntax. + if [ $# = 0 ] ; then + echo "Usage: pidofproc {program}" + return 1 + fi + + # First try "pidof" + pid=`pidof $1` + if [ "$pid" != "" ] ; then + echo $pid + return 0 + fi + + # Next try "/var/run/*.pid" files + if [ -f /var/run/$1.pid ] ; then + pid=`head -1 /var/run/$1.pid` + if [ "$pid" != "" ] ; then + echo $pid + return 0 + fi + fi + + # Finally try to extract it from ps + ps auxw | awk 'BEGIN { prog=ARGV[1]; ARGC=1 } + { if ((prog == $11) || (("(" prog ")") == $11) || + ((prog ":") == $11)) { print $2 } }' $1 +} +status() { + # Test syntax. + if [ $# = 0 ] ; then + echo "Usage: status {program}" + return 1 + fi + + # First try "pidof" + pid=`pidof $1` + if [ "$pid" != "" ] ; then + echo "$1 is running..." + return 0 + fi + + # Next try "/var/run/*.pid" files + if [ -f /var/run/$1.pid ] ; then + pid=`head -1 /var/run/$1.pid` + if [ "$pid" != "" ] ; then + echo "$1 dead but pid file exists" + return 1 + fi + fi + # See if /var/lock/subsys/$1 exists + if [ -f /var/lock/subsys/$1 ]; then + echo "$1 dead but subsys locked" + return 2 + fi + echo "$1 is stopped" + return 3 +} diff --git a/rc.d/init.d/halt b/rc.d/init.d/halt new file mode 100755 index 00000000..2c26854e --- /dev/null +++ b/rc.d/init.d/halt @@ -0,0 +1,58 @@ +#!/bin/sh +# +# rc.halt This file is executed by init when it goes into runlevel +# 0 (halt) or runlevel 6 (reboot). It kills all processes, +# unmounts file systems and then either halts or reboots. +# +# Author: Miquel van Smoorenburg, +# Modified for RHS Linux by Damien Neil +# + +# Set the path. +PATH=/sbin:/bin:/usr/bin:/usr/sbin + +# See how we were called. +case "$0" in + *halt) + message="The system is halted" + command="halt" + ;; + *reboot) + message="Please stand by while rebooting the system..." + command="reboot" + ;; + *) + echo "$0: call me as \"rc.halt\" or \"rc.reboot\" please!" + exit 1 + ;; +esac + +# Kill all processes. +[ "${BASH+bash}" = bash ] && enable kill + +echo "Sending all processes the TERM signal..." +kill -15 -1 +sleep 5 +echo "Sending all processes the KILL signal.." +kill -9 -1 + +# Write to wtmp file before unmounting /var +halt -w + +# Turn off swap, then unmount file systems. +echo "Turning off swap" +swapoff -a +echo "Unmounting file systems" +umount -a +mount -n -o remount,ro / + +echo "Remounting remaining filesystems (if any) readonly" +mount | awk '/ext2/ { print $3 }' | while read line; do + mount -n -o ro,remount $line +done + +# Now halt or reboot. +echo "$message" +[ -f /fastboot ] && echo "On the next boot fsck will be skipped." +eval $command -d + diff --git a/rc.d/init.d/killall b/rc.d/init.d/killall new file mode 100755 index 00000000..8ccfa683 --- /dev/null +++ b/rc.d/init.d/killall @@ -0,0 +1,20 @@ +#!/bin/sh + +# Bring down all unneded services that are still running (there shouldn't +# be any, so this is just a sanity check) + +for i in /var/lock/subsys/*; do + # Check if the script is there. + [ ! -f $i ] && continue + + # Get the subsystem name. + subsys=${i#/var/lock/subsys/} + + # Bring the subsystem down. + if [ -f /etc/rc.d/init.d/$subsys.init ]; then + /etc/rc.d/init.d/$subsys.init stop + else + /etc/rc.d/init.d/$subsys stop + fi +done + diff --git a/rc.d/init.d/network b/rc.d/init.d/network new file mode 100755 index 00000000..09ccc604 --- /dev/null +++ b/rc.d/init.d/network @@ -0,0 +1,72 @@ +#!/bin/sh +# +# network Bring up/down networking +# + +# Source function library. +. /etc/rc.d/init.d/functions + +if [ ! -f /etc/sysconfig/network ]; then + exit 0 +fi + +. /etc/sysconfig/network + +if [ -f /etc/sysconfig/pcmcia ]; then + . /etc/sysconfig/pcmcia +fi + +# Turn IP forwarding on or off. We do this before bringing up the interfaces +# to make sure we don't forward when we shouldn't, and we do it even if +# networking isn't configured (why not?). +if [ -d /proc/sys/net/ipv4 ]; then + # people could have left this out of their kernel, which isn't + # exactly an error + if [ ! -f /proc/sys/net/ipv4/ip_forward ] ; then + echo "/proc/sys/net/ipv4/ip_forward is missing -- cannot control IP " \ + "forwarding" >&2 + else + if [ "$FORWARD_IPV4" = "no" -o "$FORWARD_IPV4" = "false" ]; then + value=0 + echo "Disabling IPv4 packet forwarding." + else + echo "Enabling IPv4 packet forwarding." + value=1 + fi + + echo "$value" > /proc/sys/net/ipv4/ip_forward + fi +fi + +# Check that networking is up. +[ ${NETWORKING} = "no" ] && exit 0 + +[ -f /sbin/ifconfig ] || exit 0 + +cd /etc/sysconfig/network-scripts + +interfaces=`ls ifcfg* | grep -v ifcfg-lo | grep -v :` + +# See how we were called. +case "$1" in + start) + ./ifup ifcfg-lo + for i in $interfaces; do + ./ifup $i boot + done + + touch /var/lock/subsys/network + ;; + stop) + for i in $interfaces; do + ./ifdown $i boot + done + ./ifdown ifcfg-lo + rm -f /var/lock/subsys/network + ;; + *) + echo "Usage: network {start|stop}" + exit 1 +esac + +exit 0 diff --git a/rc.d/init.d/nfsfs b/rc.d/init.d/nfsfs new file mode 100755 index 00000000..6da8eaa9 --- /dev/null +++ b/rc.d/init.d/nfsfs @@ -0,0 +1,40 @@ +#!/bin/sh +# +# nfsfs Mount NFS filesystems. +# +# Version: @(#) /etc/init.d/skeleton 1.01 26-Oct-1993 +# +# Author: Miquel van Smoorenburg, +# + +# Source networking configuration. +if [ ! -f /etc/sysconfig/network ]; then + exit 0 +fi + +. /etc/sysconfig/network + +# Check that networking is up. +[ ${NETWORKING} = "no" ] && exit 0 + +# See how we were called. +case "$1" in + start) + echo -n "Mounting remote filesystems." + mount -a -t nfs + touch /var/lock/subsys/nfsfs + echo + ;; + stop) + echo -n "Unmounting remote filesystems." + umount -a -t nfs + rm -f /var/lock/subsys/nfsfs + echo + ;; + *) + echo "Usage: nfsfs {start|stop}" + exit 1 +esac + +exit 0 + diff --git a/rc.d/init.d/random b/rc.d/init.d/random new file mode 100755 index 00000000..348f0295 --- /dev/null +++ b/rc.d/init.d/random @@ -0,0 +1,37 @@ +#!/bin/sh +# +# random Script to snapshot random state and reload it at boot time. +# +# Author: Theodore Ts'o +# + +random_seed=/var/run/random-seed + +# See how we were called. +case "$1" in + start) + echo "Initializing random number generator..." + # Carry a random seed from start-up to start-up + # Load and then save 512 bytes, which is the size of the entropy pool + if [ -f $random_seed ]; then + cat $random_seed >/dev/urandom + fi + dd if=/dev/urandom of=$random_seed count=1 bs=512 2>/dev/null + touch /var/lock/subsys/random + + ;; + stop) + # Carry a random seed from shut-down to start-up + # Save 512 bytes, which is the size of the entropy pool + echo "Saving random seed..." + dd if=/dev/urandom of=$random_seed count=1 bs=512 2>/dev/null + + rm -f /var/lock/subsys/random + ;; + *) + echo "Usage: random {start|stop}" + exit 1 +esac + +exit 0 + diff --git a/rc.d/init.d/single b/rc.d/init.d/single new file mode 100755 index 00000000..98140a9c --- /dev/null +++ b/rc.d/init.d/single @@ -0,0 +1,29 @@ +#!/bin/sh +# +# +# rc.single This file is executed by init when it goes into runlevel +# 1, which is the administrative state. It kills all +# deamons and then puts the system into single user mode. +# Note that the file systems are kept mounted. +# +# Author: Miquel van Smoorenburg, +# Modified for RHS Linux by Damien Neil +# + +# Set the path. +PATH=/sbin:/bin:/usr/sbin:/usr/bin + +# Kill all processes. +[ "${BASH+bash}" = bash ] && enable kill + +echo "Sending all processes the TERM signal..." +kill -15 -1 +sleep 5 +echo "Sending all processes the KILL signal.." +kill -9 -1 + +rm -f /var/lock/subsys/* + +# Now go to the single user level. +echo "Telling INIT to go to single user mode." +exec init -t1 S diff --git a/rc.d/init.d/skeleton b/rc.d/init.d/skeleton new file mode 100755 index 00000000..a0d2758b --- /dev/null +++ b/rc.d/init.d/skeleton @@ -0,0 +1,27 @@ +#!/bin/sh +# +# skeleton Example file to build /etc/init.d scripts. +# +# Version: @(#) /etc/init.d/skeleton 1.01 26-Oct-1993 +# +# Author: Miquel van Smoorenburg, +# + +# Source function library. +. /etc/rc.d/init.d/functions + +# See how we were called. +case "$1" in + start) + touch /var/lock/subsys/skeleton + ;; + stop) + rm -f /var/lock/subsys/skeleton + ;; + *) + echo "Usage: skeleton {start|stop}" + exit 1 +esac + +exit 0 + diff --git a/rc.d/rc b/rc.d/rc new file mode 100755 index 00000000..a2b94559 --- /dev/null +++ b/rc.d/rc @@ -0,0 +1,54 @@ +#!/bin/bash +# +# rc This file is responsible for starting/stopping +# services when the runlevel changes. It is also +# responsible for the very first setup of basic +# things, such as setting the hostname. +# +# Author: Miquel van Smoorenburg, +# Modified for RHS Linux by Damien Neil +# + +# Source function library. +. /etc/rc.d/init.d/functions + +# Now find out what the current and what the previous runlevel are. +argv1="$1" +set `/sbin/runlevel` +runlevel=$2 +previous=$1 +export runlevel previous + +# Get first argument. Set new runlevel to this argument. +[ "$1" != "" ] && runlevel="$argv1" + +# Is there an rc directory for this new runlevel? +if [ -d /etc/rc.d/rc$runlevel.d ]; then + # First, run the KILL scripts. + for i in /etc/rc.d/rc$runlevel.d/K*; do + # Check if the script is there. + [ ! -f $i ] && continue + + # Check if the subsystem is already up. + subsys=${i#/etc/rc.d/rc$runlevel.d/K??} + [ ! -f /var/lock/subsys/$subsys ] && \ + [ ! -f /var/lock/subsys/${subsys}.init ] && continue + + # Bring the subsystem down. + $i stop + done + + # Now run the START scripts. + for i in /etc/rc.d/rc$runlevel.d/S*; do + # Check if the script is there. + [ ! -f $i ] && continue + + # Check if the subsystem is already up. + subsys=${i#/etc/rc.d/rc$runlevel.d/S??} + [ -f /var/lock/subsys/$subsys ] && \ + [ -f /var/lock/subsys/${subsys}.init ] && continue + + # Bring the subsystem up. + $i start + done +fi diff --git a/rc.d/rc.local b/rc.d/rc.local new file mode 100755 index 00000000..51009563 --- /dev/null +++ b/rc.d/rc.local @@ -0,0 +1,27 @@ +#!/bin/sh + +# This script will be executed *after* all the other init scripts. +# You can put your own initialization stuff in here if you don't +# want to do the full Sys V style init stuff. + +if [ -f /etc/redhat-release ]; then + R=$(cat /etc/redhat-release) +else + R="release 3.0.3" +fi + +arch=$(uname -m) +a="a" +case "_$arch" in + _a*) a="an";; + _i*) a="an";; +esac + +# This will overwrite /etc/issue at every boot. So, make any changes you +# want to make to /etc/issue here or you will lose them when you reboot. +echo "" > /etc/issue +echo "Red Hat Linux $R" >> /etc/issue +echo "Kernel $(uname -r) on $a $(uname -m)" >> /etc/issue + +cp -f /etc/issue /etc/issue.net +echo >> /etc/issue diff --git a/rc.d/rc.sysinit b/rc.d/rc.sysinit new file mode 100755 index 00000000..af3753c9 --- /dev/null +++ b/rc.d/rc.sysinit @@ -0,0 +1,212 @@ +#! /bin/sh +# +# /etc/rc.d/rc.sysinit - run once at boot time +# +# Taken in part from Miquel van Smoorenburg's bcheckrc. +# + +# Set the path +PATH=/bin:/sbin:/usr/bin:/usr/sbin +export PATH + +# Read in config data. +if [ -f /etc/sysconfig/network ]; then + . /etc/sysconfig/network +else + NETWORKING=no + HOSTNAME=localhost +fi + +# Start up swapping. +echo "Activating swap partitions" +swapon -a + +# Set the hostname. +hostname ${HOSTNAME} +echo hostname: `hostname` + +if [ ! -f /fastboot ]; then + echo "Checking root filesystems." + fsck -V -a / + + rc=$? + + # A return of 2 or higher means there were serious problems. + if [ $rc -gt 1 ]; then + echo + echo + echo "*** An error occurred during the file system check." + echo "*** Dropping you to a shell; the system will reboot" + echo "*** when you leave the shell." + + PS1="(Repair filesystem) #"; export PS1 + sulogin + + echo "Unmounting file systems" + umount -a + mount -n -o remount,ro / + echo "Automatic reboot in progress." + reboot + elif [ "$rc" = "1" -a -x /sbin/quotacheck ]; then + echo "Checking root filesystem quotas" + /sbin/quotacheck -v / + fi +fi + +if [ -x /sbin/quotaon ]; then + echo "Turning on user and group quotas for root filesystem" + /sbin/quotaon / +fi + +# Remount the root filesystem read-write. +echo "Remounting root filesystem in read-write mode." +mount -n -o remount,rw / + +if [ ! -f /etc/HOSTNAME ]; then + echo ${HOSTNAME} > /etc/HOSTNAME +fi + +# Clear mtab +>/etc/mtab + +# Enter root into mtab. +mount -f / + +# mount /proc +mount -t proc /proc /proc +if [ -f /proc/ksyms ]; then + USEMODULES=y +else + USEMODULES= +fi + +# we can't leave this mounted as it confuses "mount -a" later (dumb) +umount /proc + +if [ -x /sbin/depmod -a -n "$USEMODULES" ]; then + # Get ready for kerneld if module support in the kernel + echo -n "Finding module dependencies" + depmod -a + echo "" +fi + +if [ -x /sbin/kerneld -a -n "$USEMODULES" ]; then + /sbin/kerneld +fi + +# Check filesystems +if [ ! -f /fastboot ]; then + echo "Checking filesystems." + fsck -R -A -V -a + + # A return of 2 or higher means there were serious problems. + if [ $? -gt 1 ]; then + echo + echo + echo "*** An error occurred during the file system check." + echo "*** Dropping you to a shell; the system will reboot" + echo "*** when you leave the shell." + + PS1="(Repair filesystem) #"; export PS1 + sulogin + + echo "Unmounting file systems" + umount -a + mount -n -o remount,ro / + echo "Automatic reboot in progress." + reboot + elif [ "$rc" = "1" -a -x /sbin/quotacheck ]; then + echo "Checking filesystem quotas" + /sbin/quotacheck -v -R -a + fi +fi + +# Mount all other filesystems (except for NFS). Contrary to standard usage, +# filesystems are NOT unmounted in single user mode. +echo "Mounting local filesystems." + +mount -a -t nonfs + +if [ -x /sbin/quotaon ]; then + echo "Turning on user and group quotas for local filesystems" + /sbin/quotaon -a +fi + + +# Clean out /etc. +rm -f /etc/mtab~ /fastboot /etc/nologin +>/var/run/utmp + +# Delete UUCP lock files. +rm -f /var/lock/LCK* + +# Delete stale subsystem files. +rm -f /var/lock/subsys/* + +# Delete stale pid files +rm -f /var/run/*.pid + +# Delete X locks +rm -f /tmp/.X*-lock + +# Set the system clock. +echo -n "Setting clock" + +ARC=0 +UTC=0 +if [ -f /etc/sysconfig/clock ]; then + . /etc/sysconfig/clock + + # convert old style clock config to new values + if [ "${CLOCKMODE}" = "GMT" ]; then + UTC=true + elif [ "${CLOCKMODE}" = "ARC" ]; then + ARC=true + fi +fi + +CLOCKFLAGS="-a" +if [ $UTC = "true" ]; then + CLOCKFLAGS="$CLOCKFLAGS -u"; + echo -n " (utc)" +fi +if [ $ARC = "true" ]; then + CLOCKFLAGS="$CLOCKFLAGS -A"; + echo -n " (arc)" +fi +echo -n ": " +clock $CLOCKFLAGS + +date + +# Right, now turn on swap in case we swap to files. +echo "Enabling swap space." +swapon -a 2>&1 | grep -v "busy" + +# Initialize the serial ports. +if [ -f /etc/rc.d/rc.serial ]; then + . /etc/rc.d/rc.serial +fi + +# Load modules (for backward compatibility with VARs) +if [ -f /etc/rc.d/rc.modules ]; then + /etc/rc.d/rc.modules +fi + +# If a SCSI tape has been detected, load the st module unconditionally +# since many SCSI tapes don't deal well with st being loaded and unloaded +if cat /proc/scsi/scsi | grep -q 'Type: Sequential-Access' 2>/dev/null ; then + if cat /proc/devices | grep -qv ' 9 st' ; then + if [ -n "$USEMODULES" ] ; then + # Try to load the module. If it fails, ignore it... + modprobe st 2>/dev/null + fi + fi +fi + +# Now that we have all of our basic modules loaded and the kernel going, +# let's dump the syslog ring somewhere so we can find it later +dmesg > /var/log/dmesg + +# Feed entropy into the entropy pool +/etc/rc.d/init.d/random start -- cgit v1.2.1