![是否允许在 systemd 的环境文件中使用变量?](https://linux22.com/image/133345/%E6%98%AF%E5%90%A6%E5%85%81%E8%AE%B8%E5%9C%A8%20systemd%20%E7%9A%84%E7%8E%AF%E5%A2%83%E6%96%87%E4%BB%B6%E4%B8%AD%E4%BD%BF%E7%94%A8%E5%8F%98%E9%87%8F%EF%BC%9F.png)
是否允许在 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. [...]
所以不行。