Pass an environment variable from current shell to a systemd unit
You can affect the global systemd environment for all future commands (until reboot) by using
sudo systemctl set-environment var=value
or if you already have var
exported in your environment, you can use
sudo systemctl import-environment var
After starting your unit you can remove the variable with unset-environment
similarly.
As this is global in effect you would be better off simply writing the line DB_URL=databus.dev.mysite.io:8080
into some file /some/file
and setting EnvironmentFile=/some/file
in your unit.
An alternative method is to use a template unit [email protected]
which is started with systemctl start myunit@'databus.dev.mysite.io:8080'
. You can then recover this parameter as %i
inside the unit, for example in the [Service]
section with a line like:
Environment=DB_URL=%i