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 instantiate the unit configuration of systemd in Linux

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

This article introduces the relevant knowledge of "how to instantiate the unit configuration of systemd in Linux". 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!

At run time, you may need to instantiate several units of a template. The @ character is used to identify the relationship between the template and the unit file. The instantiation unit can be instantiated from another cell file (using the Requires or Wants option), or using the systemctlstart command. The instantiated service unit can be named as follows:

The code is as follows:

Template_name@instance_name.service

Several instances can point to all the common instances of the same template file configuration option. For example, the Wants option for a unit configuration file can be:

The code is as follows:

Wants=getty@ttyA.service,getty@ttyB.service

First, let systemd search for a given service unit. If nothing is found, systemd ignores the part between @ and the period, directly searches the getty@.service service file, reads the configuration, and starts the service.

Wildcard fields, called cell specifiers, can be used in any cell configuration file. Unit specifiers replace some unit parameters and interpretations at run time. Commonly used unit specifiers are described as follows:

% n the entire unit name, including the type suffix,% N has the same meaning, but ASCII is replaced by a forbidden character.

The% p prefix name, which, when instantiated, represents the first part of the @ character.

The direct part of the% I instance name, the @ character and the unit type. % I has the same meaning, but ASCII is replaced by forbidden characters.

% H host name, the host name when the configuration file is loaded.

The% t runtime directory, the current run directory, is the / run directory for root users and the directory specified by the XDG_RUNTIME_DIR variable for unprivileged users.

For example, getty@.service contains the following structure:

The code is as follows:

[Unit]

Description=Gettyon%I

...

[Service]

ExecStart=-/sbin/agetty--noclear%I$TERM

...

When getty@ttyA.service and getty@ttyB.service are instantiated, Description= is interpreted as "GettyonttyA" and "GettyonttyB".

That's all for "how to instantiate the unit configuration of systemd in Linux". Thank you for 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