Reputation: 561
I have a django application on an Ubuntu server that is run with gunicorn and started/stopped with supervisor. I am migrating it to a new server that is running the same Ubuntu server OS. It has been working fine up until now when I've tried starting it with supervisor. When I try to start it it exits with ERROR (abnormal termination)
I'm using the exact same configuration files on my new server as I was on the old one and it's really bothering me why it's not working on the new server... I'll put some of my configs below as well as part of the supervisor log.
/etc/supervisor/supervisor.conf
; supervisor config file
[unix_http_server]
file=/var/run/supervisor.sock ; (the path to the socket file)
chmod=0766 ; sockef file mode (default 0700)
[supervisord]
logfile=/var/log/supervisor/supervisord.log ; (main log file;default $CWD/supervisord.log)
pidfile=/var/run/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
childlogdir=/var/log/supervisor ; ('AUTO' child log dir, default $TEMP)
loglevel=debug
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
[supervisorctl]
serverurl=unix:///var/run/supervisor.sock ; use a unix:// URL for a unix socket
[include]
files = /etc/supervisor/conf.d/*.conf
/etc/supervisor/conf.d/beta.conf
[program:beta]
command = /var/www/beta/myapp/bin/gunicorn_start
user = eli
stdout_logfile = /var/web-data/logs/beta/gunicorn_supervisor.log
redirect_stderr = true
/var/www/beta/myapp/bin/gunicorn_start
#!/bin/bash
source /var/www/beta/env/bin/activate
exec gunicorn -c /var/www/beta/myapp/bin/gunicorn_config.py myapp.wsgi
/var/www/beta/myapp/bin/gunicorn_config.py
command = '/var/www/beta/env/bin/gunicorn'
pythonpath = '/var/www/beta/myapp'
bind = '127.0.0.1:9000'
workers = 1
user = 'eli'
/var/log/supervisor/supervisord.log
http://pastebin.com/fAGdJMKg
/var/web-data/logs/beta/gunicorn_supervisor.log
empty
My next step would be to just wipe the new server clean and start from scratch again to see if that might solve my problem. This is really bothering me why two servers with the exact same configurations, one works and the other doesn't.
I have also tried changing the location of the socket file as well as adding user=eli
to the [supervisord]
block to no avail.
Lastly, if I run /var/www/beta/myapp/bin/gunicorn_start
from the command line as eli
it will run and I'm able to access my website. However when I sudo su
and then run it, it will pause like it's running (~1sec) and then exit. It doesn't print anything to the console nor add anything to the log file.
Upvotes: 0
Views: 3496
Reputation: 561
The problem was solved by running /var/www/beta/myapp/bin/gunicorn_start
line by line as root. The first source worked fine but it was the second line that was having trouble.
I then tried running gunicorn -c /var/www/beta/myapp/bin/gunicorn_config.py myapp.wsgi
and this was doing the same thing but stil not showing any errors. So then I ran gunicorn -c /var/www/beta/myapp/bin/gunicorn_config.py myapp.wsgi --preload
and found that it was raising a KeyError for an environment variable that I had in my settings. Then it all made sense. When I was running this as root, it didn't have the same environment variables as my normal user did.
And granted this was the only difference between my two servers. I decided to try out environment variables for my django secret key and database password. So I switched these to their actual values. Then ran sudo supervisorctl start beta
and it started perfectly fine.
Upvotes: 2