How to write a service unit file which enforces that particular services have to be started

本文详细介绍了在Red Hat Enterprise Linux 7中如何使用systemd的Requires=、Requisite=和PartOf=选项来确保服务依赖关系正确执行。这些选项能够确保在特定服务启动前,其依赖的服务已经成功运行。

https://access.redhat.com/solutions/3120581

 SOLUTION 已验证 - 已更新 2017年七月20日15:22 - 

English 

环境

  • Red Hat Enterprise Linux 7
  • systemd

问题

  • After=/Before= options don't guarantee the listed units has been started and running. How do I write a service unit file which enforces that particular services have to be started?

决议

Background:

On RHEL7, a service unit file needs to specify its dependencies using After=/Before= options. This ensures that (if configured that way) that, for example, b.service will be started after a.service. What it does not do is ensure that b.service is only started if a.service is successfully started. This is because the After=/Before= options just specify the order of dependencies. Any After=/Before= does not care about if the dependency is running or not.

If a service requires that the dependent services have to be running, you need to consider the options listed below to satisfy that requirement.

Detailed information:

[Unit] section of a service configuration file can contain following options which enforce a requirement that the listed units must be started and running. The details are quoted from man 5 systemd.unit.

Raw

Requires=
Requisite=
PartOf=
  • The details of Requires=
    This option configures requirement dependencies on other units. If this unit gets activated, the units listed here will be activated as well. If one of the other units gets deactivated or its activation fails, this unit will be deactivated. This option may be specified more than once or multiple space-separated units may be specified in one option in which case requirement dependencies for all listed names will be created. Note that requirement dependencies do not influence the order in which services are started or stopped. This has to be configured independently with the After= or Before= options. If a unit foo.service requires a unit bar.service as configured with Requires= and no ordering is configured with After= or Before=, then both units will be started simultaneously and without any delay between them if foo.service is activated. Often it is a better choice to use Wants= instead of Requires= in order to achieve a system that is more robust when dealing with failing services.

  • The details of Requisite=
    This option is similar to Requires= respectively. However, if the units listed here are not started already, they will not be started and the transaction will fail immediately.

  • The details of PartOf=
    This option configures dependencies similar to Requires=, but limited to stopping and restarting of units. When systemd stops or restarts the units listed here, the action is propagated to this unit. Note that this is a one-way dependency — changes to this unit do not affect the listed units.

How do I choose which option preferred to my unit file?

This section provides some guidance on how to choose the appropriate keyword(s) in your unit file(s). In the following, we assume a.service and b.service have their dependencies as described below.

Raw

a.service (Before=b.service)
b.service (After=a.service)
  1. When b.service is activated, a.service should be activated also (if not already). The unit a.service must start successfully - if it fails or is deactivated b.service will also be deactivated.
    You should use Requires= to activate a.service and ensure b.service cannot start unless a.service starts.

  2. If a.service is not started already, b.service should not be started and will fail immediately. The activation of a.service should not be triggered by the activation of b.service.
    You should use Requisite= to fulfill the requirement.

  3. b.service always needs to be activated after a.service is activated. But a.service should not be activated when b.service is activated however a.service does need to be stopped or restarted when b.service is stopped or restarted.
    You should use PartOf= in this situation.

    You may need to use multiple keywords to achieve a desired outcome. For example, you may have b.service with Requires=a.service so b.service will not start unless a.service starts and starting b.service starts a.service first. As well in the definition of a.service you might need PartOf=b.service so if b.service is stopped or restarted a.service will have the same action taken on it.

    Complex interactions between units can be achieved but requires you to plan out what interactions are required. For other options, please refer to man 5 systemd.unit.

六自由度机械臂ANN人工神经网络设计:正向逆向运动学求解、正向动力学控制、拉格朗日-欧拉法推导逆向动力学方程(Matlab代码实现)内容概要:本文档围绕六自由度机械臂的ANN人工神经网络设计展开,详细介绍了正向与逆向运动学求解、正向动力学控制以及基于拉格朗日-欧拉法推导逆向动力学方程的理论与Matlab代码实现过程。文档还涵盖了PINN物理信息神经网络在微分方程求解、主动噪声控制、天线分析、电动汽车调度、储能优化等多个工程与科研领域的应用案例,并提供了丰富的Matlab/Simulink仿真资源和技术支持方向,体现了其在多学科交叉仿真与优化中的综合性价值。; 适合人群:具备一定Matlab编程基础,从事机器人控制、自动化、智能制造、电力系统或相关工程领域研究的科研人员、研究生及工程师。; 使用场景及目标:①掌握六自由度机械臂的运动学与动力学建模方法;②学习人工神经网络在复杂非线性系统控制中的应用;③借助Matlab实现动力学方程推导与仿真验证;④拓展至路径规划、优化调度、信号处理等相关课题的研究与复现。; 阅读建议:建议按目录顺序系统学习,重点关注机械臂建模与神经网络控制部分的代码实现,结合提供的网盘资源进行实践操作,并参考文中列举的优化算法与仿真方法拓展自身研究思路。
Open SQL, introduced in SAP HANA and used in ABAP environments, provides a modernized approach to database interactions, allowing developers to write more readable and maintainable code. One of the key features of the new Open SQL syntax is the use of the `@` symbol to escape host variables. This syntax helps clearly distinguish between SQL identifiers and ABAP variables, improving code clarity and reducing the risk of SQL injection attacks. When using the `@` notation, host variables are explicitly marked within the SQL statement, making it easier for both the compiler and developers to identify which values come from the application logic and which are part of the static SQL structure. For example, in a `SELECT` statement, any variable that is passed from ABAP to the SQL query must be prefixed with `@` to indicate that it is a host variable. Here is an example of how to use the `@` symbol in a `SELECT` query: ```abap DATA: lv_name TYPE string VALUE 'John', lt_result TYPE TABLE OF ztable. SELECT * FROM ztable INTO TABLE @lt_result WHERE name = @lv_name. ``` In this example, both `@lt_result` and `@lv_name` are host variables that are passed from the ABAP program into the SQL statement. The `@` symbol tells the Open SQL parser to treat these as values from the ABAP layer rather than as SQL identifiers or literals. The use of `@` also extends to more complex scenarios, such as using expressions or inline declarations. For instance, when using `VALUE` expressions or `CASE` statements, developers can still reference host variables with the `@` prefix to ensure proper scoping and interpretation. ```abap SELECT * FROM ztable INTO TABLE @lt_result WHERE age > @sy-datum - 30. ``` This syntax enforces stricter parsing rules, ensuring that developers are explicit about where data is coming from, which contributes to safer and more predictable database operations. It also supports better integration with modern IDE features, such as syntax highlighting and code analysis tools, which can now more accurately parse and validate Open SQL statements during development. Additionally, the `@` syntax enables better performance optimizations by allowing the database to cache execution plans more effectively, as the structure of the SQL statements remains consistent while only the parameter values change [^1].
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值