Skip to content

Commit 1ef9d94

Browse files
committed
allow the config file location to be specified in $SUPERVISOR_CONFIG
1 parent bb0332f commit 1ef9d94

File tree

3 files changed

+35
-7
lines changed

3 files changed

+35
-7
lines changed

docs/configuration.rst

+7-6
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ Configuration File
33

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

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

supervisor/options.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def __init__(self, require_configfile=True):
101101
self.attr_priorities = {}
102102
self.require_configfile = require_configfile
103103
self.add(None, None, "h", "help", self.help)
104-
self.add("configfile", None, "c:", "configuration=")
104+
self.add("configfile", None, "c:", "configuration=", env="SUPERVISOR_CONFIG")
105105

106106
here = os.path.dirname(os.path.dirname(sys.argv[0]))
107107
searchpaths = [os.path.join(here, 'etc', 'supervisord.conf'),

supervisor/tests/test_options.py

+27
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,33 @@ def test_no_config_file(self):
281281
self.assertEqual(instance.username, 'chris')
282282
self.assertEqual(instance.password, '123')
283283

284+
def test_config_file_env(self):
285+
"""Making sure config file can be loaded from env."""
286+
supervisord_conf = os.path.join(tempfile.mkdtemp(), 'supervisord.conf')
287+
text = lstrip("""[supervisorctl]
288+
serverurl=http://localhost:9001
289+
username=chris
290+
password=123
291+
""")
292+
with open(supervisord_conf, 'w') as f:
293+
f.write(text)
294+
295+
try:
296+
os.environ['SUPERVISOR_CONFIG'] = supervisord_conf
297+
instance = self._makeOne()
298+
instance.searchpaths = []
299+
exitcodes = []
300+
instance.exit = lambda x: exitcodes.append(x)
301+
instance.realize(args=[])
302+
finally:
303+
os.environ.pop('SUPERVISOR_CONFIG', None)
304+
305+
self.assertEqual(exitcodes, [])
306+
self.assertEqual(instance.interactive, 1)
307+
self.assertEqual(instance.serverurl, 'http://localhost:9001')
308+
self.assertEqual(instance.username, 'chris')
309+
self.assertEqual(instance.password, '123')
310+
284311
def test_options(self):
285312
tempdir = tempfile.gettempdir()
286313
s = lstrip("""[supervisorctl]

0 commit comments

Comments
 (0)