Previous Page | Next Page

  1. Introduction
  2. Boot Process
  3. Init and System Initialization
  4. rc.sysinit script
  5. rc script
  6. functions script
  7. Services
  8. apm daemon
  9. network startup
  10. The network script file
  11. The network-functions file
  12. Portmap startup
  13. Random initialization
  14. Syslog initialization
  15. Gated
  16. Atd
  17. cron initialization
  18. pcmcia
  19. inetd daemon
  20. named daemon
  21. lpd daemon
  22. mars-nwe
  23. netfs startup
  24. dhcpd daemon
  25. autofs daemon
  26. keytable daemon
  27. sendmail daemon
  28. gpm daemon
  29. httpd daemon
  30. xfs startup
  31. smb startup
  32. innd startup
  33. linuxconf startup
  34. rc.local script
  35. Init, Getty, Login
  36. The shell
  37. Shutting down
  38. X
  39. Conclusions
  40. App A. rc.sysinit listing
  41. App B. functions listing
  42. App C. rc listing
  43. Credits

Appendix C

Linux /etc/rc.d/rc script program listing

1	#!/bin/bash
2	#
3	# rc            This file is responsible for starting/stopping
4	#               services when the runlevel changes. It is also
5	#               responsible for the very first setup of basic
6	#               things, such as setting the hostname.
7	#
8	# Original Author:       
9	#               Miquel van Smoorenburg, <miquels@drinkel.nl.mugnet.org>
10	#
11	
12	# Source function library.
13	. /etc/rc.d/init.d/functions
14	
15	# Now find out what the current and what the previous runlevel are.
16	argv1="$1"
17	set `/sbin/runlevel`
18	runlevel=$2
19	previous=$1
20	export runlevel previous
21	
22	# See if we want to be in user confirmation mode
23	if [ "$previous" = "N" ]; then
24	    if grep -i confirm /proc/cmdline >/dev/null ; then
25	      CONFIRM=yes
26	    else
27	      CONFIRM=
28	    fi
29	fi
30	
31	# Get first argument. Set new runlevel to this argument.
32	[ "$1" != "" ] && runlevel="$argv1"
33	
34	# Tell linuxconf what runlevel we are in
35	[ -d /var/run ] && echo "/etc/rc.d/rc$runlevel.d" > /var/run/runlevel.dir
36	
37	# Is there an rc directory for this new runlevel?
38	if [ -d /etc/rc.d/rc$runlevel.d ]; then
39		# First, run the KILL scripts.
40		for i in /etc/rc.d/rc$runlevel.d/K*; do
41			# Check if the script is there.
42			[ ! -f $i ] && continue
43	
44			# Don't run [KS]??foo.{rpmsave,rpmorig} scripts
45			[ "${i%.rpmsave}" != "${i}" ] && continue
46			[ "${i%.rpmorig}" != "${i}" ] && continue
47			[ "${i%.rpmnew}" != "${i}" ] && continue
48	
49			# Check if the subsystem is already up.
50			subsys=${i#/etc/rc.d/rc$runlevel.d/K??}
51			[ ! -f /var/lock/subsys/$subsys ] && \
52			    [ ! -f /var/lock/subsys/${subsys}.init ] && continue
53
54			# Bring the subsystem down.
55			if egrep -q "(killproc |action )" $i ; then
56				$i stop
57			else
58				action "Stopping $subsys" $i stop
59			fi
60		done
61	
62		# Now run the START scripts.
63		for i in /etc/rc.d/rc$runlevel.d/S*; do
64			# Check if the script is there.
65			[ ! -f $i ] && continue
66	
67			# Don't run [KS]??foo.{rpmsave,rpmorig} scripts
68			[ "${i%.rpmsave}" != "${i}" ] && continue
69			[ "${i%.rpmorig}" != "${i}" ] && continue
70			[ "${i%.rpmnew}" != "${i}" ] && continue
71
72			# Check if the subsystem is already up.
73			subsys=${i#/etc/rc.d/rc$runlevel.d/S??}
74			[ -f /var/lock/subsys/$subsys ] || \
75			    [ -f /var/lock/subsys/${subsys}.init ] && continue
76			    
77			# If we're in confirmation mode, get user confirmation
78			[ -n "$CONFIRM" ]  && 
79			  { 
80			    confirm $subsys
81			    case $? in
82			      0)
83			        :
84			      ;;
85			      2)
86			        CONFIRM=
87			      ;;
88			      *)
89			        continue
90			      ;;
91			    esac 
92			  }
93	
94			# Bring the subsystem up.
95			if egrep -q "(daemon |action )" $i ; then
96				$i start
97			else
98				if [ "$subsys" = "halt" -o "$subsys" = "reboot" -o "$subsys" = "single" ]; then
99				    $i start
100				else
101				    action "Starting $subsys" $i start
102				fi
103			fi
104		done
105	fi