I've built an application and a systemd unit for it. The systemd unit works fine, but as the dev and prod environments have diverged I've started moving config out to environment variables and I can't seem to get them to work in systemd.
I've tried system-wide environment variables, and they're visible to the OS, but not the program, so i started looking at building them into systemd units.
First I tried using EnvironmentFile
I created an environment file that simply had
LCSQLH=localhost
LCSQLU=application
in it as /etc/lc.sh
and
[Unit]
Description=Service for this app
[Service]
EnvironmentFile=/etc/lc.sh
ExecStart=/usr/bin/env python /opt/app/__init__.py
did a systemctl --system daemon-reload
but no, my app errored:
Jan 27 14:24:59 machine.host env[630]: KeyError: 'LCSQLU'
I saw some had:
EnvironmentFile=-/etc/lc.sh
I tried that.... nope...
So I tried putting them in individually
[Service]
Environment="LCSQLH=localhost"
Environment="LCSQLU=application"
ExecStart=/usr/bin/env python /opt/app/__init__.py
Yet again, no...
So I heard about the idea of /etc/systemd/service_name.service.d
so I put a service.conf in there with the environments in (same format as above) but no...
My application has no access to these environment variables.
If I export them (either manually in my shell or using /etc/profile.d/) and run my app directly it works, so it is that these aren't being set rather than an app issue.
This is Centos 7.3 and I've chosen environment variables rather than a hardcoded config because it may run on either linux or windows, so don't want to bury a config file in /etc/
systemctl daemon-reload
and stop start your application each time to test your modifications?