@zappinginc/zm2 6.0.14

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.
Files changed (133) hide show
  1. package/.claude/settings.local.json +8 -0
  2. package/.gitattributes +4 -0
  3. package/.mocharc.js +14 -0
  4. package/CHANGELOG.md +2416 -0
  5. package/CLAUDE.md +84 -0
  6. package/CONTRIBUTING.md +124 -0
  7. package/GNU-AGPL-3.0.txt +665 -0
  8. package/LICENSE +1 -0
  9. package/README.md +248 -0
  10. package/bin/zm2 +3 -0
  11. package/bin/zm2-dev +3 -0
  12. package/bin/zm2-docker +3 -0
  13. package/bin/zm2-runtime +3 -0
  14. package/bin/zm2-windows +3 -0
  15. package/bin/zm2.ps1 +3 -0
  16. package/bun.lock +421 -0
  17. package/constants.js +114 -0
  18. package/index.js +13 -0
  19. package/lib/API/Configuration.js +212 -0
  20. package/lib/API/Containerizer.js +335 -0
  21. package/lib/API/Dashboard.js +459 -0
  22. package/lib/API/Deploy.js +117 -0
  23. package/lib/API/Extra.js +775 -0
  24. package/lib/API/ExtraMgmt/Docker.js +30 -0
  25. package/lib/API/Log.js +315 -0
  26. package/lib/API/LogManagement.js +371 -0
  27. package/lib/API/Modules/LOCAL.js +122 -0
  28. package/lib/API/Modules/Modularizer.js +148 -0
  29. package/lib/API/Modules/NPM.js +445 -0
  30. package/lib/API/Modules/TAR.js +362 -0
  31. package/lib/API/Modules/flagExt.js +46 -0
  32. package/lib/API/Modules/index.js +120 -0
  33. package/lib/API/Monit.js +247 -0
  34. package/lib/API/Serve.js +343 -0
  35. package/lib/API/Startup.js +629 -0
  36. package/lib/API/UX/helpers.js +213 -0
  37. package/lib/API/UX/index.js +9 -0
  38. package/lib/API/UX/pm2-describe.js +193 -0
  39. package/lib/API/UX/pm2-ls-minimal.js +31 -0
  40. package/lib/API/UX/pm2-ls.js +483 -0
  41. package/lib/API/Version.js +382 -0
  42. package/lib/API/interpreter.json +12 -0
  43. package/lib/API/pm2-plus/PM2IO.js +372 -0
  44. package/lib/API/pm2-plus/auth-strategies/CliAuth.js +288 -0
  45. package/lib/API/pm2-plus/auth-strategies/WebAuth.js +187 -0
  46. package/lib/API/pm2-plus/helpers.js +97 -0
  47. package/lib/API/pm2-plus/link.js +126 -0
  48. package/lib/API/pm2-plus/pres/motd +16 -0
  49. package/lib/API/pm2-plus/pres/motd.update +26 -0
  50. package/lib/API/pm2-plus/pres/welcome +28 -0
  51. package/lib/API/pm2-plus/process-selector.js +52 -0
  52. package/lib/API/schema.json +379 -0
  53. package/lib/API.js +1931 -0
  54. package/lib/Client.js +776 -0
  55. package/lib/Common.js +911 -0
  56. package/lib/Configuration.js +304 -0
  57. package/lib/Daemon.js +456 -0
  58. package/lib/Event.js +37 -0
  59. package/lib/God/ActionMethods.js +909 -0
  60. package/lib/God/ClusterMode.js +97 -0
  61. package/lib/God/ForkMode.js +297 -0
  62. package/lib/God/Methods.js +265 -0
  63. package/lib/God/Reload.js +240 -0
  64. package/lib/God.js +632 -0
  65. package/lib/HttpInterface.js +76 -0
  66. package/lib/ProcessContainer.js +305 -0
  67. package/lib/ProcessContainerBun.js +360 -0
  68. package/lib/ProcessContainerFork.js +42 -0
  69. package/lib/ProcessContainerForkBun.js +33 -0
  70. package/lib/ProcessUtils.js +55 -0
  71. package/lib/TreeKill.js +118 -0
  72. package/lib/Utility.js +430 -0
  73. package/lib/VersionCheck.js +46 -0
  74. package/lib/Watcher.js +117 -0
  75. package/lib/Worker.js +169 -0
  76. package/lib/binaries/CLI.js +1041 -0
  77. package/lib/binaries/DevCLI.js +183 -0
  78. package/lib/binaries/Runtime.js +101 -0
  79. package/lib/binaries/Runtime4Docker.js +192 -0
  80. package/lib/completion.js +229 -0
  81. package/lib/completion.sh +40 -0
  82. package/lib/motd +36 -0
  83. package/lib/templates/Dockerfiles/Dockerfile-java.tpl +7 -0
  84. package/lib/templates/Dockerfiles/Dockerfile-nodejs.tpl +8 -0
  85. package/lib/templates/Dockerfiles/Dockerfile-ruby.tpl +7 -0
  86. package/lib/templates/ecosystem-es.tpl +24 -0
  87. package/lib/templates/ecosystem-simple-es.tpl +8 -0
  88. package/lib/templates/ecosystem-simple.tpl +6 -0
  89. package/lib/templates/ecosystem.tpl +22 -0
  90. package/lib/templates/init-scripts/launchd.tpl +35 -0
  91. package/lib/templates/init-scripts/openrc.tpl +52 -0
  92. package/lib/templates/init-scripts/pm2-init-amazon.sh +86 -0
  93. package/lib/templates/init-scripts/rcd-openbsd.tpl +41 -0
  94. package/lib/templates/init-scripts/rcd.tpl +44 -0
  95. package/lib/templates/init-scripts/smf.tpl +43 -0
  96. package/lib/templates/init-scripts/systemd-online.tpl +22 -0
  97. package/lib/templates/init-scripts/systemd.tpl +22 -0
  98. package/lib/templates/init-scripts/upstart.tpl +103 -0
  99. package/lib/templates/logrotate.d/pm2 +10 -0
  100. package/lib/templates/sample-apps/http-server/README.md +14 -0
  101. package/lib/templates/sample-apps/http-server/api.js +9 -0
  102. package/lib/templates/sample-apps/http-server/ecosystem.config.js +14 -0
  103. package/lib/templates/sample-apps/http-server/package.json +11 -0
  104. package/lib/templates/sample-apps/pm2-plus-metrics-actions/README.md +45 -0
  105. package/lib/templates/sample-apps/pm2-plus-metrics-actions/custom-metrics.js +66 -0
  106. package/lib/templates/sample-apps/pm2-plus-metrics-actions/ecosystem.config.js +12 -0
  107. package/lib/templates/sample-apps/pm2-plus-metrics-actions/package.json +11 -0
  108. package/lib/templates/sample-apps/python-app/README.md +4 -0
  109. package/lib/templates/sample-apps/python-app/echo.py +7 -0
  110. package/lib/templates/sample-apps/python-app/ecosystem.config.js +12 -0
  111. package/lib/templates/sample-apps/python-app/package.json +11 -0
  112. package/lib/tools/Config.js +248 -0
  113. package/lib/tools/IsAbsolute.js +20 -0
  114. package/lib/tools/copydirSync.js +101 -0
  115. package/lib/tools/deleteFolderRecursive.js +19 -0
  116. package/lib/tools/find-package-json.js +74 -0
  117. package/lib/tools/fmt.js +72 -0
  118. package/lib/tools/isbinaryfile.js +94 -0
  119. package/lib/tools/json5.js +752 -0
  120. package/lib/tools/open.js +63 -0
  121. package/lib/tools/passwd.js +58 -0
  122. package/lib/tools/promise.min.js +1 -0
  123. package/lib/tools/sexec.js +55 -0
  124. package/lib/tools/treeify.js +113 -0
  125. package/lib/tools/which.js +120 -0
  126. package/lib/tools/xdg-open +861 -0
  127. package/package.json +219 -0
  128. package/paths.js +93 -0
  129. package/pm2 +11 -0
  130. package/preinstall.js +24 -0
  131. package/run.sh +9 -0
  132. package/types/index.d.ts +722 -0
  133. package/types/tsconfig.json +14 -0
@@ -0,0 +1,304 @@
1
+ /**
2
+ * Copyright 2013-2022 the PM2 project authors. All rights reserved.
3
+ * Use of this source code is governed by a license that
4
+ * can be found in the LICENSE file.
5
+ */
6
+
7
+ var Configuration = module.exports = {};
8
+
9
+ var fs = require('fs');
10
+
11
+ var Common = require('./Common');
12
+ var eachSeries = require('async/eachSeries');
13
+ var cst = require('../constants.js');
14
+
15
+ function splitKey(key) {
16
+ var values = [key];
17
+
18
+ if (key.indexOf('.') > -1)
19
+ values = key.match(/(?:[^."]+|"[^"]*")+/g).map(function(dt) { return dt.replace(/"/g, '') });
20
+ else if (key.indexOf(':') > -1)
21
+ values = key.match(/(?:[^:"]+|"[^"]*")+/g).map(function(dt) { return dt.replace(/"/g, '') });
22
+
23
+ return values;
24
+ }
25
+
26
+ function serializeConfiguration(json_conf) {
27
+ return JSON.stringify(json_conf, null, 4)
28
+ }
29
+
30
+ Configuration.set = function(key, value, cb) {
31
+ fs.readFile(cst.PM2_MODULE_CONF_FILE, function(err, data) {
32
+ if (err) return cb(err);
33
+
34
+ var json_conf = JSON.parse(data);
35
+
36
+ var values = splitKey(key);
37
+
38
+ if (values.length > 0) {
39
+ var levels = values;
40
+
41
+ var tmp = json_conf;
42
+
43
+ levels.forEach(function(key, index) {
44
+ if (index == levels.length -1)
45
+ tmp[key] = value;
46
+ else if (!tmp[key]) {
47
+ tmp[key] = {};
48
+ tmp = tmp[key];
49
+ }
50
+ else {
51
+ if (typeof(tmp[key]) != 'object')
52
+ tmp[key] = {};
53
+ tmp = tmp[key];
54
+ }
55
+ });
56
+
57
+ }
58
+ else {
59
+ if (json_conf[key] && typeof(json_conf[key]) === 'string')
60
+ Common.printOut(cst.PREFIX_MSG + 'Replacing current value key %s by %s', key, value);
61
+
62
+ json_conf[key] = value;
63
+ }
64
+
65
+ fs.writeFile(cst.PM2_MODULE_CONF_FILE, serializeConfiguration(json_conf), function(err, data) {
66
+ if (err) return cb(err);
67
+
68
+ return cb(null, json_conf);
69
+ });
70
+ return false;
71
+ });
72
+ };
73
+
74
+ Configuration.unset = function(key, cb) {
75
+ fs.readFile(cst.PM2_MODULE_CONF_FILE, function(err, data) {
76
+ if (err) return cb(err);
77
+
78
+ var json_conf = JSON.parse(data);
79
+
80
+ var values = splitKey(key);
81
+
82
+ if (values.length > 0) {
83
+ var levels = values;
84
+
85
+ var tmp = json_conf;
86
+
87
+ levels.forEach(function(key, index) {
88
+ if (index == levels.length -1)
89
+ delete tmp[key];
90
+ else if (!tmp[key]) {
91
+ tmp[key] = {};
92
+ tmp = tmp[key];
93
+ }
94
+ else {
95
+ if (typeof(tmp[key]) != 'object')
96
+ tmp[key] = {};
97
+ tmp = tmp[key];
98
+ }
99
+ });
100
+
101
+ }
102
+ else
103
+ delete json_conf[key];
104
+
105
+ if (err) return cb(err);
106
+
107
+ if (key === 'all')
108
+ json_conf = {};
109
+
110
+ fs.writeFile(cst.PM2_MODULE_CONF_FILE, serializeConfiguration(json_conf), function(err, data) {
111
+ if (err) return cb(err);
112
+
113
+ return cb(null, json_conf);
114
+ });
115
+ return false;
116
+ });
117
+ }
118
+
119
+ Configuration.setSyncIfNotExist = function(key, value) {
120
+ try {
121
+ var conf = JSON.parse(fs.readFileSync(cst.PM2_MODULE_CONF_FILE));
122
+ } catch(e) {
123
+ return null;
124
+ }
125
+
126
+ var values = splitKey(key);
127
+ var exists = false;
128
+
129
+ if (values.length > 1 && conf && conf[values[0]]) {
130
+ exists = Object.keys(conf[values[0]]).some(function(key) {
131
+ if (key == values[1])
132
+ return true;
133
+ return false;
134
+ });
135
+ }
136
+
137
+ if (exists === false)
138
+ return Configuration.setSync(key, value);
139
+
140
+ return null;
141
+ };
142
+
143
+ Configuration.setSync = function(key, value) {
144
+ try {
145
+ var data = fs.readFileSync(cst.PM2_MODULE_CONF_FILE);
146
+ } catch(e) {
147
+ return null;
148
+ }
149
+
150
+ var json_conf = JSON.parse(data);
151
+
152
+ var values = splitKey(key);
153
+
154
+ if (values.length > 0) {
155
+ var levels = values;
156
+
157
+ var tmp = json_conf;
158
+
159
+ levels.forEach(function(key, index) {
160
+ if (index == levels.length -1)
161
+ tmp[key] = value;
162
+ else if (!tmp[key]) {
163
+ tmp[key] = {};
164
+ tmp = tmp[key];
165
+ }
166
+ else {
167
+ if (typeof(tmp[key]) != 'object')
168
+ tmp[key] = {};
169
+ tmp = tmp[key];
170
+ }
171
+ });
172
+
173
+ }
174
+ else {
175
+ if (json_conf[key] && typeof(json_conf[key]) === 'string')
176
+ Common.printOut(cst.PREFIX_MSG + 'Replacing current value key %s by %s', key, value);
177
+
178
+ json_conf[key] = value;
179
+ }
180
+
181
+ if (key === 'all')
182
+ json_conf = {};
183
+
184
+ try {
185
+ fs.writeFileSync(cst.PM2_MODULE_CONF_FILE, serializeConfiguration(json_conf));
186
+ return json_conf;
187
+ } catch(e) {
188
+ console.error(e.message);
189
+ return null;
190
+ }
191
+ };
192
+
193
+ Configuration.unsetSync = function(key) {
194
+ try {
195
+ var data = fs.readFileSync(cst.PM2_MODULE_CONF_FILE);
196
+ } catch(e) {
197
+ return null;
198
+ }
199
+
200
+ var json_conf = JSON.parse(data);
201
+
202
+ var values = splitKey(key);
203
+
204
+ if (values.length > 0) {
205
+ var levels = values;
206
+
207
+ var tmp = json_conf;
208
+
209
+ levels.forEach(function(key, index) {
210
+ if (index == levels.length -1)
211
+ delete tmp[key];
212
+ else if (!tmp[key]) {
213
+ tmp[key] = {};
214
+ tmp = tmp[key];
215
+ }
216
+ else {
217
+ if (typeof(tmp[key]) != 'object')
218
+ tmp[key] = {};
219
+ tmp = tmp[key];
220
+ }
221
+ });
222
+
223
+ }
224
+ else
225
+ delete json_conf[key];
226
+
227
+ if (key === 'all')
228
+ json_conf = {};
229
+
230
+ try {
231
+ fs.writeFileSync(cst.PM2_MODULE_CONF_FILE, serializeConfiguration(json_conf));
232
+ } catch(e) {
233
+ console.error(e.message);
234
+ return null;
235
+ }
236
+ };
237
+
238
+ Configuration.multiset = function(serial, cb) {
239
+ var arrays = [];
240
+ serial = serial.match(/(?:[^ "]+|"[^"]*")+/g);
241
+
242
+ while (serial.length > 0)
243
+ arrays.push(serial.splice(0, 2));
244
+
245
+ eachSeries(arrays, function(el, next) {
246
+ Configuration.set(el[0], el[1], next);
247
+ }, cb);
248
+ };
249
+
250
+ Configuration.get = function(key, cb) {
251
+ Configuration.getAll(function(err, data) {
252
+ var climb = splitKey(key);
253
+
254
+ climb.some(function(val) {
255
+ if (!data[val]) {
256
+ data = null;
257
+ return true;
258
+ }
259
+ data = data[val];
260
+ return false;
261
+ });
262
+
263
+ if (!data) return cb({err : 'Unknown key'}, null);
264
+ return cb(null, data);
265
+ });
266
+ };
267
+
268
+ Configuration.getSync = function(key) {
269
+ try {
270
+ var data = Configuration.getAllSync();
271
+ } catch(e) {
272
+ return null;
273
+ }
274
+
275
+ var climb = splitKey(key);
276
+
277
+ climb.some(function(val) {
278
+ if (!data[val]) {
279
+ data = null;
280
+ return true;
281
+ }
282
+ data = data[val];
283
+ return false;
284
+ });
285
+
286
+ if (!data) return null;
287
+ return data;
288
+ };
289
+
290
+ Configuration.getAll = function(cb) {
291
+ fs.readFile(cst.PM2_MODULE_CONF_FILE, function(err, data) {
292
+ if (err) return cb(err);
293
+ return cb(null, JSON.parse(data));
294
+ });
295
+ };
296
+
297
+ Configuration.getAllSync = function() {
298
+ try {
299
+ return JSON.parse(fs.readFileSync(cst.PM2_MODULE_CONF_FILE));
300
+ } catch(e) {
301
+ console.error(e.stack || e);
302
+ return {};
303
+ }
304
+ };