简体   繁体   English

如何使用飞行计划重新加载/重启 pm2 并注意符号链接目录?

[英]How to reload/restart pm2 with flighplan and be aware of a symlink directory?

I am using flighplan to deploy my web service that built by Node.js我正在使用飞行计划来部署由Node.js构建的 Web 服务

My deployment script uploads the new release to a new directory which has a timestamp or some random characters in its name.我的部署脚本将新版本上传到一个新目录,该目录的名称中包含时间戳或一些随机字符。 I am keeping all my releases in my server so I can rollback easily by just changing the link to any specific release and have zero-downtime deployment.我将所有版本都保存在我的服务器中,因此我只需更改指向任何特定版本的链接即可轻松回滚,并实现零停机部署。

The main directory, named by the service name and it is just a symbolic link that get changed to the new release's directory after uploading it.主目录,以服务名称命名,它只是一个符号链接,上传后会更改为新版本的目录。

ln -snf ~/tmpDir ~/appName

在此处输入图片说明

My problem is when pm2 restars my server it uses the original path of the previous release, it doesn't bind with the symbolic link and follow the link to the new directory that the link is pointing to.我的问题是,当pm2 restars我的服务器,它使用以前的版本的原始路径,它不与符号链接绑定,并按照链接到新目录中的链接指向。

Is there any way to restart or reload pm2 and let it be aware of that symbolic link ?有没有办法重新启动或重新加载pm2并让它知道那个符号链接?

Short answer - You should not run pm2 inside a symlink which changes.简短回答- 您不应在更改的符号链接中运行 pm2。 pm2 would always pick the old path the symlink is pointing to unless you use pm2 kill command.除非您使用 pm2 kill 命令,否则 pm2 将始终选择符号链接指向的旧路径。

Solution - create a new directory and make it parent directory of smylink and your code directories (mohmal-144 etc.).解决方案- 创建一个新目录并将其设为 smylink 和您的代码目录(mohmal-144 等)的父目录。 For the sake of understanding lets call this deploy.为了便于理解,我们称之为部署。

Now you should have below structure /home/deploy /home/deploy/mohmal -> home/deploy/mohmal-144.现在你应该有以下结构 /home/deploy /home/deploy/mohmal -> home/deploy/mohmal-144。

If you are using pm2, yous should use ecosystem.json (pm2 config for starting apps) file.如果您使用的是 pm2,则应该使用生态系统.json(用于启动应用程序的 pm2 配置)文件。 Though you can name this file to anything you want.尽管您可以将此文件命名为您想要的任何名称。 For the sake of understanding, lets call this file ecosystem.json file.为了便于理解,我们将这个文件称为生态系统.json 文件。

Inside this ecossystem.json file, in the apps section, add the cwd directory and cwd should point to the path of the symlink(not the path to which symlink it pointing to).在这个 ecossystem.json 文件中的 apps 部分,添加 cwd 目录并且 cwd 应该指向符号链接的路径(而不是它指向的符号链接的路径)。 See below example.见下面的例子。

{
  "apps": [
    {
      "name": "mohmal",
      "script": "src/bin/server.js",
      "exec_mode": "cluster",
      "instances" : "0",
      "cwd": "/home/deploy/mohmal",
      "error_file": "/var/log/mohmal/error.log",
      "out_file" : "/var/log/mohmal/out.log",
      "merge_logs": true
    }
  ]
}

Place this file in the parent directory which is named deploy in this example.将此文件放在本示例中名为 deploy 的父目录中。

Now run/use pm2 start, pm2 restart commands from this directory only.现在只从这个目录运行/使用 pm2 start, pm2 restart 命令。 If you are already running pm2 in the system, just once run pm2 kill to clear the old processes.如果您已经在系统中运行 pm2,只需运行一次 pm2 kill 即可清除旧进程。

And then use the suggested changes, you would never have to pm2 kill the processes.然后使用建议的更改,您将永远不必 pm2 终止进程。 Also the changes to symlink would reflect.符号链接的变化也会反映出来。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM