<< First Page    < Previous Page    Next Page >    Last Page >>

5.2) Services and startup scripts

 

Linux developers use sysV boot method. The system can boot to one of 6 "run-levels":

  0 - halt (Do NOT set initdefault to this)

  1 - Single user mode

  2 - Multiuser, without NFS (The same as 3, if you do not have networking)

  3 - Full multiuser mode

  4 - unused

  5 - X11

  6 - reboot (Do NOT set initdefault to this)

 

The startup scripts are all located in /etc/rc.d/init.d and accept one parameter of this group: start; stop; restart. Sometimes there are more parameters, but they are script specific.

In /etc/rc.d/rc*.d/ (where * is runlevel number) there are symbolic links (like shortcut, but in filesystem) to these scripts, starting with "S" or "K" and a number. The startup script checks what run-level the system is booting to, and will execute any script which starts with S in the appropriate directory as '<script> start' in the order set by the numbers (01 will run before 28, for example). Thus, adding a service to the startup sequence means only to symlink it with an appropriate name (starting with S and a number), and next reboot or runlevel change, it will load, and vice versa. This simplifies service running, and allows an easy usage of existing programs as services (and program can run like a service) all by script writing.