3. Run-level scripting introduction
3.1. Operating level
Operating level Description:
0 Turn off the machine
1 Single-User mode
2 Multi-user mode, no NFS service
3 Multi-user mode
4 not currently used
5 X startup mode for Windows
6 Restart your computer
The directory that corresponds to the run level (/etc/rcn.d,n is the number 0, 1, 2 ...)
Current Run level
Get current RunLevel with RunLevel directory (RunLevel starting from 0)
Run-level catalog file format (x is Arabic, script is the name of the scripts)
Sxxscript
Indicates that the service for this script is started under this RunLevel
Kxxscript
Indicates that the service for this script is not started under this RunLevel
For example, in the/etc/rc5.d file with LS View inside the file,
There are k01kdcrotate, k15httpd, S80isc ... File
These files are hyperlinked files, linked to the corresponding files under/etc/init.d/, such as k01kdcrotate link file corresponding to/etc/init.d/kdcrotate file below; S80isc link file corresponds to/etc/init.d/ The ISC file below
Order of starting Services
3.2.inittab Boot file
Run level Control file (/etc/inittab)
This file is a script that is executed when the Linux system starts
Edit the Inittab file (use the Vim/etc/inittab command to open the file)
Example: Add a statement to the Inittab file to allow the system to execute a shell script file that checks the system disk when it starts checkdisk.sh
checkdisk::once:/sbin/checkdisk.sh >/dev/console 2>&1 indicates that this command is executed at each runlevel, if it is to be developed at the third run level: Checkdisk:3:o nce:/sbin/checkdisk.sh >/dev/console 2>&1
3.3. Launch the application. Start the application automatically by using a boot script, no more manual boot
startup script Analysis (Start|stop|restart)
Cat/etc/init.d/crond
Take the MySQL application as an example
MySQL has its own mysqld script file, when installing the MySQL application, put mysqld into the/etc/init.d/directory, and then under the corresponding operating level to do the corresponding kxxscript or sxxscript named format of hyperlinks
Startup scripts
Method 1:service Server start|stop|restart| ... server refers to the name of the script
Example
Service Mysald Start
Method 2:script_name Start|stop|restart
How to create your own startup scripts (you can use such a method, such as to start your own C application)
1. Create your own startup script file under the/etc/init.d/directory, and see the syntax format of the startup script file below/etc/init.d/to write your own startup script
2. In the/etc/rcn.d/directory, that is to create a link to the corresponding startup script in Sxxscript or kxxscript format at the corresponding RunLevel
Linux Shell Advanced Programming Tips 3----Run Level scripting Introduction