|
@@ -13,19 +13,19 @@ Examples
|
|
|
|
|
|
# Pidfiles and logfiles are stored in the current directory
|
|
# Pidfiles and logfiles are stored in the current directory
|
|
# by default. Use --pidfile and --logfile argument to change
|
|
# by default. Use --pidfile and --logfile argument to change
|
|
- # this. The abbreviation %N will be expanded to the current
|
|
|
|
|
|
+ # this. The abbreviation %n will be expanded to the current
|
|
# node name.
|
|
# node name.
|
|
- $ celery multi start Leslie -E --pidfile=/var/run/celery/%N.pid
|
|
|
|
- --logfile=/var/log/celery/%N.log
|
|
|
|
|
|
+ $ celery multi start Leslie -E --pidfile=/var/run/celery/%n.pid
|
|
|
|
+ --logfile=/var/log/celery/%n.log
|
|
|
|
|
|
|
|
|
|
# You need to add the same arguments when you restart,
|
|
# You need to add the same arguments when you restart,
|
|
# as these are not persisted anywhere.
|
|
# as these are not persisted anywhere.
|
|
- $ celery multi restart Leslie -E --pidfile=/var/run/celery/%N.pid
|
|
|
|
- --logfile=/var/run/celery/%N.log
|
|
|
|
|
|
+ $ celery multi restart Leslie -E --pidfile=/var/run/celery/%n.pid
|
|
|
|
+ --logfile=/var/run/celery/%n.log
|
|
|
|
|
|
# To stop the node, you need to specify the same pidfile.
|
|
# To stop the node, you need to specify the same pidfile.
|
|
- $ celery multi stop Leslie --pidfile=/var/run/celery/%N.pid
|
|
|
|
|
|
+ $ celery multi stop Leslie --pidfile=/var/run/celery/%n.pid
|
|
|
|
|
|
# 3 workers, with 3 processes each
|
|
# 3 workers, with 3 processes each
|
|
$ celery multi start 3 -c 3
|
|
$ celery multi start 3 -c 3
|
|
@@ -101,6 +101,7 @@ import socket
|
|
import sys
|
|
import sys
|
|
|
|
|
|
from collections import defaultdict, namedtuple
|
|
from collections import defaultdict, namedtuple
|
|
|
|
+from functools import partial
|
|
from subprocess import Popen
|
|
from subprocess import Popen
|
|
from time import sleep
|
|
from time import sleep
|
|
|
|
|
|
@@ -111,7 +112,8 @@ from kombu.utils.encoding import from_utf8
|
|
from celery import VERSION_BANNER
|
|
from celery import VERSION_BANNER
|
|
from celery.five import items
|
|
from celery.five import items
|
|
from celery.platforms import Pidfile, IS_WINDOWS
|
|
from celery.platforms import Pidfile, IS_WINDOWS
|
|
-from celery.utils import term, nodesplit
|
|
|
|
|
|
+from celery.utils import term
|
|
|
|
+from celery.utils import host_format, node_format, nodesplit
|
|
from celery.utils.text import pluralize
|
|
from celery.utils.text import pluralize
|
|
|
|
|
|
__all__ = ['MultiTool']
|
|
__all__ = ['MultiTool']
|
|
@@ -247,8 +249,8 @@ class MultiTool(object):
|
|
self.retcode = int(any(retcodes))
|
|
self.retcode = int(any(retcodes))
|
|
|
|
|
|
def with_detacher_default_options(self, p):
|
|
def with_detacher_default_options(self, p):
|
|
- _setdefaultopt(p.options, ['--pidfile', '-p'], '%N.pid')
|
|
|
|
- _setdefaultopt(p.options, ['--logfile', '-f'], '%N.log')
|
|
|
|
|
|
+ _setdefaultopt(p.options, ['--pidfile', '-p'], '%n.pid')
|
|
|
|
+ _setdefaultopt(p.options, ['--logfile', '-f'], '%n.log')
|
|
p.options.setdefault(
|
|
p.options.setdefault(
|
|
'--cmd',
|
|
'--cmd',
|
|
'-m {0}'.format(celery_exe('worker', '--detach')),
|
|
'-m {0}'.format(celery_exe('worker', '--detach')),
|
|
@@ -320,7 +322,7 @@ class MultiTool(object):
|
|
self.note('')
|
|
self.note('')
|
|
|
|
|
|
def getpids(self, p, cmd, callback=None):
|
|
def getpids(self, p, cmd, callback=None):
|
|
- _setdefaultopt(p.options, ['--pidfile', '-p'], '%N.pid')
|
|
|
|
|
|
+ _setdefaultopt(p.options, ['--pidfile', '-p'], '%n.pid')
|
|
|
|
|
|
nodes = []
|
|
nodes = []
|
|
for node in multi_args(p, cmd):
|
|
for node in multi_args(p, cmd):
|
|
@@ -491,25 +493,27 @@ def multi_args(p, cmd='celery worker', append='', prefix='', suffix=''):
|
|
raise KeyError('No node at index %r' % (ns_name, ))
|
|
raise KeyError('No node at index %r' % (ns_name, ))
|
|
|
|
|
|
for name in names:
|
|
for name in names:
|
|
- this_suffix = suffix
|
|
|
|
|
|
+ hostname = suffix
|
|
if '@' in name:
|
|
if '@' in name:
|
|
- this_name = options['-n'] = name
|
|
|
|
- nodename, this_suffix = nodesplit(name)
|
|
|
|
- name = nodename
|
|
|
|
|
|
+ nodename = options['-n'] = host_format(name)
|
|
|
|
+ shortname, hostname = nodesplit(nodename)
|
|
|
|
+ name = shortname
|
|
else:
|
|
else:
|
|
- nodename = '%s%s' % (prefix, name)
|
|
|
|
- this_name = options['-n'] = '%s@%s' % (nodename, this_suffix)
|
|
|
|
- expand = abbreviations({'%h': this_name,
|
|
|
|
- '%n': name,
|
|
|
|
- '%N': nodename,
|
|
|
|
- '%d': this_suffix})
|
|
|
|
|
|
+ shortname = '%s%s' % (prefix, name)
|
|
|
|
+ nodename = options['-n'] = host_format(
|
|
|
|
+ '{0}@{1}'.format(shortname, hostname),
|
|
|
|
+ )
|
|
|
|
+
|
|
|
|
+ expand = partial(
|
|
|
|
+ node_format, nodename=nodename, N=shortname, d=hostname,
|
|
|
|
+ )
|
|
argv = ([expand(cmd)] +
|
|
argv = ([expand(cmd)] +
|
|
[format_opt(opt, expand(value))
|
|
[format_opt(opt, expand(value))
|
|
for opt, value in items(p.optmerge(name, options))] +
|
|
for opt, value in items(p.optmerge(name, options))] +
|
|
[passthrough])
|
|
[passthrough])
|
|
if append:
|
|
if append:
|
|
argv.append(expand(append))
|
|
argv.append(expand(append))
|
|
- yield multi_args_t(this_name, argv, expand, name)
|
|
|
|
|
|
+ yield multi_args_t(nodename, argv, expand, name)
|
|
|
|
|
|
|
|
|
|
class NamespacedOptionParser(object):
|
|
class NamespacedOptionParser(object):
|
|
@@ -591,18 +595,6 @@ def parse_ns_range(ns, ranges=False):
|
|
return ret
|
|
return ret
|
|
|
|
|
|
|
|
|
|
-def abbreviations(mapping):
|
|
|
|
-
|
|
|
|
- def expand(S):
|
|
|
|
- ret = S
|
|
|
|
- if S is not None:
|
|
|
|
- for short_opt, long_opt in items(mapping):
|
|
|
|
- ret = ret.replace(short_opt, long_opt)
|
|
|
|
- return ret
|
|
|
|
-
|
|
|
|
- return expand
|
|
|
|
-
|
|
|
|
-
|
|
|
|
def findsig(args, default=signal.SIGTERM):
|
|
def findsig(args, default=signal.SIGTERM):
|
|
for arg in reversed(args):
|
|
for arg in reversed(args):
|
|
if len(arg) == 2 and arg[0] == '-':
|
|
if len(arg) == 2 and arg[0] == '-':
|