Had too many unstable restarts PM2

Server provisioning and management

Whenever I’m trying to deploy to server that serves as our staging enviroment I’m getting “had too many unstable restarts”

2022-05-13T12:23:57: PM2 log: App [staging.codotto.com:0] exited with code [0] via signal [SIGINT]
2022-05-13T12:23:57: PM2 log: App [staging.codotto.com:0] starting in -cluster mode-
2022-05-13T12:23:57: PM2 log: App [staging.codotto.com:0] online
2022-05-13T12:23:57: PM2 log: App name:staging.codotto.com id:0 disconnected
2022-05-13T12:23:57: PM2 log: App [staging.codotto.com:0] exited with code [0] via signal [SIGINT]
2022-05-13T12:23:57: PM2 log: App [staging.codotto.com:0] starting in -cluster mode-
2022-05-13T12:23:57: PM2 log: App [staging.codotto.com:0] online
2022-05-13T12:23:58: PM2 log: App name:staging.codotto.com id:0 disconnected
2022-05-13T12:23:58: PM2 log: App [staging.codotto.com:0] exited with code [0] via signal [SIGINT]
2022-05-13T12:23:58: PM2 log: App [staging.codotto.com:0] starting in -cluster mode-
2022-05-13T12:23:58: PM2 log: App [staging.codotto.com:0] online
2022-05-13T12:23:58: PM2 log: App name:staging.codotto.com id:0 disconnected
2022-05-13T12:23:58: PM2 log: App [staging.codotto.com:0] exited with code [0] via signal [SIGINT]
2022-05-13T12:23:58: PM2 log: App [staging.codotto.com:0] starting in -cluster mode-
2022-05-13T12:23:58: PM2 log: App [staging.codotto.com:0] online
2022-05-13T12:23:58: PM2 log: App name:staging.codotto.com id:0 disconnected
2022-05-13T12:23:58: PM2 log: App [staging.codotto.com:0] exited with code [0] via signal [SIGINT]
2022-05-13T12:23:58: PM2 log: App [staging.codotto.com:0] starting in -cluster mode-
2022-05-13T12:23:58: PM2 log: App [staging.codotto.com:0] online
2022-05-13T12:23:58: PM2 log: App name:staging.codotto.com id:0 disconnected
2022-05-13T12:23:58: PM2 log: App [staging.codotto.com:0] exited with code [0] via signal [SIGINT]
2022-05-13T12:23:58: PM2 log: App [staging.codotto.com:0] starting in -cluster mode-
2022-05-13T12:23:58: PM2 log: App [staging.codotto.com:0] online
2022-05-13T12:23:58: PM2 log: App name:staging.codotto.com id:0 disconnected
2022-05-13T12:23:58: PM2 log: App [staging.codotto.com:0] exited with code [0] via signal [SIGINT]
2022-05-13T12:23:58: PM2 log: App [staging.codotto.com:0] starting in -cluster mode-
2022-05-13T12:23:58: PM2 log: App [staging.codotto.com:0] online
2022-05-13T12:23:58: PM2 log: App name:staging.codotto.com id:0 disconnected
2022-05-13T12:23:58: PM2 log: App [staging.codotto.com:0] exited with code [0] via signal [SIGINT]
2022-05-13T12:23:58: PM2 log: Script /home/cleavr/staging.codotto.com/current/index.js had too many unstable restarts (16). Stopped. "errored"

I haven’t changed anything. It was working a couple of days ago. Now out of no where it stopped working.

Maybe it had to do with this feature being released? Strapi, Nuxt, and Directus improvements 💪🏽 - Cleavr.io release notes


EDIT 1

Trying to rollback to an older version of my app doesn’t work.

I guess we can rule out the fact that it doesn’t have anything to do with the app


EDIT 2

The PM2 logs says:

/opt/pm2/logs/staging.codotto.com-error-0.log last 15 lines:
0|staging. |     at WriteStream.<anonymous> (/usr/lib/node_modules/pm2/lib/Utility.js:186:13)
0|staging. |     at WriteStream.emit (node:events:526:28)
0|staging. |     at node:internal/fs/streams:72:16
0|staging. |     at FSReqCallback.oncomplete (node:fs:188:23)
0|staging. | Error: Cannot find module '/home/cleavr/staging.codotto.com/current/index.js'
0|staging. |     at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
0|staging. |     at Function.Module._load (node:internal/modules/cjs/loader:778:27)
0|staging. |     at /usr/lib/node_modules/pm2/lib/ProcessContainer.js:303:25
0|staging. |     at wrapper (/usr/lib/node_modules/pm2/node_modules/async/internal/once.js:12:16)
0|staging. |     at next (/usr/lib/node_modules/pm2/node_modules/async/waterfall.js:96:20)
0|staging. |     at /usr/lib/node_modules/pm2/node_modules/async/internal/onlyOnce.js:12:16
0|staging. |     at WriteStream.<anonymous> (/usr/lib/node_modules/pm2/lib/Utility.js:186:13)
0|staging. |     at WriteStream.emit (node:events:526:28)
0|staging. |     at node:internal/fs/streams:72:16
0|staging. |     at FSReqCallback.oncomplete (node:fs:188:23)

This is a bit weird

0|staging. | Error: Cannot find module '/home/cleavr/staging.codotto.com/current/index.js'

because my app is a Quasar’s app that doesn’t have a index.js under current folder. What it does have is under the current/dist/ssr/index.js


EDIT 3

This is my configuration for PM2

This is my configuration for PM2

Can you try setting cwd to point it to artifact folder:

cwd:"/home/cleavr/staginq.codotto.com/artifact"

and deploy again?

1 Like

It is working now. Thank you.

Should I make the update in my production enviroment or wait for a fix from Cleavr itself?

You should fix it yourself for now. It’s really hard to guess what a specific framework structure might look like with a NodeJS SSR app. We are still working on it to make this better but changing it to artifact works as a general solution. This change is needed to have an app run in cluster mode and be able to build on GitHub.

Even though I understand from your side guys but it is something dangerous to do.

Luckily our app is not used by thousands hundreds of people and we have two environments to avoid these issues but if timed correctly it could have brought down our entire production infrastructure down.

I appreciate the help