【问题标题】:Running forever script from Google Cloud Platform App Engine startup script从 Google Cloud Platform App Engine 启动脚本运行永久脚本
【发布时间】:2017-04-25 08:44:11
【问题描述】:

我已经为我在 Google Cloud Platform App Engine 上运行的一个实例编辑了启动脚本变量。我希望它调用一个永久脚本以确保我的节点应用程序正在运行。所以我补充说:

cd /opt/bitnami/apps/myapp
forever start --workingDir /opt/bitnami/apps/myapp/ --sourceDir /opt
/bitnami/apps/myapp/ app.js

在 #!/bin/bash 行之后(也尝试不使用 cd,因为根据我的命令,它并不是真正需要的)。但是一旦启动虚拟机,运行 forever list 并不会将我的永远任务列为已启动。如果我将该永远的命令复制并粘贴到 gcloud 终端中并运行,则该任务显示正常,并且我的应用程序启动没有问题。

我在 bash 脚本中是否以某种方式正确调用它?

【问题讨论】:

  • 你可以移动到 app.js 所在的目录,然后尝试运行forever start app.js
  • @Ideluca - 您是否偶然发现了这一点?我也有同样的问题
  • @Brian 看看我的回答

标签: node.js bash google-app-engine mean-stack forever


【解决方案1】:

在 appengine 上启动 nodejs 应用程序的正确方法是在 package.json 中指定 "scripts" 字段,作为 documentation

下面是从sample借来的一个例子

"scripts": {
    "start": "node ./bin/www",
    "test": "cd ..; npm run t -- appengine/analytics/test/*.test.js"
  },

但是,如果您只对运行节点脚本感兴趣,而对 Google 应用引擎附带的功能不感兴趣,那么您可以简单地在 Google Compute Engine 实例上运行它。

【讨论】:

  • 这不是我要问的。我知道如何在 Google Cloud Platform 上启动我的应用程序。我想弄清楚的是如何在实例重新启动/启动时启动。而不是手动。
【解决方案2】:

The simple answer is that GAE does this by default。不需要foreverPM2。 GAE 会对保存您的应用程序的 Docker 容器进行某些健康检查,如果它们未通过,则实例会自动重新启动

如果您想对这些检查进行精细控制(称为 Legacy Health Checks),您可以将其添加到您的 app.yaml 文件中:

health_check:
  enable_health_check: True
  check_interval_sec: 5
  timeout_sec: 4
  unhealthy_threshold: 2
  healthy_threshold: 2

还有一些更新的机制(称为Updated Health Checks)仍处于测试阶段,但可以替代使用

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-07
    • 2014-10-18
    • 1970-01-01
    相关资源
    最近更新 更多