Django项目未找到错误

时间:2014-04-02 11:23:33

标签: python django gunicorn

我收到错误:当我尝试在下面运行我的bash脚本时找不到django项目,为什么?

这有效:gunicorn wsgi:application -b 127.0.0.1:8003

此错误:bash start_gunicorn.sh

start_gunicorn.sh:

#!/bin/bash

set -e

LOGFILE=/srv/domain/logs/domain.log

ERRORFILE=/srv/domain/logs/error.log

LOGDIR=$(dirname $LOGFILE)

NUM_WORKERS=3

#The below address:port info will be used later to configure Nginx with Gunicorn

ADDRESS=127.0.0.1:8003

# user/group to run as

#USER=your_unix_user

#GROUP=your_unix_group

cd /srv/domain

test -d $LOGDIR || mkdir -p $LOGDIR

exec gunicorn_django -w $NUM_WORKERS --bind=$ADDRESS \

--log-level=debug \

--log-file=$LOGFILE 2>>$LOGFILE  1>>$ERRORFILE  &

我需要告诉它项目在哪里吗?这是什么设置?

堆栈:

  File "/usr/local/lib/python2.7/dist-packages/gunicorn/app/djangoapp.py", line 62, in make_default_env
    raise RuntimeError("django project not found")
RuntimeError: django project not found
2014-04-02 10:13:56 [1038] [INFO] Worker exiting (pid: 1038)
Traceback (most recent call last):
  File "/usr/local/bin/gunicorn_django", line 9, in <module>
    load_entry_point('gunicorn==18.0', 'console_scripts', 'gunicorn_django')()
  File "/usr/local/lib/python2.7/dist-packages/gunicorn/app/djangoapp.py", line 160, in run
    DjangoApplication("%(prog)s [OPTIONS] [SETTINGS_PATH]").run()
  File "/usr/local/lib/python2.7/dist-packages/gunicorn/app/base.py", line 143, in run
    Arbiter(self).run()
  File "/usr/local/lib/python2.7/dist-packages/gunicorn/arbiter.py", line 203, in run
    self.halt(reason=inst.reason, exit_status=inst.exit_status)
  File "/usr/local/lib/python2.7/dist-packages/gunicorn/arbiter.py", line 298, in halt
    self.stop()
  File "/usr/local/lib/python2.7/dist-packages/gunicorn/arbiter.py", line 341, in stop
    self.reap_workers()
  File "/usr/local/lib/python2.7/dist-packages/gunicorn/arbiter.py", line 452, in reap_workers
    raise HaltServer(reason, self.WORKER_BOOT_ERROR)
gunicorn.errors.HaltServer: <HaltServer 'Worker failed to boot.' 3>
ubuntu@ip-10-37-235-227:/srv/domain$ sudo nano start_gunicorn.sh

项目文件夹示例:Ubuntu

/srv/domain/manage.py
/srv/domain/wsgi.py
/srv/domain/project_folder/
/srv/domain/project_folder/apps/
/srv/domain/project_folder/core/
/srv/domain/project_folder/core/urls.py

etc

1 个答案:

答案 0 :(得分:2)

在bash脚本中,只需编写以下脚本即可运行django项目:

#!/bin/bash
gunicorn /srv/domain/wsgi.py

它将在默认端口运行。如果要添加日志记录,工作线程和自定义端口,则可以使用gunicorn cmd参数指定。见Gunicorn Ref

现在正在制作中,您不希望每次都运行此脚本。所以你可以把它放在/etc/init.d/中。所以它会在启动时运行。见Ref