System Service Control
1. System service control
System Service Control
systemctl, control type, service name
Control type
start: start
stop: stop
restart: restart (will interrupt the service)
reload: reload (will not interrupt the service)
status: view service status
enable: self-start at boot
disable disable boot
2. Start and control system services 2-1
ntsysv system service management tool
1. ntsysv
can press the up and down keys to select the service, the space key to select whether to start the service automatically, the Tab key to select confirm or cancel
2. ntsysv --level level list
Note: According to the default setting, only the current run level will be set. To configure different run levels, use the "-level" option to specify one or more run levels, for example: command "ntsysv --level 3 4 5" to configure the run
Start and control of level 3, 4 and 5 system services 2-2
1. Check the startup status of system services
systemctl is-enable service name
2. Set the startup status of the system service
systemctl enable/disable service name
Three, the difference between ntsysv tool and systemctl tool
1. The ntsysv tool
① provides an interactive and visual window
② It can be run on a character terminal
③ It is convenient for centralized management of multiple services
2. The systemctl tool
① Does not provide an interactive, visual window
② It is more efficient to manage a single service
Fourth, view the default run level of the system
systemctl get-default
5. Switch the current run level without restarting the machine: isolate is used to switch the current run level
1. Systemctl isolate graphical.target graphical interface
2. Systemctl isolate multi-user.target character interface
Six, view the current run level
1、runlevel
3 is the character interface refers to the previous run level, 5 is the graphical interface refers to the current run level
2, who -r
3 is the character interface refers to the previous run level, 5 is the graphical interface refers to the current run level
Seven, modify the default run level
1、systemctl set-default multi-user.target
2. rm /etc/systemd/system/default.target
ln -s /usr/lib/systemd/system/multi-user.target /etc/systemd/system/default.target
delete the target file of the link and create a soft link
Both of the above methods need to be restarted to take effect
8. Analyze the dependencies between the units of the specified target
systemctl list-dependencies multi-user.target
Note: The dots in front of each service, green means running, red means not running
Nine, check which targets refer to the targets of the current run level
systemctl list-dependencies multi-user.target --reverse
10. List all targets included in the system
systemctl list-unit-files --type=target
11. List unit items
1. List all active units
systemctl list-units
2. List all units, including inactive
systemctl list-units --all
3. List all the units that are not running, that is, the inactive
systemctl list-units --all --state=inactive
4. List all units in the current active state (active)
systemctl list-units --type=service
5. List all service units in all states (including active and inactive)
systemctl list-units --type=service --all
6. List all unit files, note: here is whether to enable
systemctl list-unit-files
static: The configuration file has no [Install] part (cannot be executed), and can only be used as a dependency of other configuration files.
Masked: The configuration file is forbidden to establish startup links.
7. List the units that a service depends on
systemctl list-dependencies firewalld.service
8. View the unit file
systemctl cat openresty.service
9. Reload all modified unit files
Systemctl daemon-reload