Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gunicorn not starting workers

When i run this command

[jenia@arch app]../bin/gunicorn zones.wsgi:application --bind localht:8000

The gunicorn server runs at localhost:8000. It doesnt return anything to the console as I assume it should. Just runs silently.

When I run my script in bin/gunicorn_start the server still runs silently and features odd behaviour. If I input an address that django can't resolve it gives me internal server error and that's it. no stack trace no nothing.

This is the bin/gunicorn_start script:

#!/bin/bash

NAME="hello_app" # Name of the application
DJANGODIR=/srv/http/proj05/app # Django project directory
SOCKFILE=/srv/http/proj05/app/run/gunicorn.sock # we will communicte using this unix socket
USER=jenia # the user to run as
GROUP=jenia # the group to run as
NUM_WORKERS=3 # how many worker processes should Gunicorn spawn
DJANGO_SETTINGS_MODULE=zones.settings # which settings file should Django use
DJANGO_WSGI_MODULE=zones.wsgi # WSGI module name

echo "Starting $NAME as `whoami`"

# Activate the virtual environment
cd $DJANGODIR
source activate
export DJANGO_SETTINGS_MODULE=$DJANGO_SETTINGS_MODULE
export PYTHONPATH=$DJANGODIR:$PYTHONPATH


# Create the run directory if it doesn't exist
RUNDIR=$(dirname $SOCKFILE)
test -d $RUNDIR || mkdir -p $RUNDIR



# Start your Django Unicorn
# Programs meant to be run under supervisor should not daemonize themselves (do not use --daemon)
echo "about to exec exec is" $DJANGO_WSGI_MODULE
exec ../bin/gunicorn ${DJANGO_WSGI_MODULE}:application \
--name $NAME \
--workers $NUM_WORKERS \
--user=$USER --group=$GROUP \
--log-level=debug \
--bind=unix:$SOCKFILE

By the way, I created a virtualen at by doing:

cd proj05
virtualenv .
source bin/activate
pip install django
pip install gunicorn
...

Can anyone tell me how to make gunicorn output the debug information instead of just internal server error?

Thanks in advance.

like image 706
Jenia Ivanov Avatar asked Jun 14 '14 17:06

Jenia Ivanov


People also ask

How do I know if Gunicorn is working?

You should receive the HTML output from your application in the terminal. This confirms that Gunicorn was started and able to serve your Django application. You can verify that the Gunicorn service is running by checking the status again: sudo systemctl status gunicorn.

How many workers does it take to set Gunicorn?

Gunicorn should only need 4-12 worker processes to handle hundreds or thousands of requests per second. Gunicorn relies on the operating system to provide all of the load balancing when handling requests. Generally we recommend (2 x $num_cores) + 1 as the number of workers to start off with.

How do I start Gunicorn service?

Running sudo -u www-data curl --unix-socket /run/gunicorn. sock http , our Gunicorn service will be automatically started and you should see some HTML from your server in the terminal.

How do Gunicorn workers work?

Gunicorn is based on the pre-fork worker model. This means that there is a central master process that manages a set of worker processes. The master never knows anything about individual clients. All requests and responses are handled completely by worker processes.


1 Answers

gunicorn doesn't return to the console by default now. Use the option --log-file=- to do it.

Also the error should be fixed in https://github.com/benoitc/gunicorn/issues/785 .

I will make a release tomorrow.

like image 200
benoitc Avatar answered Oct 22 '22 05:10

benoitc