Книга: 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.

Оглавление книги


Генерация: 2.284. Запросов К БД/Cache: 3 / 0
поделиться
Вверх Вниз