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 ++++++++++ 8 files changed, 422 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 (limited to 'rc.d/init.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 + -- cgit v1.2.1