Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to manage systemd Services in Linux system

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article focuses on "how to manage systemd services in the Linux system". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn "how to manage systemd services in the Linux system"!

(1) what is a unit

Before RHEL7, service management was distributed and managed by SysV init or UpStart through scripts under / etc/rc.d/init.d. These scripts are classic Bash scripts that allow administrators to control the status of the service. In RHEL7, these scripts are replaced by service unit files.

In systemd, resources such as services and mounts are called units, so there are many unit types in systemd. The extension of the service unit file is .service, which is similar to the function of scripts. For example, there are parameters to view, start, stop, restart, enable or disable services.

Location of systemd unit files:

/ usr/lib/systemd/system/systemd default unit file installation directory

/ run/systemd/systemsystemdsystemd unit is created at run time, and this directory takes precedence over by directory

/ etc/systemd/system system administrator creates and manages the unit directory with the highest priority.

(2) Service management of systemd

The service can be controlled using the systemcl command, and the service and chkconfig commands can still be used, but mainly for compatibility reasons and should be avoided as much as possible.

When using the systemctl command, the extension of the service name can be fully written, for example:

The code is as follows:

Systemctl stop bluuetooth.service

It can also be ignored, for example:

The code is as follows:

Systemctl stop bluetooth

Common systemctl commands:

Start the service

The code is as follows:

Systemctl start name.service

Shut down the service

The code is as follows:

Systemctl stop name.service

Restart the service

The code is as follows:

Systemctl restar tname.service

Restart the service only when the service is running

The code is as follows:

Systemctl try-restart name.service

Reload the service profile

The code is as follows:

Systemctl relaod name.service

Check the service operation status

The code is as follows:

Systemctl status name.service

Or

The code is as follows:

Systemctl is-active\ name.service

Show all service status details

The code is as follows:

Systemctl list-units--type service-all

Allow the service to boot

The code is as follows:

Systemctl enable name.service

Disable service startup

The code is as follows:

Systemclt disable name.service

Check the service boot status

The code is as follows:

Systemctl status name.service

Or

The code is as follows:

Systemctl\

Is-enabled name.service

List all services and check to see if they start up

The code is as follows:

Systemctl list-unit-files-type service

(3) View service details

Use the following command to list services:

The code is as follows:

Systemctl list-units-type service

Only active services are listed by default, and if you want to see all the services, use the-- all or-a parameter:

The code is as follows:

Systemctl list-units--type service-all

Sometimes, if you want to see it, you can set the service to be started by using the following command:

The code is as follows:

Systemctl list-unit-files-type service

To view the service details, use the following command:

The code is as follows:

Systemctl status name.service

Keyword interpretation of service information

The Loaded service has been loaded, showing the absolute path of the unit file, and marking that the unit file is available.

The Active service is already running and has startup time information.

Main PID is the same as the PID of the process name, the main process PID.

Attachment information for the Status service.

Attachment information for Process-related processes.

CGroup information for the CGroup process.

At this point, I believe you have a deeper understanding of "how to manage systemd services in the Linux system". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report