以最少的停机时间运行时更新部署的流星应用程序 - 最佳实践 [英] Update deployed meteor app while running with minimum downtime - best practice

查看:12
本文介绍了以最少的停机时间运行时更新部署的流星应用程序 - 最佳实践的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我像这样在 EC2 上运行我的流星应用程序:node main.js(在 tmux 会话中)

I run my meteor app on EC2 like this: node main.js (in tmux session)

以下是我用来更新我的流星应用程序的步骤:

Here are the steps I use to update my meteor app:

1) 流星包 app.tgz

1) meteor bundle app.tgz

2) scp app.tgz EC2-server:/path

2) scp app.tgz EC2-server:/path

3) ssh EC2-server 并附加到 tmux

3) ssh EC2-server and attach to tmux

4) 通过 C-c 杀死当前的流星节点进程

4) kill the current meteor-node process by C-c

5) 提取 app.tgz

5) extract app.tgz

6) 运行提取的 app.tgz 的node main.js"

6) run "node main.js" of the extracted app.tgz

这是标准做法吗?

我意识到 forever 也可以使用,但是每次我更新我的应用程序时,您是否仍然必须杀死旧的节点进程并启动一个新的节点进程?在不杀死Node进程的情况下,升级可以更无缝吗?

I realize forever can be used too but still do you have to kill the old node process and start a new one every time I update my app? Can the upgrade be more seamless without killing the Node process?

推荐答案

如果不杀死节点进程,你就无法做到这一点,但我还没有发现这真的很重要.实际上更烦人的是客户端上的浏览器刷新,但您对此无能为力.

You can't do this without killing the node process, but I haven't found that really matters. What's actually more annoying is the browser refresh on the client, but there isn't much you can do about that.

首先,让我们假设应用程序已经在运行.我们使用类似于我的回答 此处.我会向您展示我的整个升级脚本,但它包含各种 Edthena 特定的内容,因此我将在下面概述我们采取的步骤:

First, let's assume the application is already running. We start our app via forever with a script like the one in my answer here. I'd show you my whole upgrade script but it contains all kinds of Edthena-specific stuff, so I'll outline the steps we take below:

  1. 构建一个新的包.我们在服务器本身上执行此操作,以避免任何丢失的纤程 问题.捆绑文件写入 /home/ubuntu/apps/edthena/edthena.tar.gz.

  1. Build a new bundle. We do this on the server itself, which avoids any missing fibers issues. The bundle file is written to /home/ubuntu/apps/edthena/edthena.tar.gz.

我们cd进入/home/ubuntu/apps/edthena目录和rm -rf bundle.这将吹走当前正在运行的进程使用的文件.因为服务器仍在内存中运行,它将继续执行.但是,如果您的应用程序在启动后定期执行未缓存的磁盘操作(例如从 private 目录中读取),则此步骤是有问题的.我们没有,所有静态资产都由 nginx 提供,所以我这样做是安全的.或者,您可以将旧的 bundle 目录移动到 bundle.old 之类的目录中,然后 应该有效.

We cd into the /home/ubuntu/apps/edthena directory and rm -rf bundle. That will blow away the files used by the current running process. Because the server is still running in memory it will keep executing. However, this step is problematic if your app regularly does uncached disk operatons like reading from the private directory after startup. We don't, and all of the static assets are served by nginx, so I feel safe in doing this. Alternatively, you can move the old bundle directory to something like bundle.old and it should work.

tar xzf edthena.tar.gz

cd bundle/programs/server &&npm 安装

永远重启/home/ubuntu/apps/edthena/bundle/main.js

这种方法确实没有任何停机时间 - 它只是以与服务器抛出异常时相同的方式重新启动应用程序.Forever 还会保留原始脚本中的环境,因此您无需再次指定环境变量.

There really isn't any downtime with this approach - it just restarts the app in the same way it would if the server threw an exception. Forever also keeps the environment from your original script, so you don't need to specify your environment variables again.

最后,您可以查看 ~/.forever 目录中的日志文件.可以通过forever list找到确切的路径.

Finally, you can have a look at the log files in your ~/.forever directory. The exact path can be found via forever list.

这篇关于以最少的停机时间运行时更新部署的流星应用程序 - 最佳实践的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆