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

Unit file configuration of Systemd in Centos7

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

This article introduces the knowledge of "Unit file configuration of Systemd in Centos7". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Systemd uses units (Units) to manage system services and programs. The system unit uses configuration files to control its related operations. There are three types of cell profiles: default cell profiles, system-specific unit profiles, and runtime unit profiles.

The paths where the three types of cell profiles are located are listed below:

Default cell profile-/ usr/lib/systemd/system

Runtime configuration file-/ run/systemd/system

System-specific configuration file-/ etc/systemd/system

The default unit configuration file, which is generated in the / usr/lib/systemd/system directory during installation when a new package is installed.

Run-time unit configuration files are automatically generated and deleted when units starts and stops, respectively.

System-specific configuration files contain custom unit configurations. With these profiles, users can override the default behavior of units.

When we make any changes to the state of system services and programs, such as start, stop, enable, and disable, systemd reads and executes its unit configuration file. Check the cell configuration files in the following order.

System-specific unit profile, run-time unit profile, default unit profile.

For example, if a units configuration file exists under all three paths, only the system-specific configuration file, / etc/systemd/system, is used.

Unit configuration file writing format

A unit configuration file contains all the necessary information to control the unit, such as: the path to start the Units file, the name of the service/units that needs to be started before and after Units, the location of documents, manuals, dependency information, conflict information, and so on.

The information in the Unit configuration file is usually divided into three parts. [Unit], [Type], [Install] .

Look for a Unit configuration file to explain:

[root@localhost ~] # cat / usr/lib/systemd/system/sshd.service [Unit] Description=OpenSSH server daemon Documentation=man:sshd (8) man:sshd_config (5) After=network.target sshd-keygen.target Wants=sshd-keygen.target [Service] Type=notify EnvironmentFile=-/etc/crypto-policies/back-ends/opensshserver.config EnvironmentFile=-/etc/sysconfig/sshd ExecStart=/usr/sbin/sshd-D $OPTIONS $CRYPTO_POLICY ExecReload=/bin/kill-HUP $MAINPID KillMode=process Restart=on-failure RestartSec=42s [Install] WantedBy=multi-user.target

Unit part

This section usually contains descriptions, documentation, settings that depend on other programs, including settings before or after which service to start the Units, and so on.

Description: this statement provides a brief description. You can see the description in systemctl list-units or systemctl status [Units].

Documentation: this statement provides the location of the manual (help documentation) page and the command to access the manual page.

After: this statement lists the units that should be activated after this unit. It simply regulates the order in which services are started, and there is no mandatory requirement for startup.

Before: this statement lists the units that should be activated before the unit. It simply regulates the order in which services are started, and there is no mandatory requirement for startup.

Wants: defines which unit needs to be started after the unit starts.

Requires: clearly defines which unit needs to be started before it can be started, and if the previous unit is not started, then the unit will not be started.

Conflicts: this statement lists the units / services that must be stopped before starting the unit.

The After/Before statement of a unit defines the order in which the unit should be started. The want/Requires statement of a unit defines the dependency of that unit.

Type part

This section represents the type of Unit. There are [Service], [Socket], [Timer], [Mount], [Path] and other types. Sshd.service is used as an example in this article, so the [Service] type is used here.

The following is a list of common statements:

Type: indicates the type of startup. There are several types: simple is the default, forking, oneshot, and so on.

EnvironmentFile: you can have multiple of this statement, followed by a configuration file.

ExecStart: followed by the statement started

ExecStop: followed by a statement to stop the service

ExecReload: followed by a statement to restart the service

KillMode: if this statement is process, it terminates the main program when the process is terminated. If you none, the program will not be closed.

Install part

In this section, which target to install this Unit into. It is often installed in multi-user.target.

WantedBy: the Target name that automatically starts the Unit. For example, if you see multi-user.target in this statement, it means that the Unit will start automatically when the system enters the "multi-user.target" run level.

You can see that when systemctl enable sshd.service is executed, the sshd.service is created from the / usr/lib/systemd/system directory to hyperlink under / etc/systemd/system/multi-user.target.wants.

This is the end of the Unit file configuration of Systemd in Centos7. Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

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