Why systemd is not loading environment file
Hello, I have this:
cat /etc/sysconfig/pagekite
OPTIONS="--optdir=/etc/pagekite.d"
PK_UID="daemon"
PK_GID="daemon"
PK_LOGFILE="/var/log/pagekite/pagekite.log"
Then I have this systemd unit:
cat /usr/lib/systemd/system/pagekite.service
[Unit]
Description=PageKite makes localhost servers visible to the world
Documentation=man:pagekite(1) http://www.pagekite.net
[Service]
Type=forking
EnvironmentFile=/etc/sysconfig/pagekite
PIDFile=/var/run/pagekite.pid
ExecStart=/usr/bin/pagekite --clean --logfile=$PK_LOGFILE --runas=$PK_UID:$PK_GID --pidfile=/var/run/pagekite.pid $OPTIONS --daemonize
ExecReload=kill -HUP `cat /var/run/pagekite.pid`
[Install]
WantedBy=multi-user.target
Everytime I try to start the service, it is apparently not substituting variables and my program is ending with:
Error: 'getpwnam(): name not found: $PK_UID'
Because it tries to find UID "$PK_UID" instead of substituted "pagekite".
What is wrong here? I am pretty sure I am doing it correctly according to the docs. Thanks.
Why not define these things in configuration files, to be read at runtime? Your implementation here seems fragile.
I want to keep backward compabitility with upstream and also support RHEL6/RHEL5. I want to use EnvifonmentFile. Now, do you see any issues here? Why it does not work?
Are you sure? Because files are not parsed with Bash in case of systemd. It's not evaluated, it's interpreted by systemd itself.
Ok now it works, I was changing the unit file and I was ignoring this Warning: Unit file changed on disk, 'systemctl --system daemon-reload' recommended.
This is working unit file.
I was missing curly braces.