14---Services for Linux Systems management

Source: Internet
Author: User
Tags stop script


One, Inittab document detailed

(a) The Inittab document detailed:



# 0-halt (do not set Initdefault to this)//stop, shut down Linux, stop all services
# 1-single User mode//single user modes
# 2-multiuser, without NFS//multi-user mode, no NFS access
# 3-full Multiuser mode//multi-user mode, start the network monitoring on the computer
# 4-unused//Reservation not defined
# 5-x11//Graphics login
# 6-reboot (do not set Initdefault to this)//restart



Id:3:initdefault://Set the default operating level of the system, here is 3.


REDHAT5 the following content, REDHAT6 will not have the following content, but the implementation of the same functionality.
# System initialization.
Si::sysinit:/etc/rc.d/rc.sysinit//through the Sysinit system initialization, this is bound to run.


L0:0:WAIT:/ETC/RC.D/RC 0//corresponds to each level defined above. Here is the script and program that runs when you select Level 0. The running script is stored in the/ETC/RC.D/RC0.D directory.
L1:1:WAIT:/ETC/RC.D/RC Run script at 1//1 level. All scripts starting with the s in the/ETC/RC.D/RC1.D directory will be started and all scripts starting with K stopped. The following levels are analogous.
L2:2:WAIT:/ETC/RC.D/RC 2
L3:3:WAIT:/ETC/RC.D/RC 3
L4:4:WAIT:/ETC/RC.D/RC 4
L5:5:WAIT:/ETC/RC.D/RC 5
L6:6:WAIT:/ETC/RC.D/RC 6



# Trap Ctrl-alt-delete
Ca::ctrlaltdel:/sbin/shutdown-t3-r Now//define the restart key. If commented out, then pressing Ctrlaltdel three keys will not restart.


1:2345:respawn:/sbin/mingetty tty1
2:2345:respawn:/sbin/mingetty Tty2
3:2345:respawn:/sbin/mingetty Tty3
4:2345:respawn:/sbin/mingetty Tty4
5:2345:respawn:/sbin/mingetty Tty5
6:2345:respawn:/sbin/mingetty Tty6
This indicates that the system will start several virtual consoles by default and can be toggled by CTRL + Alt + F1~F6.
The second column of 2345 indicates that they will run at these four levels
The respawn, however, indicates that the command will always be called. The most common example is that in a shell environment, we enter exit to exit the environment, but then a login prompt waits for the new user to log in.
Six virtual consoles are set up here, so if you don't need that much, you can get rid of the extra comments.





Two
/etc/inittab's Mission:

1. Set the default operating level
2. Run the system initialization script/etc/rc.d/rc.sysint
3. Run the script in the directory corresponding to the specified run level
4, set the operation of Ctrl+alt+del key combination
5, define the UPS power supply in the power, the operation performed when the recovery
6. Start the virtual terminal
7, start the diagram open terminal.



Second,/etc/rc.d/rc.sysinit script to complete the task:

1. Activate Udev and SELinux
2, according to the/etc/sysctl.conf file to set the kernel parameters
3. Set the clock
4. Load Keyboard mapping
5. Enable swap partition
6. Set Host name
7. root file system detection and re-mount with read and write text
8. Activating RAID and LVM devices
9. Enable disk quotas
10. Check and mount other file systems
11. Purge expired locks and PID files

Third, the corresponding level of the script
Execute the/etc/rc.d/rc.sysinit script first
Executes the specified level of script again

/ETC/RC.D/RC#.D//In the directory with the corresponding execution level in the/etc/rc.d/directory, that is, the number of choices, execute the script and service under the corresponding directory.

K*: The script starting with K is stopped. That is stop
s* scripts that begin with s are started, that is, start

Iv. Description of the service class script

1, Redhat script is adopted SYSV style
2,/ETC/RC.D/INIT.D and/ETC/INIT.D//service class scripts are in both directories, in fact, the two directories are the same, the latter is a link to the previous directory.

3, the Service class script format detailed:
Cases:
#chkconfig: 2345 25 10

The first group sets the default boot level, which indicates that the service script is started at level 2,345. The second set of SS, that is, 25, is the priority of the start of the third group: KK, which is 10 off the priority order. SS+KK two sets of numbers are roughly equal to 99.

#description: Startup/shutdown script for the Common UNIX \
# Printing System (CUPS).
Describe the simple function of the script, and use \ to continue the line.



Start |stop |restart|status//Each service script has at least these four parameters
Reload|configtest//Optional parameters



V. Use of the Chkconfig command:

1, write the script first, then put it under/ETC/RC.D/INIT.D, and then execute the chkconfig command can be added to the service script, that is, you can define whether the script is running, or not running, at which level to run. You can also delete a script that has been added to the service script.
The Chkconfig command is primarily used to update (start or stop) and query run-level information for system services. Keep in mind that Chkconfig does not immediately automatically disable or activate a service, it simply changes the symbolic connection.

2. Use syntax:
chkconfig [--add][--del][--list][system service] or Chkconfig [--level < class Code >][system service][on/off/reset]

Chkconfig Displays the usage when no parameters are running. If the service name is added, check that the service is started at the current run level. If yes, returns TRUE, otherwise false is returned. If On,off or reset is specified after the service name, CHKCONFI will change the startup information for the specified service. On and off refers to the service being started and stopped, and reset refers to the boot information of the reset service, regardless of what is specified by the problematic initialization script. On and off switches, the system is only valid for run-level 3,4,5 by default, but reset can be valid for all run levels.

Parameter usage:
--add adds the specified system service, allows the CHKCONFIG directive to manage it, and adds relevant data to the system-initiated narrative file.
--del deletes the specified system service, is no longer managed by the Chkconfig directive, and deletes the relevant data within the system-initiated narrative file.
--level< Class code > Specify which execution level the system service should be opened or closed.
Level 0 means: shutdown
Level 1 means: Single user mode
Level 2: Multi-user command line mode with no network connection
Level 3 means: Multi-user command line mode with network connection
Level 4 means: not available
Level 5 means: Multi-user mode with graphical interface
Level 6 means: reboot
It is necessary to note that the level option can specify the run levels to view and not necessarily the current run level. For each run level, there can be only one startup script or stop script. When you switch the run level, Init does not restart the service that is already started, nor does it stop the service that has stopped.

Chkconfig--list [name]: Displays the health status information (on or off) of all run-level system services. If name is specified, only the state of the specified service at a different run level is displayed.
Chkconfig--add Name: Add a new service. Chkconfig ensure that each run level has a start (S) or Kill (K) entry. If one is missing, it is automatically created from the default init script.
Chkconfig--del Name: Deletes the service and removes the associated symbolic connection from the/ETC/RC[0-6].D.
Chkconfig [--level Levels] Name: Sets whether a service is started, stopped, or reset at the specified run level.

Run-level files:
Each service managed by Chkconfig needs to add two or more lines of comments to the script under the corresponding INIT.D. The first line tells Chkconfig the run level of the default startup and the priority of start and stop. If a service does not start at any run level by default, use-instead of run-level. The second line describes the service, which you can annotate with \ cross-line.
For example, Random.init contains three rows:
# chkconfig:2345 20 80
# description:saves and restores system entropy pool for \
# higher quality random number generation.

Examples of Use:
Chkconfig--list #列出所有的系统服务
Chkconfig--add httpd #增加httpd服务
Chkconfig--del httpd #删除httpd服务
Chkconfig--level httpd 2345 on #设置httpd在运行级别为2, 3, 4, 5 in the case of On (open) state
Chkconfig--list #列出系统所有的服务启动情况
Chkconfig--list mysqld #列出mysqld服务设置情况
Chkconfig--level mysqld on #设定mysqld在等级3和5为开机运行服务,--level 35 means that the operation is performed only on levels 3 and 5, on means start, off means off
Chkconfig mysqld on #设定mysqld在各等级为on, "each level" includes 2, 3, 4, 5 ratings

Cases:
How to add a service:
1. The service script must be stored in the/etc/init.d/directory;
2.chkconfig--add servicename//add a script to the service script without specifying a run level default is 2345
Add this service to the list of Chkconfig tool services, at which point the service is given the k/s entry in/ETC/RC.D/RC#.D;
3.chkconfig--level mysqld on
Modifies the default startup level of the service.



Note: In a directory such as/etc/rc.d/rc#.d/, there is finally a s99local script that is actually linked to/etc/rc.d/rc.local, which is the last script to run. You can write the command you want to run in this script to start the execution.




Vi. Daemon Type:

Independent Daemon Process

Transient daemon: xinetd: Super Daemon, responsible for the management of the transient daemon process. You do not need to associate to the RunLevel. The default is not installed.

This article is from the "Network Line World" blog, please make sure to keep this source http://kuangkuang.blog.51cto.com/838/1686942

14---Services for Linux Systems management

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.