@task
def start():
    """Start the Gunicorn process"""

    set_env_defaults()

    if gunicorn_running():
        puts(colors.red("Gunicorn is already running!"))
        return

    if 'gunicorn_wsgi_app' not in env:
        abort(colors.red('env.gunicorn_wsgi_app not defined'))

    with cd(env.remote_workdir):
        prefix = []
        if 'virtualenv_dir' in env:
            prefix.append('source %s/bin/activate' % env.virtualenv_dir)
        if 'django_settings_module' in env:
            prefix.append('export DJANGO_SETTINGS_MODULE=%s' %
                          env.django_settings_module)

        prefix_string = ' && '.join(prefix)
        if len(prefix_string) > 0:
            prefix_string += ' && '

        options = [
            '--daemon',
            '--pid %s' % env.gunicorn_pidpath,
            '--bind %s' % env.gunicorn_bind,
        ]
        if 'gunicorn_workers' in env:
            options.append('--workers %s' % env.gunicorn_workers)
        if 'gunicorn_worker_class' in env:
            options.append('--worker-class %s' % env.gunicorn_worker_class)
        options_string = ' '.join(options)

        if 'paster_config_file' in env:
            run('%s gunicorn_paster %s %s' % (prefix_string, options_string,
                                   env.paster_config_file))
        else:
            run('%s gunicorn %s %s' % (prefix_string, options_string,
                                   env.gunicorn_wsgi_app))

        if gunicorn_running():
            puts(colors.green("Gunicorn started."))
        else:
            abort(colors.red("Gunicorn wasn't started!"))
dataset/ETHPy150Open jarus/fabric-gunicorn/fabric_gunicorn.py/start/original