简体   繁体   English

主管不开枪

[英]Supervisor not starting gunicorn

I have a django application on an Ubuntu server that is run with gunicorn and started/stopped with supervisor. 我在使用gunicorn运行并由主管启动/停止的Ubuntu服务器上有一个django应用程序。 I am migrating it to a new server that is running the same Ubuntu server OS. 我正在将其迁移到运行相同Ubuntu服务器操作系统的新服务器。 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. 当我尝试启动它时,它退出并显示ERROR (abnormal termination)我在新服务器上使用的配置文件与旧服务器上使用的配置文件完全相同,这真的让我感到困扰,为什么它在新服务器上不起作用...我将在下面以及我的主管日志中放置一些配置。

/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/log/supervisor/supervisord.log http://pastebin.com/fAGdJMKg

/var/web-data/logs/beta/gunicorn_supervisor.log empty /var/web-data/logs/beta/gunicorn_supervisor.log

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. 我也尝试过更改套接字文件的位置,以及将user=eli添加到[supervisord]块中均无济于事。

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. 最后,如果我像eli一样从命令行运行/var/www/beta/myapp/bin/gunicorn_start ,它将运行,并且我可以访问我的网站。 However when I sudo su and then run it, it will pause like it's running (~1sec) and then exit. 但是,当我sudo su然后运行它时,它将像正在运行时一样暂停(〜1秒),然后退出。 It doesn't print anything to the console nor add anything to the log file. 它既不打印任何内容到控制台,也不添加任何内容到日志文件。

The problem was solved by running /var/www/beta/myapp/bin/gunicorn_start line by line as root. 通过以root /var/www/beta/myapp/bin/gunicorn_start逐行运行/var/www/beta/myapp/bin/gunicorn_start解决了该问题。 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. 然后,我尝试运行gunicorn -c /var/www/beta/myapp/bin/gunicorn_config.py myapp.wsgi ,这样做是在做相同的事情,但没有显示任何错误。 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. 因此,然后我运行了gunicorn -c /var/www/beta/myapp/bin/gunicorn_config.py myapp.wsgi --preload ,发现它正在为设置中的环境变量gunicorn -c /var/www/beta/myapp/bin/gunicorn_config.py myapp.wsgi --preload 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. 当我以root用户身份运行时,它没有与普通用户相同的环境变量。

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. 我决定尝试为我的Django秘密密钥和数据库密码尝试环境变量。 So I switched these to their actual values. 因此,我将其切换为实际值。 Then ran sudo supervisorctl start beta and it started perfectly fine. 然后运行sudo supervisorctl start beta ,它开始运行正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM