[英]Gunicorn and Django with Upstart and Nginx
First of all I have many Django instances setup and running like this. 首先,我有许多Django实例设置并运行如下。
In each project I have a script.sh shell script that starts gunicorn etc.: 在每个项目中,我都有一个script.sh shell脚本,可以启动gunicorn等:
#!/bin/bash
set -e
LOGFILE=/var/log/gunicorn/app_name.log
LOGDIR=$(dirname $LOGFILE)
NUM_WORKERS=3
# user/group to run as
USER=root
GROUP=root
PORT=8060
IP=127.0.0.1
cd /var/www/webapps/app_name
source ../bin/activate
test -d $LOGDIR || mkdir -p $LOGDIR
exec /var/www/webapps/bin/gunicorn_django -b $IP:$PORT -w $NUM_WORKERS \
--user=$USER --group=$GROUP --log-level=debug --log-file=$LOGFILE 2>>$LOGFILE
When running this script from the command line with bash script.sh , the site works perfectly, so Nginx is setup right. 当使用bash script.sh从命令行运行此脚本时,该站点运行正常,因此Nginx设置正确。
As soon as I use upstart with service app_name start the app starts and then just stops. 一旦我使用upstart与服务app_name启动应用程序启动,然后停止。 It does not even write to the log file.
它甚至没有写入日志文件。
This is the app_name.conf file in /etc/init/app_name.conf : 这是/etc/init/app_name.conf中的app_name.conf文件:
description "Test Django instance"
start on runlevel [2345]
stop on runlevel [06]
respawn
respawn limit 10 5
exec /var/www/webapps/app_name/script.sh
So what is the problem here? 那么这里的问题是什么? Cause running from command line works, but doing trough upstart does not.
导致从命令行运行,但执行低谷新手不会。 And I dont know where to see whats wrong?
我不知道哪里看错了什么?
Well, I figured it out. 好吧,我明白了。 If any one ever run into something like this...
如果有人碰到这样的事情......
Its basically a lack of knowledge about shell scripts that was holding me back. 它基本上缺乏关于shell脚本的知识,这些知识阻碍了我。
After commenting out each line o the script file i found the problem with the line : source ../bin/activate and all after that. 在注释掉脚本文件的每一行后,我发现了行的问题: source ../bin/activate以及之后的所有行。
The problem was that it had 2 spaces on front of it, and now I know it needs to be left aligned all the way. 问题是它前面有2个空格,现在我知道它需要一直保持对齐。 Now it works.
现在它有效。
This is how i figured it out: 这就是我弄清楚的方式:
tail -f /var/log/syslog
Jun 26 10:54:59 saturn7 init: app_name main process (3521) terminated with status 127
I found out that status 127 is basically a command that is not found. 我发现状态127基本上是一个找不到的命令。 So I know the problem was actually in the script file.
所以我知道问题实际上是在脚本文件中。
But I am not sure why bash ./script.sh would work and not tell me anything is wrong? 但我不确定为什么bash ./script.sh会工作,而不是告诉我什么是错的? I need to read up about schell scripts..
我需要阅读有关schell脚本的信息..
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.