Supervisor process exits with 'exit status 1; not expected'

I'm trying to run a gunicorn_django process in supervisor but it always exits immediately, giving this error:

INFO exited: my_app (exit status 1; not expected)
INFO received SIGCLD indicating a child quit
INFO gave up: my_app entered FATAL state, too many start retries too quickly

My server script looks like this:

#!/bin/bash
set -e
LOGFILE=/var/log/gunicorn/my_app.log
LOGDIR=$(dirname $LOGFILE)
NUM_WORKERS=3
USER=my-www-user
GROUP=my-www-user
cd /home/my-www-user/my_app
source /home/my-www-user/.virtualenvs/my_app/bin/activate
test -d $LOGDIR || mkdir -p $LOGDIR
gunicorn_django -w $NUM_WORKERS --debug \
 --user=$USER --group=$GROUP \
 --log-level=debug --log-file=$LOGFILE 2>>$LOGFILE\
 --pythonpath=my_app --settings=settings.active \
 my_app.wsgi:application

And my supervisor config looks like this:

[program:my_app]
directory=/home/my-www-user/my_app/
user=my-www-user
command=/home/my-www-user/my_app/server.sh
stdout_logfile=/var/log/supervisor/my_app.log
stderr_logfile=/var/log/supervisor/my_app-error.log
autostart=true
autorestart=true

When I su into the my-www-user account the server starts normally. When I do sudo supervisorctl start my_app it simply hangs until I do CTRL-c, then I find the error above in the supervisord.log file.

Does anyone have a clue about what I am missing?


Solution 1:

I seem to have found the solution. I can't have supervisor run my server script as the unprivileged my-www-user since it has to write to log files etc that requires more access. So the solution is to run the server as root and let gunicorn_django spawn the worker process as my-www-user

[program:my_app]
user=root
; rest of config follows

Solution 2:

I had this error trying to run ‍Celery, and I had exactly the opposite problem.

I changed my user from root to www-data and that solved it.