From d17263139ed2b54eaa6b4d05e2d1ea63ed9cabca Mon Sep 17 00:00:00 2001 From: Matchu Date: Wed, 3 Nov 2021 16:46:35 -0700 Subject: [PATCH] Fix pm2 monitoring Okay huh, while digging a bit into another issue, I found what was wrong with our config and pm2's built-in monitoring! You can't use `yarn start`, because the wrapper script breaks its ability to look inside and see what's happening. I also removed the compiler flag thing from the `start` script in `package.json`, because I think it's redundant? There's no compilation to be done in a live server. I think I might remove monit after this? It's nice extra resilience in a sense, but it feels like extra complexity when it's doing the job `pm2` is supposed to do. (And tbh I've almost never heard of nginx crashing, and if it does it's probably a scenario worth investigating by hand.) --- deploy/playbooks/setup.yml | 7 +++++-- package.json | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/deploy/playbooks/setup.yml b/deploy/playbooks/setup.yml index d0f9ac5..c5ee5ee 100644 --- a/deploy/playbooks/setup.yml +++ b/deploy/playbooks/setup.yml @@ -71,8 +71,11 @@ { name: "impress-2020", cwd: "/srv/impress-2020/current", - script: "yarn", - args: "start", + // Instead of `yarn start`, we specify the `next` binary + // directly, because it helps pm2 monitor our app correctly. + // https://github.com/vercel/next.js/discussions/10675#discussioncomment-34615 + script: "./node_modules/.bin/next", + args: "start --port=3000", instances: "max", exec_mode: "cluster", // We add `app` to the end of the filename, to avoid a pm2 diff --git a/package.json b/package.json index 459deb7..010f689 100644 --- a/package.json +++ b/package.json @@ -60,7 +60,7 @@ }, "scripts": { "prepare": "husky install", - "start": "TS_NODE_COMPILER=typescript-cached-transpile next start", + "start": "next start", "dev": "yarn build-cached-data && REACT_APP_IMPRESS_LOG_IN_AS=$IMPRESS_LOG_IN_AS TS_NODE_COMPILER=typescript-cached-transpile next dev", "build": "yarn build-cached-data && next build", "vercel-build": "yum install libuuid-devel libmount-devel && cp /lib64/{libuuid,libmount,libblkid}.so.1 node_modules/canvas/build/Release/",