Книга: Fedora™ Unleashed, 2008 edition
Understanding init Scripts and the Final Stage of Initialization
Understanding init
Scripts and the Final Stage of Initialization
Each /etc/rc.d/init.d
script, or init
script, contains logic that determines what to do when receiving a start or stop value. The logic might be a simple switch statement for execution, as in this example:
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
reload)
reload
;;
status)
rhstatus
;;
condrestart)
[ -f /var/lock/subsys/smb ] && restart || :
;;
*)
echo $"Usage: $0 {start|stop|restart|status|condrestart}"
exit 1
esac
Although the scripts can be used to customize the way that the system runs from power- on, absent the replacement of the kernel, this script approach also means that the system does not have to be halted in total to start, stop, upgrade, or install new services.
Note that not all scripts use this approach, and that other messages might be passed to the service script, such as restart
, reload
, or status
. Also, not all scripts respond to the same set of messages (with the exception of start
and stop
, which they all have to accept by convention) because each service might require special commands.
TIP
You can write your own init
scripts, using the existing scripts as examples. Sample scripts can also be found in /usr/share/doc/initscripts/sysvinitfiles,
along with a brief tutorial written by Red Hat and a brief explanation of all the options available to use in init
scripts.
After all the system scripts have been run, your system is configured and all the necessary system services have been started. If you are using a runlevel other than 5, the final act of the init
process is to launch the user shell, which on Linux is nearly always bash
. The shell launches and you see a login prompt on the screen.
- Beginning the Boot Loading Process
- Loading the Linux Kernel
- System Services and Runlevels
- Runlevel Definitions
- Booting into the Default Runlevel
- Booting to a Nondefault Runlevel with GRUB
- Understanding init Scripts and the Final Stage of Initialization
- Controlling Services at Boot with Administrative Tools
- Running Services Through xinetd
- Changing Runlevels
- System Services and Runlevels
- Understanding Generics
- 7.13. Директива final
- Разработка приложений баз данных InterBase на Borland Delphi
- 4.4.4 The Dispatcher
- Open Source Insight and Discussion
- 3.3.4 init.c
- Introduction to Microprocessors and Microcontrollers
- About the author
- Chapter 6. Traversing of tables and chains
- Chapter 7. The state machine
- Chapter 8. Saving and restoring large rule-sets