MCPcopy
hub / github.com/ever-co/ever-demand / autoExit

Function autoExit

packages/core/src/pm2bootstrap.ts:96–142  ·  view source on GitHub ↗

* Exit current PM2 instance if 0 app is online

()

Source from the content-addressed store, hash-verified

94 * Exit current PM2 instance if 0 app is online
95 */
96async function autoExit() {
97 const interval = 3000;
98 const aliveInterval = interval * 1.5;
99
100 let alive = false;
101
102 while (true) {
103 await timeout(interval);
104
105 const aliveTimer = setTimeout(function () {
106 if (!alive) {
107 console.error('PM2 Daemon is dead');
108 process.exit(1);
109 }
110 }, aliveInterval);
111
112 try {
113 const apps = await runningApps();
114
115 clearTimeout(aliveTimer);
116 alive = true;
117
118 let appOnline = 0;
119
120 apps.forEach(function (app) {
121 if (
122 app.pm2_env.status === cst.ONLINE_STATUS ||
123 app.pm2_env.status === cst.LAUNCHING_STATUS
124 ) {
125 appOnline++;
126 }
127 });
128
129 console.log('check ' + appOnline);
130
131 if (appOnline === 0) {
132 console.log('0 application online, exiting');
133 exitPM2();
134 }
135 } catch (err) {
136 console.log('pm2.list got error');
137 console.error(err);
138 exitPM2();
139 return;
140 }
141 }
142}

Callers

nothing calls this directly

Calls 4

timeoutFunction · 0.85
exitPM2Function · 0.85
logMethod · 0.80
errorMethod · 0.45

Tested by

no test coverage detected