是否允许在 systemd 的环境文件中使用变量?

是否允许在 systemd 的环境文件中使用变量?

是否允许在 systemd 的环境文件中使用变量?

[Unit]
Description=ServiceAuto
Requires=network-online.target
After=network-online.target

[Service]
EnvironmentFile=/etc/systemd/system/auto.service.d/env.conf
Type=simple
ExecStart="Script to execute"
IgnoreSIGPIPE=no
RestartSec=8
TimeoutStartSec=10
TimeoutStopSec=15
User=support

[Install]
WantedBy=multi-user.target

我想知道是否允许在 /etc/systemd/system/auto.service.d/env.conf 中使用变量 MAIN_HOME 。例如:

MAIN_HOME=/opt/prod
USER=support
PATH=/usr/java/jdk1.8.0_161/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/support/.local/bin:/home/support/bin

JAVA_HOME=/usr/java/jdk1.8.0_161
LD_LIBRARY_PATH=/$MAIN_HOME/bin:/usr/lib

答案1

systemd.exec(5)手册页:

   EnvironmentFile=
       Similar to Environment= but reads the environment variables from a
       text file. [...]

...

   Environment=
       [...] Variable expansion is not performed
       inside the strings, however, specifier expansion is possible. The $
       character has no special meaning. [...]

所以不行。

相关内容