gpt4 book ai didi

ruby-on-rails - 零停机的目标,如何在套接字和(g)unicorn :中使用 Upstart

转载 作者:行者123 更新时间:2023-12-03 11:52:03 25 4
gpt4 key购买 nike

我的目标是电子商务应用程序的零停机时间部署,并且我正在尝试以最好的方式做到这一点。

我在nginx/unicorn/django设置以及单独服务器的nginx/unicorn/rails设置上执行此操作。

我的策略是在preload_app=true/guincorn.py文件中设置unicorn.rb,然后通过向运行服务器的PID发送USR2信号来重新加载。这将派生该过程,它是子进程,并且pre_fork/before_fork可以接管此进程并发送后续的QUIT信号。

这是我的pre_fork在guincorn版本中所做的示例:

# ...

pidfile='/opt/run/my-website/my-website.pid'

# socket doesn't come back after QUIT
bind='unix:/opt/run/my-website/my-website.socket'

# works, but I'd prefer the socket for security
# bind='localhost:8333'

# ...

def pre_fork(server, worker):
old_pid_file = '/opt/run/my-website/my-website.pid.oldbin'

if os.path.isfile(old_pid_file):
with open(old_pid_file, 'r') as pid_contents:
try:
old_pid = int(pid_contents.read())
if old_pid != server.pid:
os.kill(old_pid, signal.SIGQUIT)
except Exception as err:
pass

pre_fork=pre_fork

这是我的sysv脚本中的一个选项,它执行重新加载:
DESC="my website"
SITE_PATH="/opt/python/my-website"
ENV_PATH="/opt/env/my-website"
RUN_AS="myuser"

SETTINGS="my.settings"
STDOUT_LOG="/var/log/my-website/my-website-access.log"
STDERR_LOG="/var/log/my-website/my-website-error.log"
GUNICORN="/opt/env/my-website/bin/gunicorn.py"

CMD="$ENV_PATH/bin/python $SITE_PATH/manage.py run_gunicorn -c $GUNICORN >> $STDOUT_LOG 2>>$STDERR_LOG"

sig () {
test -s "$PID" && kill -$1 `cat $PID`
}

run () {
if [ "$(id -un)" = "$RUN_AS" ]; then
eval $1
else
su -c "$1" - $RUN_AS
fi
}

reload () {
echo "Reloading $DESC"
sig USR2 && echo reloaded OK && exit 0
echo >&2 "Couldn't reload, starting '$DESC' instead"
run "$CMD"
}
action="$1"
case $action in
reload)
reload
;;
esac

我选择preload_app = true来实现零停机时间呼吁。由于工作人员已将应用程序预加载到内存中,因此,只要我正确切换进程,它就应该将停机时间模拟为零。无论如何,这就是想法。

这在我通过端口监听的地方有效,但是我无法通过套接字使其正常工作。

我的问题如下:
  • 这是您其余部分的工作方式吗?
  • 是否有更好的方法,例如以某种方式使用HUP?我的理解是您不能将preload_app=true与HUP一起使用。
  • 是否可以使用套接字执行此操作?我的套接字在QUIT上不断消失,再也不会回来。我的想法是套接字更加安全,因为您必须有权访问文件系统。
  • 是否有人使用upstart而不是sysv完成此操作?理想情况下,我想通过植绒PID来看到an interesting way of accomplishing that。这对于 Upstart 来说是一个挑战,因为一旦来自gunicorn/unicorn的exec-fork接手, Upstart 就不再监视它原来管理的流程,需要以某种方式重新建立。
  • 最佳答案

    您应该查看GDS同事的unicornherder,它是专门为管理此问题而设计的:

    Unicorn Herder is a utility designed to assist in the use of Upstart and similar supervisors with Unicorn.

    关于ruby-on-rails - 零停机的目标,如何在套接字和(g)unicorn :中使用 Upstart ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29110077/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com