@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,240 @@
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
+ 'use strict';
7
+
8
+ /**
9
+ * @file Reload functions related
10
+ * @author Alexandre Strzelewicz <as@unitech.io>
11
+ * @project PM2
12
+ */
13
+
14
+ var cst = require('../../constants.js');
15
+ var Utility = require('../Utility.js');
16
+
17
+ /**
18
+ * softReload will wait permission from process to exit
19
+ * @method softReload
20
+ * @param {} God
21
+ * @param {} id
22
+ * @param {} cb
23
+ * @return Literal
24
+ */
25
+ function softReload(God, id, cb) {
26
+ var t_key = '_old_' + id;
27
+
28
+ // Move old worker to tmp id
29
+ God.clusters_db[t_key] = God.clusters_db[id];
30
+
31
+ delete God.clusters_db[id];
32
+
33
+ var old_worker = God.clusters_db[t_key];
34
+
35
+ // Deep copy
36
+ var new_env = Utility.clone(old_worker.pm2_env);
37
+
38
+ // Reset created_at and unstable_restarts
39
+ God.resetState(new_env);
40
+
41
+ new_env.restart_time += 1;
42
+
43
+ old_worker.pm2_env.pm_id = t_key;
44
+ old_worker.pm_id = t_key;
45
+
46
+ God.executeApp(new_env, function(err, new_worker) {
47
+ if (err) return cb(err);
48
+
49
+ var timer = null;
50
+
51
+ var onListen = function () {
52
+ clearTimeout(timer);
53
+ softCleanDeleteProcess();
54
+ console.log('-softReload- New worker listening');
55
+ };
56
+
57
+ // Bind to know when the new process is up
58
+ new_worker.once('listening', onListen);
59
+
60
+ timer = setTimeout(function() {
61
+ new_worker.removeListener('listening', onListen);
62
+ softCleanDeleteProcess();
63
+ }, new_env.listen_timeout || cst.GRACEFUL_LISTEN_TIMEOUT);
64
+
65
+ // Remove old worker properly
66
+ var softCleanDeleteProcess = function () {
67
+ var cleanUp = function () {
68
+ clearTimeout(timer);
69
+ console.log('-softReload- Old worker disconnected');
70
+ return God.deleteProcessId(t_key, cb);
71
+ };
72
+
73
+ old_worker.once('disconnect', cleanUp);
74
+
75
+ try {
76
+ if (old_worker.state != 'dead' && old_worker.state != 'disconnected')
77
+ old_worker.send && old_worker.send('shutdown');
78
+ else {
79
+ clearTimeout(timer);
80
+ console.error('Worker %d is already disconnected', old_worker.pm2_env.pm_id);
81
+ return God.deleteProcessId(t_key, cb);
82
+ }
83
+ } catch(e) {
84
+ clearTimeout(timer);
85
+ console.error('Worker %d is already disconnected', old_worker.pm2_env.pm_id);
86
+ return God.deleteProcessId(t_key, cb);
87
+ }
88
+
89
+ timer = setTimeout(function () {
90
+ old_worker.removeListener('disconnect', cleanUp);
91
+ return God.deleteProcessId(t_key, cb);
92
+ }, cst.GRACEFUL_TIMEOUT);
93
+ return false;
94
+ };
95
+ return false;
96
+ });
97
+ return false;
98
+ };
99
+
100
+ /**
101
+ * hardReload will reload without waiting permission from process
102
+ * @method hardReload
103
+ * @param {} God
104
+ * @param {} id
105
+ * @param {} cb
106
+ * @return Literal
107
+ */
108
+ function hardReload(God, id, wait_msg, cb) {
109
+ var t_key = '_old_' + id;
110
+
111
+ // Move old worker to tmp id
112
+ God.clusters_db[t_key] = God.clusters_db[id];
113
+ delete God.clusters_db[id];
114
+
115
+ var old_worker = God.clusters_db[t_key];
116
+ // Deep copy
117
+ var new_env = Utility.clone(old_worker.pm2_env);
118
+ new_env.restart_time += 1;
119
+
120
+ // Reset created_at and unstable_restarts
121
+ God.resetState(new_env);
122
+
123
+ old_worker.pm2_env.pm_id = t_key;
124
+ old_worker.pm_id = t_key;
125
+ var timer = null;
126
+ var readySignalSent = false;
127
+
128
+ var onListen = function () {
129
+ clearTimeout(timer);
130
+ readySignalSent = true;
131
+ console.log('-reload- New worker listening');
132
+ return God.deleteProcessId(t_key, cb);
133
+ };
134
+
135
+ var listener = function (packet) {
136
+ if (packet.raw === 'ready' &&
137
+ packet.process.name === old_worker.pm2_env.name &&
138
+ packet.process.pm_id === id) {
139
+ God.bus.removeListener('process:msg', listener);
140
+ return onListen();
141
+ }
142
+ };
143
+
144
+ if (wait_msg !== 'listening') {
145
+ God.bus.on('process:msg', listener);
146
+ }
147
+
148
+ God.executeApp(new_env, function(err, new_worker) {
149
+ if (err) return cb(err);
150
+
151
+ // Bind to know when the new process is up
152
+ if (wait_msg === 'listening') {
153
+ new_worker.once('listening', onListen);
154
+ }
155
+
156
+ timer = setTimeout(function() {
157
+ if (readySignalSent) {
158
+ return;
159
+ }
160
+
161
+ if (wait_msg === 'listening')
162
+ new_worker.removeListener(wait_msg, onListen);
163
+ else
164
+ God.bus.removeListener('process:msg', listener);
165
+
166
+ return God.deleteProcessId(t_key, cb);
167
+ }, new_env.listen_timeout || cst.GRACEFUL_LISTEN_TIMEOUT);
168
+
169
+ return false;
170
+ });
171
+ return false;
172
+ };
173
+
174
+ /**
175
+ * Description
176
+ * @method exports
177
+ * @param {} God
178
+ * @return
179
+ */
180
+ module.exports = function(God) {
181
+
182
+ /**
183
+ * Reload
184
+ * @method softReloadProcessId
185
+ * @param {} id
186
+ * @param {} cb
187
+ * @return CallExpression
188
+ */
189
+ God.softReloadProcessId = function(opts, cb) {
190
+ var id = opts.id;
191
+ var env = opts.env || {};
192
+
193
+ if (!(id in God.clusters_db))
194
+ return cb(new Error(`pm_id ${id} not available in ${id}`));
195
+
196
+ if (God.clusters_db[id].pm2_env.status == cst.ONLINE_STATUS &&
197
+ God.clusters_db[id].pm2_env.exec_mode == 'cluster_mode' &&
198
+ !God.clusters_db[id].pm2_env.wait_ready) {
199
+
200
+ Utility.extend(God.clusters_db[id].pm2_env.env, opts.env);
201
+ Utility.extendExtraConfig(God.clusters_db[id], opts);
202
+
203
+ return softReload(God, id, cb);
204
+ }
205
+ else {
206
+ console.log('Process %s in a stopped status, starting it', id);
207
+ return God.restartProcessId(opts, cb);
208
+ }
209
+ };
210
+
211
+ /**
212
+ * Reload
213
+ * @method reloadProcessId
214
+ * @param {} id
215
+ * @param {} cb
216
+ * @return CallExpression
217
+ */
218
+ God.reloadProcessId = function(opts, cb) {
219
+ var id = opts.id;
220
+ var env = opts.env || {};
221
+
222
+ if (!(id in God.clusters_db))
223
+ return cb(new Error('PM2 ID unknown'));
224
+
225
+ if (God.clusters_db[id].pm2_env.status == cst.ONLINE_STATUS &&
226
+ God.clusters_db[id].pm2_env.exec_mode == 'cluster_mode') {
227
+
228
+ Utility.extend(God.clusters_db[id].pm2_env.env, opts.env);
229
+ Utility.extendExtraConfig(God.clusters_db[id], opts);
230
+
231
+ var wait_msg = God.clusters_db[id].pm2_env.wait_ready ? 'ready' : 'listening';
232
+ return hardReload(God, id, wait_msg, cb);
233
+ }
234
+ else {
235
+ console.log('Process %s in a stopped status, starting it', id);
236
+ return God.restartProcessId(opts, cb);
237
+ }
238
+ };
239
+
240
+ };