Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow configuration file to be specified via a environment variable #917

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ Configuration File

The Supervisor configuration file is conventionally named
:file:`supervisord.conf`. It is used by both :program:`supervisord`
and :program:`supervisorctl`. If either application is started
without the ``-c`` option (the option which is used to tell the
application the configuration filename explicitly), the application
will look for a file named :file:`supervisord.conf` within the
following locations, in the specified order. It will use the first
file it finds.
and :program:`supervisorctl`. Either application can be starting with
the ``-c`` or ``--configuration`` option, which is used to tell the
application the configuration filename explicitly. Alternatively the
config file can be specified in the ``$SUPERVISOR_CONFIG`` environment
variable. If neither is he application will look for a file named
:file:`supervisord.conf` within the following locations, in the
specified order. It will use the first file it finds.

#. :file:`$CWD/supervisord.conf`

Expand Down
2 changes: 1 addition & 1 deletion supervisor/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def __init__(self, require_configfile=True):
self.attr_priorities = {}
self.require_configfile = require_configfile
self.add(None, None, "h", "help", self.help)
self.add("configfile", None, "c:", "configuration=")
self.add("configfile", None, "c:", "configuration=", env="SUPERVISOR_CONFIG")

here = os.path.dirname(os.path.dirname(sys.argv[0]))
searchpaths = [os.path.join(here, 'etc', 'supervisord.conf'),
Expand Down
27 changes: 27 additions & 0 deletions supervisor/tests/test_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,33 @@ def test_no_config_file(self):
self.assertEqual(instance.username, 'chris')
self.assertEqual(instance.password, '123')

def test_config_file_env(self):
"""Making sure config file can be loaded from env."""
supervisord_conf = os.path.join(tempfile.mkdtemp(), 'supervisord.conf')
text = lstrip("""[supervisorctl]
serverurl=http://localhost:9001
username=chris
password=123
""")
with open(supervisord_conf, 'w') as f:
f.write(text)

try:
os.environ['SUPERVISOR_CONFIG'] = supervisord_conf
instance = self._makeOne()
instance.searchpaths = []
exitcodes = []
instance.exit = lambda x: exitcodes.append(x)
instance.realize(args=[])
finally:
os.environ.pop('SUPERVISOR_CONFIG', None)

self.assertEqual(exitcodes, [])
self.assertEqual(instance.interactive, 1)
self.assertEqual(instance.serverurl, 'http://localhost:9001')
self.assertEqual(instance.username, 'chris')
self.assertEqual(instance.password, '123')

def test_options(self):
tempdir = tempfile.gettempdir()
s = lstrip("""[supervisorctl]
Expand Down