System Service Control under Linux

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
Insert picture description here
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

Insert picture description here

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
Insert picture description here

2. Set the startup status of the system service
systemctl enable/disable service name
Insert picture description here

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
Insert picture description here

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
Insert picture description here
Insert picture description here

2. Systemctl isolate multi-user.target character interface
Insert picture description here
Insert picture description here

Six, view the current run level

1、runlevel
Insert picture description here

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
Insert picture description here

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
Insert picture description here

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
Insert picture description here

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
Insert picture description here

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
Insert picture description here

10. List all targets included in the system

systemctl list-unit-files --type=target
Insert picture description here

11. List unit items

1. List all active units
systemctl list-units
Insert picture description here

2. List all units, including inactive
systemctl list-units --all
Insert picture description here

3. List all the units that are not running, that is, the inactive
systemctl list-units --all --state=inactive
Insert picture description here

4. List all units in the current active state (active)
systemctl list-units --type=service
Insert picture description here

5. List all service units in all states (including active and inactive)
systemctl list-units --type=service --all
Insert picture description here

6. List all unit files, note: here is whether to enable
systemctl list-unit-files
Insert picture description here

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
Insert picture description here

8. View the unit file
systemctl cat openresty.service
Insert picture description here

9. Reload all modified unit files
Systemctl daemon-reload
Insert picture description here

Guess you like

Origin blog.csdn.net/yuiLan0/article/details/108323917