加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

python – 在将当前符号链接切换到新目录后正常重新加载gunicorn

发布时间:2020-12-20 13:35:53 所属栏目:Python 来源:网络整理
导读:我正在尝试部署我的应用程序,我的文件夹的组织方式意味着我只想在部署新版本时更改符号链接.像这样: ./2013-07-16-10-12-48-test/ ./2013-07-16-10-17-01-test/ ./current - 2013-07-16-10-17-01-test/ 通常我只是使用kill -HUP master-pid,只要目录保持不
我正在尝试部署我的应用程序,我的文件夹的组织方式意味着我只想在部署新版本时更改符号链接.像这样:

./2013-07-16-10-12-48-test/  
./2013-07-16-10-17-01-test/  
./current -> 2013-07-16-10-17-01-test/

通常我只是使用kill -HUP master-pid,只要目录保持不变,一切正常.但是当我第一次更改符号链接然后重新加载时,代码仍然从旧目录运行到其绝对路径,就像gunicorn跟随符号链接并保存最终路径一样.
我开始像这样的gunicorn:gunicorn运行:在“当前”目录中的app -c gunicorn-config.py,我的配置文件如下所示:

workers = 4
worker_class = 'gevent'
bind = '127.0.0.1:5000'
pidfile = '/var/run/gunicorn.pid'
debug = False
loglevel = 'debug'
errorlog = '/var/log/gunicorn-error.log'
daemon = True

有没有办法让gunicorn重新评估符号链接或仅保存符号链接而不是完整路径?也许在某种on_starting或on_reload挂钩?

Here’s一个我无法开始工作的解决方案,也许这会提供更多的背景信息.

解决方法

我使用 USR2 signal得到了这个工作.
这是我的init.d文件,在部署之后,我将运行service gunicorn start_or_reload,它可以根据新位置启动或优雅地重新加载代码.它在技术上产生了当前主人内部的另一个主人,然后杀死了旧工人和主人,最后促进了新产生的主人.我使用这个解决方案后来添加了烟雾测试,然后杀死了老主人和类似的东西.我希望这可以帮助别人!

#!/bin/sh
### BEGIN INIT INFO
# Provides:          thin
# Required-Start:    $local_fs $remote_fs
# Required-Stop:     $local_fs $remote_fs
# Default-Start:     2 3 4 5
# Default-Stop:      S 0 1 6
# Short-Description: thin initscript
# Description:       thin
### END INIT INFO

# Original author: Forrest Robertson

# Do NOT "set -e"

DEPLOY_PATH=/opt/project/current
PID_FOLDER=/var/run/gunicorn
PID_FILE=$PID_FOLDER/project.pid
OLD_PID_FILE=$PID_FOLDER/project.pid.oldbin

start() {
    cd $DEPLOY_PATH && gunicorn run:app -c gunicorn-config.py
}

stop() {
  if [ -f $PID_FILE ]
  then
    kill `cat $PID_FILE`
    rm $PID_FILE
  fi
}

reload() {
    kill -USR2 `cat $PID_FILE`
    sleep 1
    kill -QUIT `cat $OLD_PID_FILE`
    rm $OLD_PID_FILE
}

start_or_reload() {
    if [ -f $PID_FILE ]
    then
        reload
    else
        start
    fi
}

case "$1" in
    start)
        echo "Starting server..."
        start
    ;;
    reload)
        echo "Reloading server..."
        reload
    ;;
    stop)
        echo "Stopping server..."
        stop
    ;;
    restart)
        echo "Restarting server..."
        stop && sleep 1 && start
    ;;
    start_or_reload)
        echo 'Starting or reloading server...'
        start_or_reload
    ;;
    wup)
        echo "Increasing workers..."
        kill -TTIN `cat $PID_FILE`
    ;;
    wdown)
        echo "Decreasing workers..."
        kill kill -TTOU `cat $PID_FILE`
    ;;
    *)
        echo "Usage: $SCRIPT_NAME {start|reload|stop|restart|start_or_reload|wup|wdown}" >&2
        exit 3
    ;;
esac

:

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读