home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1999 March B / SCO_CASTOR4RRT.iso / base / root.15 / etc / init.d / README / README~
Text File  |  1998-08-19  |  5KB  |  127 lines

  1. #ident    "@(#)initpkg:common/cmd/initpkg/init.d/README    1.4.5.3"
  2. #ident "$Header: /sms/sinixV5.4es/rcs/s19-full/usr/src/cmd/initpkg/init.d/README,v 1.1 91/02/28 17:36:40 ccs Exp $"
  3.  
  4. SEE THE NOTES ON EFFICIENCY AT THE END OF THIS FILE.
  5.  
  6. /etc/init.d contains initialization and termination scripts for changing
  7. init states.  These scripts are linked when appropriate to files in the
  8. rc?.d and dinit.d directories.  File names in these directories are
  9. of the form [SK]nn<init.d filename> where 'S' means start this job, 'K'
  10. means kill this job, and 'nn' is the relative sequence number for
  11. killing or starting the job.  When entering a state (init 0,2,3,etc.)
  12. the rc[0-6] command executes those scripts in /etc/rc[0-6].d that are 
  13. prefixed with 'K' followed by those scripts prefixed with 'S'.
  14. The dinit command processes the scripts in dinit.d in a similar
  15. way, and runs in the background on entering multiuser state.  This
  16. is an attempt to provide a login prompt as early as feasible.
  17.  
  18. EXAMPLE: When changing to init state 2 (default multi-user mode),
  19.     /sbin/rc2 is initiated by the init process. The following
  20.     steps are performed by /sbin/rc2.
  21.  
  22.     1. In the directory /etc/rc2.d are files used to stop processes 
  23.     that should not be running in state 2.  The filenames
  24.     are prefixed with 'K'.  Each 'K'  file in the directory is
  25.     executed (by /sbin/rc2) in alpha-numeric order when the system 
  26.     enters init state 2.  (see example under next item).
  27.  
  28.     2. Also in the rc2.d directory are files used to start
  29.     processes that should be running in state 2.  As in the step
  30.     above, each 'S' file is executed.
  31.  
  32.     Example:
  33.  
  34.         The file /etc/netdaemon is a script that will initiate
  35.         networking daemons when given the argument 'start',
  36.         and will terminate the daemons if given the argumant
  37.         'stop'.  It is linked to /etc/rc2.d/S68netdaemon,
  38.         and to /etc/rc0.d/K67netdaemon.  The file is executed
  39.         by '/etc/rc2.d/S68netdaemon start' when init state 2
  40.         is entered and by '/etc/rc0.d/S67netdaemon stop' when
  41.         shutting the system down.  (But see the NOTES ON
  42.         EFFECIENCY BELOW.)
  43.  
  44. NOTE:
  45. /sbin/rc2 has references to the obsolescent 'rc.d' directory.  These
  46. references are for compatibility with old INSTALL scripts. New
  47. INSTALL scripts should use the init.d directory for related executables.
  48. The same is true for the shutdown.d directory.
  49.  
  50. NOTES ON EFFICIENCY:
  51.  
  52. Boot and shutdown performance are interesting to a large class of users.
  53. These notes give some hints for providing efficient /etc/init.d
  54. scripts, which are critical to fast boot/shutdown.  The rc? and dinit
  55. commands are assumed to be run only by shutdown and init.  This makes
  56. several optimizations possible in the /etc/init.d scripts.
  57.  
  58. It is easy to recognize "normal" boot from power off or firmware to
  59. multiuser; "normal" shutdown from multiuser to power off or firmware;
  60. and administrative shutdown to run state 1.  The rc? and dinit commands
  61. put enough information in the environment for the rc?.d scripts to avoid
  62. running who and ps to try to figure out how much work to do.
  63.  
  64.     _AUTOBOOT - If this string is nonzero in the environment,
  65.     the system is going multiuser for the first time.  An
  66.     rc[23].d/S* link is free to assume that none of its startup
  67.     work has yet been done, and therefore does not have to run
  68.     ps, for example, to see if daemons have already been started.
  69.  
  70.     Example:
  71.  
  72.     start )
  73.  
  74.     pid=
  75.     if [ -z "$_AUTOBOOT" ]
  76.     then
  77.         set -- `ps -e | grep ' daemon$'`
  78.         [ $? -eq 0 ] && pid=$1
  79.     fi
  80.     if [ -z "$pid" ]
  81.     then
  82.         daemon&
  83.     fi
  84.  
  85.     _AUTOKILL - If this string is nonzero in the environment, the
  86.     system is either (1) going down to firmware or power off, or
  87.     (2) going to run level 1.  In either case the rc? script will
  88.     issue a killall -9 after running the rc[10].d/K* scripts.
  89.     This implies that rc[10].d/K* scripts need not and should not
  90.     issue a kill -9 to their daemons, and usually need not
  91.     explicitly tear down protocol stacks, etc.  In fact, except
  92.     for packages that monitor daemons that write administrative
  93.     databases, e.g., keymaster and lp, few init.d scripts need
  94.     links to rc[01].d.
  95.  
  96.     Example:
  97.  
  98.     stop )
  99.     if [ -n "$_AUTOKILL" ]
  100.     then
  101.         exit 0
  102.     fi
  103.     pid=
  104.     set -- `ps -e | egrep ' daemon$'`
  105.     [ $? -eq 0 ] && pid=$1
  106.     if [ -n "$pid" ]
  107.     then
  108.         kill -9 $pid 2>/dev/null
  109.     fi
  110.  
  111.     _CURR_RL, _CURR_NTIMES, _PREV_RL - These are put into the
  112.     environment for scripts that need more information than
  113.     encoded _AUTOBOOT and _AUTOKILL.  This will not be the
  114.     case for most well-written scripts.
  115.  
  116.         _CURR_RL - The current run-level.
  117.  
  118.         _CURR_NTIMES - The number of times the current run-level
  119.         was previously entered.
  120.  
  121.         _PREV_RL - The previous run level.
  122.  
  123. Something that bears emphasizing:  Most init.d scripts do not need rc0.d/K
  124. or rc1.d/K entries unless exceptional cleanup is needed, because rc0 and
  125. rc1 issue killall -9 commands.  Keeping rc[01].d small improves the
  126. possibilities for quick shutdown.
  127.