@abtnode/util 1.16.51 → 1.16.52-beta-20250908-085420-224a58fa
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
const fs = require('node:fs');
|
|
5
5
|
const path = require('node:path');
|
|
6
6
|
const os = require('node:os');
|
|
7
|
+
const debug = require('debug')('@core/util:pm2-start-or-reload');
|
|
7
8
|
const pm2 = require('./async-pm2');
|
|
8
9
|
|
|
9
10
|
function getTempEnvPath(name) {
|
|
@@ -97,14 +98,47 @@ async function isProcessRunningByPm2(name) {
|
|
|
97
98
|
return isHasRunning;
|
|
98
99
|
}
|
|
99
100
|
|
|
101
|
+
async function getCurrentProcessCount(name) {
|
|
102
|
+
const count = await new Promise((resolve) => {
|
|
103
|
+
pm2.list((err, list) => {
|
|
104
|
+
if (err) {
|
|
105
|
+
return resolve(0);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const procs = list.filter((p) => p.name === name);
|
|
109
|
+
resolve(procs.length);
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
return count;
|
|
114
|
+
}
|
|
115
|
+
|
|
100
116
|
async function pm2StartOrReload(config = {}) {
|
|
101
|
-
const { name } = config;
|
|
117
|
+
const { name, instances, execMode } = config;
|
|
102
118
|
const tempEnvPath = getTempEnvPath(name);
|
|
103
119
|
fs.writeFileSync(tempEnvPath, JSON.stringify(config.env));
|
|
104
120
|
|
|
105
121
|
const isHasRunning = await isProcessRunningByPm2(name);
|
|
106
122
|
|
|
107
123
|
if (isHasRunning) {
|
|
124
|
+
// Check if we need to restart for cluster mode with different instance count
|
|
125
|
+
debug('execMode', execMode, instances);
|
|
126
|
+
if (execMode === 'cluster' && instances) {
|
|
127
|
+
const currentCount = await getCurrentProcessCount(name);
|
|
128
|
+
debug('current instance count', currentCount);
|
|
129
|
+
|
|
130
|
+
if (currentCount !== instances) {
|
|
131
|
+
try {
|
|
132
|
+
await pm2.deleteAsync(name);
|
|
133
|
+
debug('existing processes deleted', name);
|
|
134
|
+
} catch (error) {
|
|
135
|
+
debug('delete existing processes error', error);
|
|
136
|
+
}
|
|
137
|
+
await pm2.startAsync(config);
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
108
142
|
await pm2ReloadWithEnv(config);
|
|
109
143
|
} else {
|
|
110
144
|
await pm2.startAsync(config);
|
|
@@ -114,5 +148,6 @@ async function pm2StartOrReload(config = {}) {
|
|
|
114
148
|
module.exports = {
|
|
115
149
|
loadReloadEnv,
|
|
116
150
|
isProcessRunningByPm2,
|
|
151
|
+
getCurrentProcessCount,
|
|
117
152
|
pm2StartOrReload,
|
|
118
153
|
};
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.16.
|
|
6
|
+
"version": "1.16.52-beta-20250908-085420-224a58fa",
|
|
7
7
|
"description": "ArcBlock's JavaScript utility",
|
|
8
8
|
"main": "lib/index.js",
|
|
9
9
|
"files": [
|
|
@@ -18,15 +18,15 @@
|
|
|
18
18
|
"author": "polunzh <polunzh@gmail.com> (http://github.com/polunzh)",
|
|
19
19
|
"license": "Apache-2.0",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@abtnode/constant": "1.16.
|
|
22
|
-
"@abtnode/db-cache": "1.16.
|
|
21
|
+
"@abtnode/constant": "1.16.52-beta-20250908-085420-224a58fa",
|
|
22
|
+
"@abtnode/db-cache": "1.16.52-beta-20250908-085420-224a58fa",
|
|
23
23
|
"@arcblock/did": "1.24.0",
|
|
24
24
|
"@arcblock/event-hub": "1.24.0",
|
|
25
25
|
"@arcblock/pm2": "^6.0.12",
|
|
26
|
-
"@blocklet/constant": "1.16.
|
|
26
|
+
"@blocklet/constant": "1.16.52-beta-20250908-085420-224a58fa",
|
|
27
27
|
"@blocklet/error": "^0.2.5",
|
|
28
|
-
"@blocklet/meta": "1.16.
|
|
29
|
-
"@blocklet/xss": "^0.2.
|
|
28
|
+
"@blocklet/meta": "1.16.52-beta-20250908-085420-224a58fa",
|
|
29
|
+
"@blocklet/xss": "^0.2.7",
|
|
30
30
|
"@ocap/client": "1.24.0",
|
|
31
31
|
"@ocap/mcrypto": "1.24.0",
|
|
32
32
|
"@ocap/util": "1.24.0",
|
|
@@ -91,5 +91,5 @@
|
|
|
91
91
|
"fs-extra": "^11.2.0",
|
|
92
92
|
"jest": "^29.7.0"
|
|
93
93
|
},
|
|
94
|
-
"gitHead": "
|
|
94
|
+
"gitHead": "400eda55fc1058c961fd622907237a649b5c4f86"
|
|
95
95
|
}
|