小编Los*_*und的帖子

systemd: use variables in a unit file

I have unit files for bunch of services. In ExecStart I want to refer to directory part of a path name using a variable so that I can easily update many unit files in case a location of executables changes.

我正在使用 EnvironmentFile 来定义变量并在单元文件中获取文件。然而,变量似乎在单元文件本身内不可见,而只能在环境中(我没有测试过它们是否确实在环境中可见)。有没有其他惯用的方式来使用变量进行动态配置?

环境文件

[Service]
Environment=MYS_PATH=/opt/myservice
Environment=MYS_USER=user
Run Code Online (Sandbox Code Playgroud)

单元文件

[Unit]
Description=My service
After=network.target

[Service]
EnvironmentFile=/etc/systemd/system/myservice.service.d/myservice_defs.conf
Type=simple
User=${MYS_USER}
WorkingDirectory=${MYS_PATH}
ExecStart=${MYS_PATH}/usr/bin/myservice -C ${MYS_PATH}/etc/myservice.conf
Run Code Online (Sandbox Code Playgroud)

variables configuration systemd

4
推荐指数
1
解决办法
5869
查看次数

标签 统计

configuration ×1

systemd ×1

variables ×1