diff --git a/server/website/website/management/commands/startcelery.py b/server/website/website/management/commands/startcelery.py index 5e235b1..d04b93e 100644 --- a/server/website/website/management/commands/startcelery.py +++ b/server/website/website/management/commands/startcelery.py @@ -80,15 +80,14 @@ class Command(BaseCommand): self.stdout = open(os.devnull, 'w') # Stealth option that assigns where to pipe initial output - pipe = options.get('pipe', None) - if pipe is None: - pipe = '> /dev/null 2>&1' - try: - if 'celery' in settings.LOGGING['loggers']['celery']['handlers']: - logfile = settings.LOGGING['handlers']['celery']['filename'] + pipe = options.get('pipe', '') + if not pipe: + handler_names = settings.LOGGING.get('loggers', {}).get('celery', {}).get('handlers', []) + if 'console' not in handler_names and 'celery' in handler_names: + logfile = settings.LOGGING.get('handlers', {}).get('celery', {}).get('filename', None) + if logfile: pipe = '>> {} 2>&1'.format(logfile) - except KeyError: - pass + pipe = pipe or '' loglevel = options['loglevel'] or ('DEBUG' if settings.DEBUG else 'INFO') celery_options = [ @@ -101,7 +100,7 @@ class Command(BaseCommand): '--pidfile={}'.format(options['celerybeat_pidfile']), ] + self._parse_suboptions(options['celerybeat_options']) - with lcd(settings.PROJECT_ROOT), hide('commands'): # pylint: disable=not-context-manager + with lcd(settings.PROJECT_ROOT): # pylint: disable=not-context-manager if not options['celerybeat_only']: local(self.celery_cmd( cmd='celery worker', opts=' '.join(celery_options), pipe=pipe)) diff --git a/server/website/website/management/commands/stopcelery.py b/server/website/website/management/commands/stopcelery.py index e528755..8ecaae9 100644 --- a/server/website/website/management/commands/stopcelery.py +++ b/server/website/website/management/commands/stopcelery.py @@ -39,7 +39,7 @@ class Command(BaseCommand): check_pidfiles.append((name, pidfile)) except Exception as e: # pylint: disable=broad-except self.stdout.write(self.style.NOTICE( - "ERROR: an exception occurred while stopping '{}':\n{}\n".format(name, e))) + "WARNING: an exception occurred while stopping '{}': {}\n".format(name, e))) if check_pidfiles: self.stdout.write("Waiting for processes to shutdown...\n") @@ -49,9 +49,12 @@ class Command(BaseCommand): time.sleep(1) wait_sec += 1 if os.path.exists(pidfile): - self.stdout.write(self.style.NOTICE( - "WARNING: file '{}' still exists after stopping {}.".format( + self.stdout.write(self.style.NOTICE(( + "WARNING: file '{}' still exists after stopping {}. " + "Removing it manually.").format( pidfile, name))) + with quiet(): + local('rm -f {}'.format(pidfile)) else: self.stdout.write(self.style.SUCCESS( "Successfully stopped '{}'.".format(name))) @@ -59,4 +62,3 @@ class Command(BaseCommand): with quiet(): local("ps auxww | grep '[c]elery worker' | awk '{print $2}' | xargs kill -9") local("ps auxww | grep '[c]elerybeat' | awk '{print $2}' | xargs kill -9") - local('rm -f {} {}'.format(options['celery_pidfile'], options['celerybeat_pidfile']))