Skip to content
Advertisement

How to use environment variables in a .service script

I have an elixir project on a linux server. I have created a .service script which will start and stop the application with the following commands

JavaScript

The .service file looks something like this…

JavaScript

It works as expected, the one exception being that it will not read the environment variables. I can give the application access to them by adding them to the script manually like I have with PORT=4000 above.

I want to know if there is a way for the .service file to access the env vars that I have on my server so I do not have to write them in each I use this script on a new server. Thanks in advance

Feel free to check out the repo if you would like more info on the project! 👍

Advertisement

Answer

You are looking for EnvironmentFile= directive in [Service] section.

JavaScript

Read here for more info.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement