Skip to content

Commit

Permalink
allow the config file location to be specified in $SUPERVISOR_CONFIG
Browse files Browse the repository at this point in the history
  • Loading branch information
luto committed Apr 11, 2017
1 parent bb0332f commit 1ef9d94
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 7 deletions.
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

0 comments on commit 1ef9d94

Please sign in to comment.