Skip to content

Add support for loading environment variables from optional file - #80

Merged
kardianos merged 1 commit into
kardianos:masterfrom
jessecarbon:master
Nov 19, 2016
Merged

kardianos merged 1 commit into
kardianos:masterfrom
jessecarbon:master

Conversation

@jessecarbon

Copy link
Copy Markdown
Contributor

It's common to want to load environment variables from an external file for a service upon startup. The common location for these for SysV scripts is /etc/sysconfig/$service_name. Some examples: docker, Graylog, nginx, elasticsearch.

For systemd unit files, there's an option called EnvironmentFile. Example: elasticsearch.

Both of these additions are only applied if the files exist. I've tested both of them on CentOS 6 and 7, respectively. The systemd EnvironmentFile can always be added after the fact with a drop-in, but i added it here for consistency. If it should be excluded, I can edit the PR. For SysV scripts however, there's not really another good way to inject environment variables.

@jessecarbon

jessecarbon commented Nov 8, 2016 •

Copy link
Copy Markdown
Contributor Author

I just realized that debian actually uses /etc/default/$service_name instead of /etc/sysconfig/$service_name. Without maintaining separate templates for rpm/deb distros, I could add a secondary check for that file. Please let me know your thoughts.

@kardianos
kardianos merged commit 6d3a0ee into kardianos:master Nov 19, 2016
@kardianos

Copy link
Copy Markdown
Owner

Supporting debian would be nice. Please issue a PR when you get a chance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants