Skip to content

Commit 7d384f9

Browse files
committed
Support directory expansions
1 parent 29eeb9d commit 7d384f9

File tree

4 files changed

+24
-8
lines changed

4 files changed

+24
-8
lines changed

CHANGES.rst

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
4.3.0.dev0 (Next Release)
22
-------------------------
33

4+
- Support ``directory`` expansions. Patch by Waket Zheng.
5+
46
- Fixed a bug where the poller would not unregister a closed
57
file descriptor under some circumstances, which caused excessive
68
polling, resulting in higher CPU usage. Patch by aftersnow.

docs/configuration.rst

+3-1
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,7 @@ where specified.
642642
expressions are evaluated against a dictionary containing the keys
643643
``group_name``, ``host_node_name``, ``program_name``, ``process_num``,
644644
``numprocs``, ``here`` (the directory of the supervisord config file),
645+
``directory`` (if set in this section), ``user`` (if set in section),
645646
and all supervisord's environment variables prefixed with ``ENV_``.
646647
Controlled programs should themselves not be daemons, as supervisord
647648
assumes it is responsible for daemonizing its subprocesses (see
@@ -916,7 +917,8 @@ where specified.
916917
can contain Python string expressions that will evaluated against a
917918
dictionary that contains the keys ``group_name``, ``host_node_name``,
918919
``process_num``, ``program_name``, and ``here`` (the directory of the
919-
supervisord config file).
920+
supervisord config file). If ``directory`` section is set, the value
921+
``%(directory)s`` can be used.
920922

921923
.. note::
922924

supervisor/options.py

+3
Original file line numberDiff line numberDiff line change
@@ -943,6 +943,7 @@ def get(section, opt, *args, **kwargs):
943943
uid = None
944944
else:
945945
uid = name_to_uid(user)
946+
common_expansions['user'] = user
946947

947948
umask = get(section, 'umask', None)
948949
if umask is not None:
@@ -977,6 +978,8 @@ def get(section, opt, *args, **kwargs):
977978
expansions['ENV_%s' % k] = v
978979

979980
directory = get(section, 'directory', None)
981+
if directory is not None:
982+
expansions['directory'] = directory
980983

981984
logfiles = {}
982985

supervisor/tests/test_options.py

+16-7
Original file line numberDiff line numberDiff line change
@@ -1692,7 +1692,7 @@ def test_processes_from_section(self):
16921692
instance = self._makeOne()
16931693
text = lstrip("""\
16941694
[program:foo]
1695-
command = /bin/cat
1695+
command = /bin/cat /%(user)s/.vimrc
16961696
priority = 1
16971697
autostart = false
16981698
autorestart = false
@@ -1719,7 +1719,7 @@ def test_processes_from_section(self):
17191719
self.assertEqual(len(pconfigs), 2)
17201720
pconfig = pconfigs[0]
17211721
self.assertEqual(pconfig.name, 'bar_foo_00')
1722-
self.assertEqual(pconfig.command, '/bin/cat')
1722+
self.assertEqual(pconfig.command, '/bin/cat /root/.vimrc')
17231723
self.assertEqual(pconfig.autostart, False)
17241724
self.assertEqual(pconfig.autorestart, False)
17251725
self.assertEqual(pconfig.startsecs, 100)
@@ -1753,13 +1753,21 @@ def test_processes_from_section_host_node_name_expansion(self):
17531753

17541754
def test_processes_from_section_process_num_expansion(self):
17551755
instance = self._makeOne()
1756+
nums = (0, 1)
1757+
for num in nums:
1758+
log_dir = '/tmp/foo_{0}/foo_{0}_stdout'.format(num)
1759+
if not os.path.exists(log_dir):
1760+
parent = os.path.dirname(log_dir)
1761+
if not os.path.exists(parent):
1762+
os.mkdir(parent)
1763+
os.mkdir(log_dir)
17561764
text = lstrip("""\
17571765
[program:foo]
17581766
process_name = foo_%(process_num)d
1759-
command = /bin/foo --num=%(process_num)d
1767+
command = /bin/foo --num=%(process_num)d --dir=%(directory)s
17601768
directory = /tmp/foo_%(process_num)d
17611769
stderr_logfile = /tmp/foo_%(process_num)d_stderr
1762-
stdout_logfile = /tmp/foo_%(process_num)d_stdout
1770+
stdout_logfile = %(directory)s/foo_%(process_num)d_stdout
17631771
environment = NUM=%(process_num)d
17641772
numprocs = 2
17651773
""")
@@ -1768,14 +1776,15 @@ def test_processes_from_section_process_num_expansion(self):
17681776
config.read_string(text)
17691777
pconfigs = instance.processes_from_section(config, 'program:foo', 'bar')
17701778
self.assertEqual(len(pconfigs), 2)
1771-
for num in (0, 1):
1779+
for num in nums:
17721780
self.assertEqual(pconfigs[num].name, 'foo_%d' % num)
1773-
self.assertEqual(pconfigs[num].command, "/bin/foo --num=%d" % num)
1781+
self.assertEqual(pconfigs[num].command,
1782+
"/bin/foo --num=%d --dir=/tmp/foo_%d" % (num, num))
17741783
self.assertEqual(pconfigs[num].directory, '/tmp/foo_%d' % num)
17751784
self.assertEqual(pconfigs[num].stderr_logfile,
17761785
'/tmp/foo_%d_stderr' % num)
17771786
self.assertEqual(pconfigs[num].stdout_logfile,
1778-
'/tmp/foo_%d_stdout' % num)
1787+
'/tmp/foo_%d/foo_%d_stdout' % (num, num))
17791788
self.assertEqual(pconfigs[num].environment, {'NUM': '%d' % num})
17801789

17811790
def test_processes_from_section_numprocs_expansion(self):

0 commit comments

Comments
 (0)