Getting systemd to use user ENV configs
I am trying to create an LXC container to run a specific Django Application automatically at start. The issue I am having is that getting the Django side of things starting up with systemd was fairly easy, however the application checks ENV variables as well as relies on some Ruby Gems to function.
The LXC Template is based on Debian 11.
Due to the specific requirements, I run pyenv and rbenv to manage the installed versions for the specific user (django for the purposes of this example).
I can get systemd to start the Gunicorn server well enough, but am having an issue that it seems to not pull ENV variables (Not sure yet), nor does it get access to the required Ruby Gems (Confirmed).
My gunicorn.service file looks like this:
[Unit]
Description=Start Gunicorn to run Django App
After=network.target
[Service]
Type=notify
# the specific user that our service will run as
User=django
Group=django
RuntimeDirectory=/home/django/.pyenv/shims
WorkingDirectory=/home/django/application
ExecStartPre=/home/django/.pyenv/shims/python /home/django/app/manage.py migrate
ExecStart=/home/django/.pyenv/shims/gunicorn --chdir /home/django/app app.wsgi:application -k=gevent -t 600 --certfile=/home/django/app/server.crt --keyfile=/home/django/app/server.key -b=0.0.0.0:8000 -w=4 --forwarded-allow-ips=* --proxy-allow-from=*
ExecReload=/bin/kill -s HUP $MAINPID
KillMode=mixed
TimeoutStopSec=5
PrivateTmp=true
[Install]
WantedBy=multi-user.target
How can I get systemd to run the gunicorn.service wherein the ENV variables specified in home/django/.bashrc will be honored, and also gain access to the required Gems. For reference, running gunicorn from the user account with the above variables works 100% as expected, so this is merely getting the same functionality from systemd at startup without requiring me to manually log into the server and run the commands.