【问题标题】:Gunicorn not found in virtualenv在 virtualenv 中找不到 Gunicorn
【发布时间】:2019-02-05 09:40:13
【问题描述】:

我正在部署一个 django 应用程序,当我手动运行它时它工作正常。我正在尝试使用主管,但是当我运行 sudo supervisorctl status botApp 时,日志文件显示:

Starting botApp as ubuntu
/home/ubuntu/gunicorn_start.bash: line 28: exec: gunicorn: not found

我的 gunicorn_start.bash 如下:

#!/bin/bash

NAME="botApp"                                   # Name of the application
DJANGODIR=/home/ubuntu/chimpy               # Django project directory
SOCKFILE=/home/ubuntu/django_env/run/gunicorn.sock  # we will communicte using this unix socket
USER=ubuntu                                         # the user to run as
GROUP=ubuntu                                        # the group to run as
NUM_WORKERS=3                                       # how many worker processes should Gunicorn spawn
DJANGO_SETTINGS_MODULE=botApp.settings      # which settings file should Django use
DJANGO_WSGI_MODULE=botApp.wsgi              # WSGI module name
echo "Starting $NAME as `whoami`"

# Activate the virtual environment

cd $DJANGODIR
source /home/ubuntu/django_env/bin/activate
export DJANGO_SETTINGS_MODULE=$DJANGO_SETTINGS_MODULE
export PYTHONPATH=$DJANGODIR:$PYTHONPATH

# Create the run directory if it doesn't exist

RUNDIR=$(dirname $SOCKFILE)
test -d $RUNDIR || mkdir -p $RUNDIR

# Start your Django Unicorn
# Programs meant to be run under supervisor should not daemonize themselves (do not use --daemon)

exec gunicorn ${DJANGO_WSGI_MODULE}:application \
  --name $NAME \
  --workers $NUM_WORKERS \
  --user=$USER --group=$GROUP \
  --bind=unix:$SOCKFILE \
  --log-level=debug \
  --log-file=-

而我在 /etc/supervisor/conf.d/botApp.conf 中的配置文件是:

[program:botApp]
command = /home/ubuntu/gunicorn_start.bash;
user = ubuntu;
stdout_logfile = /home/ubuntu/logs/gunicorn_supervisor.log;
redirect_stderr = true;
environment=LANG=en_US.UTF-8,LC_ALL=en_US.UTF-8;

我的 gunicorn bash 有什么问题吗?非常感谢

【问题讨论】:

  • 愚蠢的问题,但是您是否通过pip install gunicorn 安装了 gunicorn?
  • @GamesBrainiac 是的,我可以手动运行 gunicorn_start.bash,它显然工作正常
  • 如果您在 bash 脚本中使用/home/ubuntu/django_env/bin/gunicorn 而不是gunicorn,那么您应该不需要source 命令来激活虚拟环境。
  • 是的,这就是我的建议。
  • 成功了,谢谢! (再次:))

标签: python django deployment gunicorn supervisord


【解决方案1】:

检查虚拟环境是否处于活动状态。只需编写简单的脚本

#!bin/bash

source /var/www/html/project_env/bin/activate

然后运行命令 -> sudo bash 文件名.sh

如果您没有收到任何错误,则表明 venv 已激活

注意 - 您不会在终端或外壳上获得任何 venv 激活标记。

【讨论】:

    猜你喜欢
    • 2014-03-21
    • 1970-01-01
    • 2015-05-09
    • 2013-09-18
    • 2015-11-07
    • 1970-01-01
    • 1970-01-01
    • 2021-07-24
    相关资源
    最近更新 更多