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

What is the method of modifying the existing systemd unit file under the Linux system

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

Share

Shulou(Shulou.com)05/31 Report--

This article analyzes "what is the method of modifying existing systemd unit files in Linux system". The content is detailed and easy to understand, and friends who are interested in "what is the method of modifying existing systemd unit files under the Linux system" can follow the editor's train of thought to read it slowly and deeply. I hope it will be helpful to you after reading. Let's follow the editor to learn more about "what is the method of modifying existing systemd unit files under the Linux system".

We will show how to modify an existing cell file under the Linux system, such as what a cell file is, extend the default cell configuration, and overwrite the default cell configuration.

Preface

There are three main directories for storing unit files on the system, but the "/ etc/systemd/system/" directory is reserved for unit files created or customized by the system administrator.

1. / usr/lib/systemd/system/: the systemd unit file that is deleted when installing the package.

2. / systemd unit file created by run/systemd/system/: at run time.

3. / etc/systemd/system/: systemd unit files created by the "systemctl enable" command and unit files added to extend the service.

Reference: methods for creating custom scripts and systemd service unit files in Linux.

What is a unit file?

The unit file contains configuration instructions that describe the unit and define its behavior. Several systemctl commands process the unit file in the background to make the unit file run as expected.

Unit files use the following general syntax:

Unit_name.type_extension

Httpd.service

1. Unit_name (httpd) stands for the name of the unit.

2. Type_extension (service) identifies the unit type.

To demonstrate this, we add the following two parameters to the "httpd.service" file:

Restart=on-failure

RestartSec=5s

You can modify an existing systemd unit file in two ways:

1. Extend the default unit configuration.

2. Override the default unit configuration.

1. Extend the default unit configuration

This section describes how to extend the default cell file with other configuration options.

For example, to edit the "httpd.service" unit file, run:

$sudo systemctl edit httpd.service

This creates an overlay fragment file under "/ etc/systemd/system/httpd.service.d/override.conf" and opens it in your text editor. Add new parameters to the httpd.service unit file, and when you save the file, the new parameters are added to the existing service file.

To apply the changes made to the cell, execute:

$sudo systemctl daemon-reload

Restart the httpd service to load the new service configuration (if you modify the running unit file, you must redeclare the unit file):

$sudo systemctl restart httpd

To undo the changes, perform the following steps.

To delete a clip, run:

$sudo rm-r / etc/systemd/system/httpd.service.d

To apply changes to unit files without restarting the system, execute the "daemon-reload" option to reload all unit files and recreate the entire dependency tree:

$sudo systemctl daemon-reload

To check the extended or modified unit file, run the following command output to clearly indicate that the file "apache2.service" has been extended:

$systemd-delta [EQUIVALENT] / etc/systemd/system/default.target → / usr/lib/systemd/system/default.target [OVERRIDDEN] / etc/systemd/system/sshd.service → / usr/lib/systemd/system/sshd.serviceFiles / usr/lib/systemd/system/sshd.service and / etc/systemd/system/sshd.service are identical [EXTENDED] / usr/lib/systemd/system/NetworkManager.service → / usr/lib/systemd/system/NetworkManager.service.d/NetworkManager -ovs.conf [EXTENDED] / usr/lib/systemd/system/apache2.service → / etc/systemd/system/apache2.service.d/override.conf [EXTENDED] / usr/lib/systemd/system/btrfs-balance.timer → / etc/systemd/system/btrfs-balance.timer.d/schedule.conf [EXTENDED] / usr/lib/systemd/system/btrfs-scrub.timer → / etc/systemd/system/btrfs-scrub.timer.d/schedule.conf [EXTENDED] / usr/lib/systemd/system/nfs-client.target → / usr/lib/systemd/system/nfs-client.target.d/nfs.conf [EXTENDED] / usr/lib/systemd/system/rpc-gssd.service → / usr/lib/systemd/system/rpc-gssd.service.d/options.conf [EXTENDED] / usr/lib/systemd/system/rpc-statd-notify.service → / usr/lib/systemd/system/rpc-statd-notify.service.d / options.conf [EXTENDED] / usr/lib/systemd/system/rpc-statd.service → / usr/lib/systemd/system/rpc-statd.service.d/options.conf [EXTENDED] / usr/lib/systemd/system/rpc-svcgssd.service → / usr/lib/systemd/system/rpc-svcgssd.service.d/options.conf [EXTENDED] / usr/lib/systemd/system/systemd-sysctl.service → / usr/lib/systemd/system/systemd-sysctl. Service.d/50-kernel-uname_r.conf12 overridden configuration files found.

2. Override the default unit configuration

This section describes how to override the default cell configuration.

If you want to keep the changes after updating the package that provides the unit file, edit the complete cell file as follows:

$sudo systemctl edit-full httpd.service

This loads the current cell file into the editor. After saving the file, systemctl will create a file at "/ etc/systemd/system/httpd.service".

To apply the changes made to the cell, execute:

$sudo systemctl daemon-reload

Restart the httpd service to load the new service configuration (if you modify the running unit file, you must redeclare the unit file):

$sudo systemctl restart httpd

Note that any unit file in "/ etc/systemd/system" will overwrite the corresponding file in "/ lib/systemd/system".

To restore the changes or return to the default configuration of the device, delete the following custom configuration file.

To delete the complete modification unit file, run:

$sudo rm / etc/systemd/system/httpd.service

To apply changes to unit files without restarting the system, execute the "daemon-reload" option to reload all unit files and recreate the entire dependency tree:

$sudo systemctl daemon-reload

To check for overwritten or modified unit files, run the following command to clearly show that the file "apache2.service" has been overwritten:

$systemd-delta [OVERRIDDEN] / etc/systemd/system/apache2.service → / usr/lib/systemd/system/apache2.service--- / usr/lib/systemd/system/apache2.service 2021-07-08 22 systemd-delta 20 OVERRIDDEN 27.000000000 + 0530 WantedBy=multi-user.target + / etc/systemd/system/apache2.service 2021-07-09 14 systemd-delta 36 Velcro 06.989928469 + 0530 @-13L8 @ @ KillMode=mixedTasksMax=infinityNotifyAccess=all+Restart=on-failure+RestartSec=5s [Install] WantedBy=multi-user.target [EQUIVALENT] / etc/systemd/system/default.target → / usr/lib/systemd/system/default.target [OVERRIDDEN] / etc/systemd/system/sshd.service → / usr/lib/systemd/system/sshd.serviceFiles / usr/lib/systemd/system/sshd.service and / etc/systemd/system/sshd.service are identical [EXTENDED] / usr/lib/systemd/system/NetworkManager.service → / usr/lib/systemd/system/NetworkManager.service.d/NetworkManager-ovs.conf [EXTENDED] / usr/lib/systemd/system/btrfs -balance.timer → / etc/systemd/system/btrfs-balance.timer.d/schedule.conf [EXTENDED] / usr/lib/systemd/system/btrfs-scrub.timer → / etc/systemd/system/btrfs-scrub.timer.d/schedule.conf [EXTENDED] / usr/lib/systemd/system/nfs-client.target → / usr/lib/systemd/system/nfs-client.target.d/nfs.conf [EXTENDED] / usr/lib/systemd/system/rpc- Gssd.service → / usr/lib/systemd/system/rpc-gssd.service.d/options.conf [EXTENDED] / usr/lib/systemd/system/rpc-statd-notify.service → / usr/lib/systemd/system/rpc-statd-notify.service.d/options.conf [EXTENDED] / usr/lib/systemd/system/rpc-statd.service → / usr/lib/systemd/system/rpc-statd.service.d/options.conf [EXTENDED] / usr/lib / systemd/system/rpc-svcgssd.service → / usr/lib/systemd/system/rpc-svcgssd.service.d/options.conf [EXTENDED] / usr/lib/systemd/system/systemd-sysctl.service → / usr/lib/systemd/system/systemd-sysctl.service.d/50-kernel-uname_r.conf13 overridden configuration files found. What is Linux system Linux is a free-to-use and free-spread UNIX-like operating system, is a POSIX-based multi-user, multi-task, multi-threaded and multi-CPU operating system, using Linux can run major Unix tools, applications and network protocols.

On the Linux system to modify the existing systemd unit files what is the method to share here, I hope that the above content can make you improve. If you want to learn more knowledge, please pay more attention to the editor's updates. Thank you for following the website!

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