예제 #1
0
def validate_sieve(value):
    sieve_name = '%s.sieve' % hashlib.md5(value.encode('utf8')).hexdigest()
    path = os.path.join(settings.MAILBOXES_SIEVETEST_PATH, sieve_name)
    with open(path, 'w') as f:
        f.write(value)
    context = {
        'orchestra_root': paths.get_orchestra_dir()
    }
    sievetest = settings.MAILBOXES_SIEVETEST_BIN_PATH % context
    test = run(' '.join([sievetest, path, '/dev/null']), silent=True)
    if test.return_code:
        errors = []
        for line in test.stderr.decode('utf8').splitlines():
            error = re.match(r'^.*(line\s+[0-9]+:.*)', line)
            if error:
                errors += error.groups()
        raise ValidationError(' '.join(errors))
예제 #2
0
def validate_sieve(value):
    sieve_name = '%s.sieve' % hashlib.md5(value).hexdigest()
    path = os.path.join(settings.MAILBOXES_SIEVETEST_PATH, sieve_name)
    with open(path, 'wb') as f:
        f.write(value)
    context = {
        'orchestra_root': paths.get_orchestra_dir()
    }
    sievetest = settings.MAILBOXES_SIEVETEST_BIN_PATH % context
    try:
        test = run(' '.join([sievetest, path, '/dev/null']), display=False)
    except CommandError:
        errors = []
        for line in test.stderr.splitlines():
            error = re.match(r'^.*(line\s+[0-9]+:.*)', line)
            if error:
                errors += error.groups()
        raise ValidationError(' '.join(errors))
예제 #3
0
def validate_sieve(value):
    sieve_name = '%s.sieve' % hashlib.md5(value.encode('utf8')).hexdigest()
    test_path = os.path.join(settings.MAILBOXES_SIEVETEST_PATH, sieve_name)
    with open(test_path, 'w') as f:
        f.write(value)
    context = {'orchestra_root': paths.get_orchestra_dir()}
    sievetest = settings.MAILBOXES_SIEVETEST_BIN_PATH % context
    try:
        test = run(' '.join([sievetest, test_path, '/dev/null']), silent=True)
    finally:
        os.unlink(test_path)
    if test.exit_code:
        errors = []
        for line in test.stderr.decode('utf8').splitlines():
            error = re.match(r'^.*(line\s+[0-9]+:.*)', line)
            if error:
                errors += error.groups()
        raise ValidationError(' '.join(errors))
예제 #4
0
    def handle(self, *args, **options):
        context = {
            'site_dir': get_site_dir(),
            'username': options.get('username'),
            'bin_path': path.join(get_orchestra_dir(), 'bin'),
            'processes': options.get('processes'),
            'settings': path.join(get_project_dir(), 'settings.py')
        }

        celery_config = textwrap.dedent("""\
            # Name of nodes to start, here we have a single node
            CELERYD_NODES="w1"
            
            # Where to chdir at start.
            CELERYD_CHDIR="%(site_dir)s"
            
            # How to call "manage.py celeryd_multi"
            CELERYD_MULTI="python3 $CELERYD_CHDIR/manage.py celeryd_multi"
            
            # Extra arguments to celeryd
            CELERYD_OPTS="-P:w1 processes -c:w1 %(processes)s -Q:w1 celery"
            
            # Name of the celery config module.
            CELERY_CONFIG_MODULE="celeryconfig"
            
            # %%n will be replaced with the nodename.
            CELERYD_LOG_FILE="/var/log/celery/%%n.log"
            CELERYD_PID_FILE="/var/run/celery/%%n.pid"
            CELERY_CREATE_DIRS=1
            
            # Full path to the celeryd logfile.
            CELERYEV_LOG_FILE="/var/log/celery/celeryev.log"
            CELERYEV_PID_FILE="/var/run/celery/celeryev.pid"
            
            # Workers should run as an unprivileged user.
            CELERYD_USER="******"
            CELERYD_GROUP="$CELERYD_USER"
            
            # Persistent revokes
            CELERYD_STATE_DB="$CELERYD_CHDIR/persistent_revokes"
            
            # Celeryev
            CELERYEV="python3 $CELERYD_CHDIR/manage.py"
            CELERYEV_CAM="djcelery.snapshot.Camera"
            CELERYEV_USER="******"
            CELERYEV_GROUP="$CELERYD_USER"
            CELERYEV_OPTS="celerycam"
            
            # Celerybeat
            CELERYBEAT="python3 ${CELERYD_CHDIR}/manage.py celerybeat"
            CELERYBEAT_USER="******"
            CELERYBEAT_GROUP="$CELERYD_USER"
            CELERYBEAT_CHDIR="$CELERYD_CHDIR"
            CELERYBEAT_OPTS="--schedule=/var/run/celerybeat-schedule --scheduler=djcelery.schedulers.DatabaseScheduler"
            """ % context)

        run("echo '%s' > /etc/default/celeryd" % celery_config)

        # https://raw.github.com/celery/celery/master/extra/generic-init.d/
        for script in ['celeryevcam', 'celeryd', 'celerybeat']:
            context['script'] = script
            run('cp %(bin_path)s/%(script)s /etc/init.d/%(script)s' % context)
            run('chmod +x /etc/init.d/%(script)s' % context)
            run('update-rc.d %(script)s defaults' % context)

        rotate = textwrap.dedent("""\
            /var/log/celery/*.log {
                weekly
                missingok
                rotate 10
                compress
                delaycompress
                notifempty
                copytruncate
            }""")
        run("echo '%s' > /etc/logrotate.d/celeryd" % rotate)

        changes = {}
        if Setting.settings['TASKS_BACKEND'].value != 'celery':
            changes['TASKS_BACKEND'] = 'celery'
        if Setting.settings[
                'ORCHESTRA_START_SERVICES'].value == Setting.settings[
                    'ORCHESTRA_START_SERVICES'].default:
            changes['ORCHESTRA_START_SERVICES'] = (
                'postgresql',
                'celeryevcam',
                'celeryd',
                'celerybeat',
                ('uwsgi', 'nginx'),
            )
        if Setting.settings[
                'ORCHESTRA_RESTART_SERVICES'].value == Setting.settings[
                    'ORCHESTRA_RESTART_SERVICES'].default:
            changes['ORCHESTRA_RESTART_SERVICES'] = (
                'celeryd',
                'celerybeat',
                'uwsgi',
            )
        if Setting.settings[
                'ORCHESTRA_STOP_SERVICES'].value == Setting.settings[
                    'ORCHESTRA_STOP_SERVICES'].default:
            changes['ORCHESTRA_STOP_SERVICES'] = (('uwsgi', 'nginx'),
                                                  'celerybeat', 'celeryd',
                                                  'celeryevcam', 'postgresql')
        if changes:
            settings_parser.apply(changes)
예제 #5
0
 def handle(self, *filenames, **options):
     flake = run('flake8 {%s,%s} | grep -v "W293\|E501"' % (get_orchestra_dir(), get_site_dir()))
     self.stdout.write(flake.stdout.decode('utf8'))
예제 #6
0
 def handle(self, *filenames, **options):
     flake = run('flake8 {%s,%s} | grep -v "W293\|E501"' %
                 (get_orchestra_dir(), get_site_dir()))
     self.stdout.write(flake.stdout.decode('utf8'))
예제 #7
0
 def handle(self, *args, **options):
     context = {
         'site_dir': get_site_dir(),
         'username': options.get('username'),
         'bin_path': path.join(get_orchestra_dir(), 'bin'),
         'processes': options.get('processes'),
     }
     
     celery_config = textwrap.dedent("""\
         # Name of nodes to start, here we have a single node
         CELERYD_NODES="w1"
         
         # Where to chdir at start.
         CELERYD_CHDIR="%(site_dir)s"
         
         # How to call "manage.py celeryd_multi"
         CELERYD_MULTI="python3 $CELERYD_CHDIR/manage.py celeryd_multi"
         
         # Extra arguments to celeryd
         CELERYD_OPTS="-P:w1 processes -c:w1 %(processes)s -Q:w1 celery"
         
         # Name of the celery config module.
         CELERY_CONFIG_MODULE="celeryconfig"
         
         # %%n will be replaced with the nodename.
         CELERYD_LOG_FILE="/var/log/celery/%%n.log"
         CELERYD_PID_FILE="/var/run/celery/%%n.pid"
         CELERY_CREATE_DIRS=1
         
         # Full path to the celeryd logfile.
         CELERYEV_LOG_FILE="/var/log/celery/celeryev.log"
         CELERYEV_PID_FILE="/var/run/celery/celeryev.pid"
         
         # Workers should run as an unprivileged user.
         CELERYD_USER="******"
         CELERYD_GROUP="$CELERYD_USER"
         
         # Persistent revokes
         CELERYD_STATE_DB="$CELERYD_CHDIR/persistent_revokes"
         
         # Celeryev
         CELERYEV="python3 $CELERYD_CHDIR/manage.py"
         CELERYEV_CAM="djcelery.snapshot.Camera"
         CELERYEV_USER="******"
         CELERYEV_GROUP="$CELERYD_USER"
         CELERYEV_OPTS="celerycam"
         
         # Celerybeat
         CELERYBEAT="python3 ${CELERYD_CHDIR}/manage.py celerybeat"
         CELERYBEAT_USER="******"
         CELERYBEAT_GROUP="$CELERYD_USER"
         CELERYBEAT_CHDIR="$CELERYD_CHDIR"
         CELERYBEAT_OPTS="--schedule=/var/run/celerybeat-schedule --scheduler=djcelery.schedulers.DatabaseScheduler"
         """ % context
     )
     
     run("echo '%s' > /etc/default/celeryd" % celery_config)
     
     # https://raw.github.com/celery/celery/master/extra/generic-init.d/
     for script in ['celeryevcam', 'celeryd', 'celerybeat']:
         context['script'] = script
         run('cp %(bin_path)s/%(script)s /etc/init.d/%(script)s' % context)
         run('chmod +x /etc/init.d/%(script)s' % context)
         run('update-rc.d %(script)s defaults' % context)
     
     rotate = textwrap.dedent("""\
         /var/log/celery/*.log {
             weekly
             missingok
             rotate 10
             compress
             delaycompress
             notifempty
             copytruncate
         }"""
     )
     run("echo '%s' > /etc/logrotate.d/celeryd" % rotate)