我正在为网站运行带有 PHP laravel 后端的 Angular SSR 应用程序。 我已经设置了一个节点服务器,并使用 PM2 管理它,使用环境配置生成它,如下所示:
module.exports = {
apps : [{
name: 'FFBLive',
script: 'local.js',
// instances: "max",
// Options reference: https://pm2.io/doc/en/runtime/reference/ecosystem-file/
args: 'one two',
instances: 1,
autorestart: true,
watch: false, //was true before but tried turning it off to see if it helps
watch_delay: 1000,
ignore_watch : ["system202005","system202005/*"],
max_memory_restart: '1G',
env: {
NODE_ENV: 'development'
},
env_production: {
NODE_ENV: 'production'
}
}],
应用程序生成得很好,并正常运行了一段时间,然后过了一会儿,我在网站上得到了 503 服务不可用,当我查看服务器时,PM2 守护进程已死掉..当我尝试查看日志,我明白 -
pm2 logs
[PM2] Spawning PM2 daemon with pm2_home=/home2/bfo/.pm2
[PM2] PM2 Successfully daemonized
[TAILING] Tailing last 15 lines for [all] processes (change the value with --lines option)
/home2/bfo/.pm2/pm2.log last 15 lines:
PM2 | 2020-05-30T21:23:24: PM2 log: ===============================================================================
PM2 | 2020-05-30T21:23:24: PM2 log: --- New PM2 Daemon started ----------------------------------------------------
PM2 | 2020-05-30T21:23:24: PM2 log: Time : Sat May 30 2020 21:23:24 GMT-0400 (Eastern Daylight Time)
PM2 | 2020-05-30T21:23:24: PM2 log: PM2 version : 3.5.1
PM2 | 2020-05-30T21:23:24: PM2 log: Node.js version : 10.20.1
PM2 | 2020-05-30T21:23:24: PM2 log: Current arch : x64
PM2 | 2020-05-30T21:23:24: PM2 log: PM2 home : /home2/bfo/.pm2
PM2 | 2020-05-30T21:23:24: PM2 log: PM2 PID file : /home2/bfo/.pm2/pm2.pid
PM2 | 2020-05-30T21:23:24: PM2 log: RPC socket file : /home2/bfo/.pm2/rpc.sock
PM2 | 2020-05-30T21:23:24: PM2 log: BUS socket file : /home2/bfo/.pm2/pub.sock
PM2 | 2020-05-30T21:23:24: PM2 log: Application log path : /home2/bfo/.pm2/logs
PM2 | 2020-05-30T21:23:24: PM2 log: Process dump file : /home2/bfo/.pm2/dump.pm2
PM2 | 2020-05-30T21:23:24: PM2 log: Concurrent actions : 2
PM2 | 2020-05-30T21:23:24: PM2 log: SIGTERM timeout : 1600
PM2 | 2020-05-30T21:23:24: PM2 log: ===============================================================================
输出日志文件包含 -
Listening on: http://localhost:9700
Listening on: http://localhost:9700
Listening on: http://localhost:9700
Listening on: http://localhost:9700
Listening on: http://localhost:9700
Listening on: http://localhost:9700
{ catSlug: 'all', searchStr: 'Um9odQ' }
Listening on: http://localhost:9700
Listening on: http://localhost:9700
错误日志确实包含一些异常,主要与我的 Angular 应用程序未找到 laravel index.php 文件的路由有关 - 例如
ERROR { Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'index.php'
Error: Cannot match any routes. URL Segment: 'index.php'
at ApplyRedirects.module.exports.ApplyRedirects.noMatchError (/home2/bfo/public_html/dist/server.js:165170:16)
at CatchSubscriber.selector (/home2/bfo/public_html/dist/server.js:165151:29)
在某些情况下,Laravel API 出现异常(例如,一个供应商依赖项未正确导入到控制器中)-
Class 'Barryvdh\Snappy\ServiceProvider' not found
Class 'Barryvdh\Snappy\ServiceProvider' not found
ERROR { Error: Uncaught (in promise): Class 'Barryvdh\Snappy\ServiceProvider' not found
at resolvePromise (/home2/bfo/public_html/dist/server.js:123429:31)
但我的问题是 - a) 这些异常是否会导致 sigterm 并导致 PM2 守护进程完全停止?我不这么认为,但可能是错的。 b) 我首先认为观察程序正在监视太多文件,因为最初它正在监视子文件夹中的 PHP REST API 文件,但后来我将其添加到忽略监视列表,然后简单地关闭监视以查看是否这有帮助。 c) 我还想知道资源分配(例如内存)是否会导致这种情况,但在这种情况下它只会重新启动而不是死亡。
我对 PM2 不太熟悉,这更多的是一个实验,目的是让 Angular SSR 在使用 PM2 的节点服务器上正常工作,所以我在设置它时可能做错了。
我尝试用谷歌搜索可能的答案,但结果here和here或here并没有真正的帮助。 我很高兴能得到一些关于如何正确设置它以获得稳定生产模式的指导。
谢谢你。
我已经通过运行以下命令解决了该问题。
npm uninstall -g pm2
npm install -g [email protected]
我在运行 5.3.1 时遇到了同样的问题,我认为这是我可以在我的旧 Mac 上使用的最新版本。