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

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

问题描述

我在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.

首先,让我们假设应用程序已经在运行.我们使用

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 install

forever restart /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天全站免登陆