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)