为什么 gunicorn 没有创建 .sock 或 .pid 文件?

为什么 gunicorn 没有创建 .sock 或 .pid 文件?

首先,我想澄清一下,我完全了解服务器调试和一般部署。我是我所在大学的一名学生开发人员,到目前为止,我的所有工作都与编程有关,但我被赋予了团队的部署职责。

我正在尝试使用 gunicorn 和 wsgi 部署我们的 Django 应用程序。我的前任老板(不再与我们合作)编写了这个 init 脚本,该脚本应该启动 wsgi 服务器:

#! /bin/sh
# Do NOT "set -e"


# PATH should only include /usr/* if it runs after the mountnfs.sh script
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/usr/sbin:/bin:/usr/bin
PIDFILE=/tmp/site.edu.pid
PROJECT_DIR=/opt/project_name
PROC_NAME="project_name"
NAME=$PROC_NAME
VENV=/opt/envs/project_name
SOCK=/tmp/site.edu.sock
CMD="gunicorn project_name.wsgi:application --pid $PIDFILE --bind unix:$SOCK --workers 9 --name $PROC_NAME --preload --daemon --timeout 300 --error-logfile '-' --log-file '-'"
USER="www-data"

. $VENV/bin/activate;

# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh

# Define LSB log_* functions.
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
. /lib/lsb/init-functions

#
# Function that starts the daemon/service
#
do_start()
{
    # Return
    #   0 if daemon has been started
    #   1 if daemon was already running
    #   2 if daemon could not be started
    if [ -e $PIDFILE ]; then
      return 1
    fi
    cd $PROJECT_DIR
    . $VENV/bin/activate
    $CMD
    if [ $? = 0 ]; then
      return 0
    else
      return 2
    fi

    sleep 1;
    chown $USER:nogroup $SOCK;
    chmod 660 $SOCK;

}

据我了解,这应该运行 gunicorn 并在 /tmp 目录中创建一个 unix 套接字和 pidfile,然后启动服务器运行,但情况似乎并非如此,因为这些文件不在 /tmp 目录中(导致我们的 nginx 配置中出现 502 错误网关)。

我还应该注意,这在 Python 2 虚拟环境中有效(因为它们以前都是使用 python 2 部署的),但在 python 3 虚拟环境中无效(在服务器上),但它在 python3 虚拟环境中本地有效。

此外,我确实有一个站点使用 Python 3 和此配置成功运行,但我似乎无法弄清楚为什么其他站点不能运行(因为它们的虚拟环境都有相同的要求和 gunicorn 版本gunicorn==20.0.4

如上所述,我对服务器的了解非常有限,我正在努力学习最好的知识。如果有人可以提供任何调试技巧。

这是我运行时的输出systemctl status working-site.edu.service

working-site.edu.service - LSB: working_project initscript
   Loaded: loaded (/etc/init.d/working-site.edu.sh; generated)
   Active: active (running) since Tue 2020-07-14 17:04:44 EDT; 1 day 19h ago
     Docs: man:systemd-sysv-generator(8)
    Tasks: 10 (limit: 4638)
   CGroup: /system.slice/working-site.edu.service
           ├─27489 /opt/envs/working_project/bin/python3.6 /opt/envs/working_project/bin/gunicorn working_project.wsgi:application --pid
           ├─27493 /opt/envs/working_project/bin/python3.6 /opt/envs/working_project/bin/gunicorn working_project.wsgi:application --pid
           ├─27494 /opt/envs/working_project/bin/python3.6 /opt/envs/working_project/bin/gunicorn working_project.wsgi:application --pid
           ├─27495 /opt/envs/working_project/bin/python3.6 /opt/envs/working_project/bin/gunicorn working_project.wsgi:application --pid
           ├─27496 /opt/envs/working_project/bin/python3.6 /opt/envs/working_project/bin/gunicorn working_project.wsgi:application --pid
           ├─27497 /opt/envs/working_project/bin/python3.6 /opt/envs/working_project/bin/gunicorn working_project.wsgi:application --pid
           ├─27498 /opt/envs/working_project/bin/python3.6 /opt/envs/working_project/bin/gunicorn working_project.wsgi:application --pid
           ├─27499 /opt/envs/working_project/bin/python3.6 /opt/envs/working_project/bin/gunicorn working_project.wsgi:application --pid
           ├─27500 /opt/envs/working_project/bin/python3.6 /opt/envs/working_project/bin/gunicorn working_project.wsgi:application --pid
           └─27501 /opt/envs/working_project/bin/python3.6 /opt/envs/working_project/bin/gunicorn working_project.wsgi:application --pid

Jul 14 17:04:44 staging-server systemd[1]: Starting LSB: working_project initscript...
Jul 14 17:04:44 staging-server systemd[1]: Started LSB: working_project initscript.

当我跑步时systemctl status broken-site.edu.service

broken-site.edu.service - LSB: broken_project initscript
   Loaded: loaded (/etc/init.d/broken-site.edu.sh; generated)
   Active: active (exited) since Thu 2020-07-16 12:51:26 EDT; 15min ago
     Docs: man:systemd-sysv-generator(8)
  Process: 32425 ExecStart=/etc/init.d/broken-site.edu.sh start (code=exited, status=0/SUCCESS)

Jul 16 12:51:26 staging-server systemd[1]: Starting LSB: broken_project initscript...
Jul 16 12:51:26 staging-server systemd[1]: Started LSB: broken_project initscript.

我将非常感激任何与此相关的调试技巧。我正在尽力学习服务器配置,但在这方面我陷入了困境,我试图一边学习一边把事情拼凑起来。

谢谢!

相关内容