Ask Your Question
0

Why systemd is not loading environment file

asked 2013-02-12 17:10:59 -0500

lzap gravatar image

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.

edit retag flag offensive close merge delete

Comments

Why not define these things in configuration files, to be read at runtime? Your implementation here seems fragile.

randomuser gravatar imagerandomuser ( 2013-02-12 19:14:55 -0500 )edit

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?

lzap gravatar imagelzap ( 2013-02-13 02:27:16 -0500 )edit

Are you sure? Because files are not parsed with Bash in case of systemd. It's not evaluated, it's interpreted by systemd itself.

lzap gravatar imagelzap ( 2013-02-13 02:50:13 -0500 )edit

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.

lzap gravatar imagelzap ( 2013-02-13 03:03:47 -0500 )edit

This is working unit file.

[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 $MAINPID

[Install]
WantedBy=multi-user.target

I was missing curly braces.

lzap gravatar imagelzap ( 2013-02-13 03:24:28 -0500 )edit

2 Answers

Sort by » oldest newest most voted
2

answered 2013-02-14 10:18:03 -0500

lennart gravatar image

You want ${FOOBAR} instead of $FOOBAR if shall be resolved as part of a word.

See the discussion about this in systemd.service(5), the part about ExectStart=.

edit flag offensive delete link more
0

answered 2015-02-20 05:58:45 -0500

nemd gravatar image

Don't use quotes in environment file.

cat /etc/sysconfig/pagekite 
OPTIONS=--optdir=/etc/pagekite.d
PK_UID=daemon PK_GID=daemon
PK_LOGFILE=/var/log/pagekite/pagekite.log

will work

edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-02-12 17:10:59 -0500

Seen: 28,516 times

Last updated: Feb 20 '15