Changeset - 1d539bb18165
[Not reviewed]
default
1 4 1
Thomas De Schampheleire - 7 years ago 2018-11-18 20:02:17
thomas.de_schampheleire@nokia.com
cli: convert 'gearbox celeryd' into 'kallithea-cli celery-run'

Note:
- '--' is never explicitly present in the arguments when using Click.
The click parser will take care of '--' as separator between
dash-dash-arguments and positional arguments, following standard UNIX
conventions.
5 files changed with 28 insertions and 27 deletions:
0 comments (0 inline, 0 general)
docs/setup.rst
Show inline comments
 
@@ -286,49 +286,49 @@ Kallithea can use the distributed task q
 
cloning repositories or sending emails.
 

	
 
Kallithea will in most setups work perfectly fine out of the box (without
 
Celery), executing all tasks in the web server process. Some tasks can however
 
take some time to run and it can be better to run such tasks asynchronously in
 
a separate process so the web server can focus on serving web requests.
 

	
 
For installation and configuration of Celery, see the `Celery documentation`_.
 
Note that Celery requires a message broker service like RabbitMQ_ (recommended)
 
or Redis_.
 

	
 
The use of Celery is configured in the Kallithea ini configuration file.
 
To enable it, simply set::
 

	
 
  use_celery = true
 

	
 
and add or change the ``celery.*`` and ``broker.*`` configuration variables.
 

	
 
Remember that the ini files use the format with '.' and not with '_' like
 
Celery. So for example setting `BROKER_HOST` in Celery means setting
 
`broker.host` in the configuration file.
 

	
 
To start the Celery process, run::
 

	
 
  gearbox celeryd -c my.ini
 
  kallithea-cli celery-run -c my.ini
 

	
 
Extra options to the Celery worker can be passed after ``--`` - see ``-- -h``
 
for more info.
 

	
 
.. note::
 
   Make sure you run this command from the same virtualenv, and with the same
 
   user that Kallithea runs.
 

	
 

	
 
HTTPS support
 
-------------
 

	
 
Kallithea will by default generate URLs based on the WSGI environment.
 

	
 
Alternatively, you can use some special configuration settings to control
 
directly which scheme/protocol Kallithea will use when generating URLs:
 

	
 
- With ``https_fixup = true``, the scheme will be taken from the
 
  ``X-Url-Scheme``, ``X-Forwarded-Scheme`` or ``X-Forwarded-Proto`` HTTP header
 
  (default ``http``).
 
- With ``force_https = true`` the default will be ``https``.
 
- With ``use_htsts = true``, Kallithea will set ``Strict-Transport-Security`` when using https.
 

	
 
.. _nginx_virtual_host:
init.d/celeryd-upstart.conf
Show inline comments
 
# celeryd - run the celeryd daemon as an upstart job for kallithea
 
# Change variables/paths as necessary and place file /etc/init/celeryd.conf
 
# start/stop/restart as normal upstart job (ie: $ start celeryd)
 

	
 
description     "Celery for Kallithea Mercurial Server"
 
author          "Matt Zuba <matt.zuba@goodwillaz.org"
 

	
 
start on starting kallithea
 
stop on stopped kallithea
 

	
 
respawn
 

	
 
umask 0022
 

	
 
env PIDFILE=/tmp/celeryd.pid
 
env APPINI=/var/hg/kallithea/production.ini
 
env HOME=/var/hg
 
env USER=hg
 
# To use group (if different from user), you must edit sudoers file and change
 
# root's entry from (ALL) to (ALL:ALL)
 
# env GROUP=hg
 

	
 
script
 
    COMMAND="/var/hg/.virtualenvs/kallithea/bin/gearbox celeryd -c $APPINI -- --pidfile=$PIDFILE"
 
    COMMAND="/var/hg/.virtualenvs/kallithea/bin/kallithea-cli celery-run -c $APPINI -- --pidfile=$PIDFILE"
 
    if [ -z "$GROUP" ]; then
 
        exec sudo -u $USER $COMMAND
 
    else
 
        exec sudo -u $USER -g $GROUP $COMMAND
 
    fi
 
end script
 

	
 
post-stop script
 
    rm -f $PIDFILE
 
end script
kallithea/bin/kallithea_cli.py
Show inline comments
 
# -*- coding: utf-8 -*-
 
# This program is free software: you can redistribute it and/or modify
 
# it under the terms of the GNU General Public License as published by
 
# the Free Software Foundation, either version 3 of the License, or
 
# (at your option) any later version.
 
#
 
# This program is distributed in the hope that it will be useful,
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
# GNU General Public License for more details.
 
#
 
# You should have received a copy of the GNU General Public License
 
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 

	
 
# 'cli' is the main entry point for 'kallithea-cli', specified in setup.py as entry_points console_scripts
 
from kallithea.bin.kallithea_cli_base import cli
 

	
 
# import commands (they will add themselves to the 'cli' object)
 
import kallithea.bin.kallithea_cli_celery
 
import kallithea.bin.kallithea_cli_config
 
import kallithea.bin.kallithea_cli_db
 
import kallithea.bin.kallithea_cli_extensions
 
import kallithea.bin.kallithea_cli_iis
 
import kallithea.bin.kallithea_cli_index
 
import kallithea.bin.kallithea_cli_ishell
 
import kallithea.bin.kallithea_cli_repo
kallithea/bin/kallithea_cli_celery.py
Show inline comments
 
file renamed from kallithea/lib/paster_commands/celeryd.py to kallithea/bin/kallithea_cli_celery.py
 
# -*- coding: utf-8 -*-
 
# This program is free software: you can redistribute it and/or modify
 
# it under the terms of the GNU General Public License as published by
 
# the Free Software Foundation, either version 3 of the License, or
 
# (at your option) any later version.
 
#
 
# This program is distributed in the hope that it will be useful,
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
# GNU General Public License for more details.
 
#
 
# You should have received a copy of the GNU General Public License
 
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 

	
 
import argparse
 
import click
 
import kallithea.bin.kallithea_cli_base as cli_base
 

	
 
import kallithea
 
from kallithea.lib.paster_commands.common import BasePasterCommand
 

	
 
__all__ = ['Command']
 

	
 
@cli_base.register_command(config_file_initialize_app=True)
 
@click.argument('celery_args', nargs=-1)
 
def celery_run(celery_args):
 
    """Start Celery worker(s) for asynchronous tasks.
 

	
 
class Command(BasePasterCommand):
 
    """Kallithea: Celery worker for asynchronous tasks"""
 
    This commands starts the Celery daemon which will spawn workers to handle
 
    certain asynchronous tasks for Kallithea.
 

	
 
    # Starts the celery worker using configuration from a paste.deploy
 
    # configuration file.
 
    Any extra arguments you pass to this command will be passed through to
 
    Celery. Use '--' before such extra arguments to avoid options to be parsed
 
    by this CLI command.
 
    """
 

	
 
    def take_action(self, args):
 
        if not kallithea.CELERY_ON:
 
            raise Exception('Please set use_celery = true in .ini config '
 
                            'file before running celeryd')
 
                        'file before running this command')
 

	
 
        from kallithea.lib import celerypylons
 
        cmd = celerypylons.worker.worker(celerypylons.app)
 

	
 
        celery_args = args.celery_args
 
        if '--' in celery_args:
 
            celery_args.remove('--')
 

	
 
        return cmd.run_from_argv('kallithea celery worker', celery_args)
 

	
 
    def get_parser(self, prog_name):
 
        parser = super(Command, self).get_parser(prog_name)
 

	
 
        parser.add_argument('celery_args', nargs=argparse.REMAINDER,
 
            help="Pass extra options to Celery after a '--' separator",
 
            )
 

	
 
        return parser
setup.py
Show inline comments
 
@@ -138,28 +138,27 @@ setuptools.setup(
 
    dependency_links=dependency_links,
 
    url=__url__,
 
    install_requires=requirements,
 
    classifiers=classifiers,
 
    data_files=data_files,
 
    packages=packages,
 
    include_package_data=True,
 
    message_extractors={'kallithea': [
 
            ('**.py', 'python', None),
 
            ('templates/**.mako', 'mako', {'input_encoding': 'utf-8'}),
 
            ('templates/**.html', 'mako', {'input_encoding': 'utf-8'}),
 
            ('public/**', 'ignore', None)]},
 
    zip_safe=False,
 
    entry_points="""
 
    [console_scripts]
 
    kallithea-api =    kallithea.bin.kallithea_api:main
 
    kallithea-gist =   kallithea.bin.kallithea_gist:main
 
    kallithea-config = kallithea.bin.kallithea_config:main
 
    kallithea-cli =    kallithea.bin.kallithea_cli:cli
 

	
 
    [paste.app_factory]
 
    main = kallithea.config.middleware:make_app
 

	
 
    [gearbox.commands]
 
    celeryd=kallithea.lib.paster_commands.celeryd:Command
 
    upgrade-db=kallithea.lib.dbmigrate:UpgradeDb
 
    """,
 
)
0 comments (0 inline, 0 general)