diff --git a/docs/configuration.rst b/docs/configuration.rst index e99274e75..ed7aa3826 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -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` diff --git a/supervisor/options.py b/supervisor/options.py index 9747e4292..f297cb3c4 100644 --- a/supervisor/options.py +++ b/supervisor/options.py @@ -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'), diff --git a/supervisor/tests/test_options.py b/supervisor/tests/test_options.py index 3bae59b8a..a2966d526 100644 --- a/supervisor/tests/test_options.py +++ b/supervisor/tests/test_options.py @@ -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]