I have the following unit file:
[Unit]
Description=Panel for Systemd Services
After=network.target
[Service]
User=pysd
Group=pysd
PermissionsStartOnly=true
WorkingDirectory=/opt/pysd
ExecStartPre=/bin/mkdir /run/pysd
ExecStartPre=/bin/chown -R pysd:pysd /run/pysd
ExecStart=/usr/local/bin/gunicorn app:app -b 127.0.0.1:8100 --pid /run/pysd/pysd.pid --workers=2
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID
ExecStopPost=/bin/rm -rf /run/pysd
PIDFile=/run/pysd/pysd.pid
PrivateTmp=true
[Install]
WantedBy=multi-user.target
Alias=pysd.service
I would like to create an environment variable with ExecStartPre and then incorporating this variable to ExecStart.
To be more specific, I want to create an environment variable GUNICORN_SERVER, before running the ExecStart, and then using this environment variable for the option -b at ExecStart.
I tried something like ExecStartPre=/bin/bash -c 'export GUNICORN_SERVER=127.0.0.1:8100', but no environment variable was created.
How do I achieve this scenario?