Database Environment Variables not available with systemd unit start

I have my package-based docker container based on the univention/ucs-appbox-amd64:4.2-2 image up and running. My app is started - as suggested - via a systemd service unit.

The app fails to start up, because it is missing the environment variables (DB_HOST, DB_PASSWORD, DB_NAME and so on) to connect to the host’s mysql database. I’ve dump a list of the environment during the application’s startup:

Mar 06 15:27:30 kitom-23801244 bash[8569]: environ({‘PATH’: ‘/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin’, ‘LANG’: ‘C.UTF-8’, ‘KITOMA_CONFIG’: ‘/opt/kitoma/config/default.py’, ‘FLASK_APP’: ‘kitoma’, ‘_’: ‘/opt/kitoma/bin/python3.4’, ‘PWD’: ‘/opt/kitoma’, ‘KITOMA_MODE’: ‘WEB’, ‘SHLVL’: ‘1’, ‘PYTHONPATH’: ‘/opt/kitoma/’})

The set variables are configured in the systemd unit:

[Unit]
Description=Kitoma VOIP-Management

[Service]
User=kitoma
Environment=PYTHONPATH=/opt/kitoma/
Environment=FLASK_APP=kitoma
Environment=LANG=C.UTF-8
Environment=KITOMA_CONFIG=/opt/kitoma/config/default.py
Environment=KITOMA_MODE=WEB
WorkingDirectory=/opt/kitoma/
ExecStart=/opt/kitoma/bin/python3.4 -m flask run --host 0.0.0.0

[Install]
WantedBy=multi-user.target

Please note that the required environment variables are available when I run the application manually from the bash console. I also tried to set ExecStart to start with

/bin/bash -c "myapp"

but it did not change the behavior. At the moment I have no idea how to make sure that the environment variables are injected into the systemd unit’s context.

Hi,

maybe it is possible to use EnvironmentFile? You could write it manually in a custom setup file (that calls the original setup script at the end).

https://wiki.univention.de/index.php/Docker_Apps/Container_Scripts
http://fedoraproject.org/wiki/Packaging:Systemd#EnvironmentFiles_and_support_for_.2Fetc.2Fsysconfig_files

Regards,
Dirk Wiesenthal

Thanks this works. After some more investigation systemd does not embed the enviornment variables at all as it runs in a very own context.

I create my environment file now in the join script and this works fine.

Mastodon