@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,459 @@
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 os = require('os');
8
+ var p = require('path');
9
+ var blessed = require('@pm2/blessed');
10
+ var debug = require('debug')('zm2:monit');
11
+ var printf = require('sprintf-js').sprintf;
12
+
13
+ // Total memory
14
+ const totalMem = os.totalmem();
15
+
16
+ var Dashboard = {};
17
+
18
+ var DEFAULT_PADDING = {
19
+ top : 0,
20
+ left : 1,
21
+ right : 1
22
+ };
23
+
24
+ var WIDTH_LEFT_PANEL = 30;
25
+
26
+ /**
27
+ * Synchronous Dashboard init method
28
+ * @method init
29
+ * @return this
30
+ */
31
+ Dashboard.init = function() {
32
+ // Init Screen
33
+ this.screen = blessed.screen({
34
+ smartCSR: true,
35
+ fullUnicode: true
36
+ });
37
+ this.screen.title = 'PM2 Dashboard';
38
+
39
+ this.logLines = {}
40
+
41
+ this.list = blessed.list({
42
+ top: '0',
43
+ left: '0',
44
+ width: WIDTH_LEFT_PANEL + '%',
45
+ height: '70%',
46
+ padding: 0,
47
+ scrollbar: {
48
+ ch: ' ',
49
+ inverse: false
50
+ },
51
+ border: {
52
+ type: 'line'
53
+ },
54
+ keys: true,
55
+ autoCommandKeys: true,
56
+ tags: true,
57
+ style: {
58
+ selected: {
59
+ bg: 'blue',
60
+ fg: 'white'
61
+ },
62
+ scrollbar: {
63
+ bg: 'blue',
64
+ fg: 'black'
65
+ },
66
+ fg: 'white',
67
+ border: {
68
+ fg: 'blue'
69
+ },
70
+ header: {
71
+ fg: 'blue'
72
+ }
73
+ }
74
+ });
75
+
76
+ this.list.on('select item', (item, i) => {
77
+ this.logBox.clearItems()
78
+ })
79
+
80
+ this.logBox = blessed.list({
81
+ label: ' Logs ',
82
+ top: '0',
83
+ left: WIDTH_LEFT_PANEL + '%',
84
+ width: 100 - WIDTH_LEFT_PANEL + '%',
85
+ height: '70%',
86
+ padding: DEFAULT_PADDING,
87
+ scrollable: true,
88
+ scrollbar: {
89
+ ch: ' ',
90
+ inverse: false
91
+ },
92
+ keys: true,
93
+ autoCommandKeys: true,
94
+ tags: true,
95
+ border: {
96
+ type: 'line'
97
+ },
98
+ style: {
99
+ fg: 'white',
100
+ border: {
101
+ fg: 'white'
102
+ },
103
+ scrollbar: {
104
+ bg: 'blue',
105
+ fg: 'black'
106
+ }
107
+ }
108
+ });
109
+
110
+ this.metadataBox = blessed.box({
111
+ label: ' Metadata ',
112
+ top: '70%',
113
+ left: WIDTH_LEFT_PANEL + '%',
114
+ width: 100 - WIDTH_LEFT_PANEL + '%',
115
+ height: '26%',
116
+ padding: DEFAULT_PADDING,
117
+ scrollable: true,
118
+ scrollbar: {
119
+ ch: ' ',
120
+ inverse: false
121
+ },
122
+ keys: true,
123
+ autoCommandKeys: true,
124
+ tags: true,
125
+ border: {
126
+ type: 'line'
127
+ },
128
+ style: {
129
+ fg: 'white',
130
+ border: {
131
+ fg: 'white'
132
+ },
133
+ scrollbar: {
134
+ bg: 'blue',
135
+ fg: 'black'
136
+ }
137
+ }
138
+ });
139
+
140
+ this.metricsBox = blessed.list({
141
+ label: ' Custom Metrics ',
142
+ top: '70%',
143
+ left: '0%',
144
+ width: WIDTH_LEFT_PANEL + '%',
145
+ height: '26%',
146
+ padding: DEFAULT_PADDING,
147
+ scrollbar: {
148
+ ch: ' ',
149
+ inverse: false
150
+ },
151
+ keys: true,
152
+ autoCommandKeys: true,
153
+ tags: true,
154
+ border: {
155
+ type: 'line'
156
+ },
157
+ style: {
158
+ fg: 'white',
159
+ border: {
160
+ fg: 'white'
161
+ },
162
+ scrollbar: {
163
+ bg: 'blue',
164
+ fg: 'black'
165
+ }
166
+ }
167
+ });
168
+
169
+ this.box4 = blessed.text({
170
+ content: ' left/right: switch boards | up/down/mouse: scroll | Ctrl-C: exit{|} {cyan-fg}{bold}To go further check out https://pm2.io/{/} ',
171
+ left: '0%',
172
+ top: '95%',
173
+ width: '100%',
174
+ height: '6%',
175
+ valign: 'middle',
176
+ tags: true,
177
+ style: {
178
+ fg: 'white'
179
+ }
180
+ });
181
+
182
+ this.list.focus();
183
+
184
+ this.screen.append(this.list);
185
+ this.screen.append(this.logBox);
186
+ this.screen.append(this.metadataBox);
187
+ this.screen.append(this.metricsBox);
188
+ this.screen.append(this.box4);
189
+
190
+ this.list.setLabel(' Process List ');
191
+
192
+ this.screen.render();
193
+
194
+ var that = this;
195
+
196
+ var i = 0;
197
+ var boards = ['list', 'logBox', 'metricsBox', 'metadataBox'];
198
+ this.screen.key(['left', 'right'], function(ch, key) {
199
+ (key.name === 'left') ? i-- : i++;
200
+ if (i == 4)
201
+ i = 0;
202
+ if (i == -1)
203
+ i = 3;
204
+ that[boards[i]].focus();
205
+ that[boards[i]].style.border.fg = 'blue';
206
+ if (key.name === 'left') {
207
+ if (i == 3)
208
+ that[boards[0]].style.border.fg = 'white';
209
+ else
210
+ that[boards[i + 1]].style.border.fg = 'white';
211
+ }
212
+ else {
213
+ if (i == 0)
214
+ that[boards[3]].style.border.fg = 'white';
215
+ else
216
+ that[boards[i - 1]].style.border.fg = 'white';
217
+ }
218
+ });
219
+
220
+ this.screen.key(['escape', 'q', 'C-c'], function(ch, key) {
221
+ this.screen.destroy();
222
+ process.exit(0);
223
+ });
224
+
225
+ // async refresh of the ui
226
+ setInterval(function () {
227
+ that.screen.render();
228
+ }, 300);
229
+
230
+ return this;
231
+ }
232
+
233
+ /**
234
+ * Refresh dashboard
235
+ * @method refresh
236
+ * @param {} processes
237
+ * @return this
238
+ */
239
+ Dashboard.refresh = function(processes) {
240
+ debug('Monit refresh');
241
+
242
+ if(!processes) {
243
+ this.list.setItem(0, 'No process available');
244
+ return;
245
+ }
246
+
247
+ if (processes.length != this.list.items.length) {
248
+ this.list.clearItems();
249
+ }
250
+
251
+ // Total of processes memory
252
+ var mem = 0;
253
+ processes.forEach(function(proc) {
254
+ mem += proc.monit.memory;
255
+ })
256
+
257
+ // Sort process list
258
+ processes.sort(function(a, b) {
259
+ if (a.pm2_env.name < b.pm2_env.name)
260
+ return -1;
261
+ if (a.pm2_env.name > b.pm2_env.name)
262
+ return 1;
263
+ return 0;
264
+ });
265
+
266
+ // Loop to get process infos
267
+ for (var i = 0; i < processes.length; i++) {
268
+ // Percent of memory use by one process in all pm2 processes
269
+ var memPercent = (processes[i].monit.memory / mem) * 100;
270
+
271
+ // Status of process
272
+ var status = processes[i].pm2_env.status == 'online' ? '{green-fg}' : '{red-fg}';
273
+ status = status + '{bold}' + processes[i].pm2_env.status + '{/}';
274
+
275
+ var name = processes[i].pm2_env.name || p.basename(processes[i].pm2_env.pm_exec_path);
276
+
277
+ // Line of list
278
+ var item = printf('[%2s] %s {|} Mem: {bold}{%s-fg}%3d{/} MB CPU: {bold}{%s-fg}%2d{/} %s %s',
279
+ processes[i].pm2_env.pm_id,
280
+ name,
281
+ gradient(memPercent, [255, 0, 0], [0, 255, 0]),
282
+ (processes[i].monit.memory / 1048576).toFixed(2),
283
+ gradient(processes[i].monit.cpu, [255, 0, 0], [0, 255, 0]),
284
+ processes[i].monit.cpu,
285
+ "%",
286
+ status);
287
+
288
+ // Check if item exist
289
+ if (this.list.getItem(i)) {
290
+ this.list.setItem(i, item);
291
+ }
292
+ else {
293
+ this.list.pushItem(item);
294
+ }
295
+
296
+ var proc = processes[this.list.selected];
297
+ // render the logBox
298
+ let process_id = proc.pm_id
299
+ let logs = this.logLines[process_id];
300
+ if(typeof(logs) !== "undefined"){
301
+ this.logBox.setItems(logs)
302
+ if (!this.logBox.focused) {
303
+ this.logBox.setScrollPerc(100);
304
+ }
305
+ }else{
306
+ this.logBox.clearItems();
307
+ }
308
+ this.logBox.setLabel(` ${proc.pm2_env.name} Logs `)
309
+
310
+ this.metadataBox.setLine(0, 'App Name ' + '{bold}' + proc.pm2_env.name + '{/}');
311
+ this.metadataBox.setLine(1, 'Namespace ' + '{bold}' + proc.pm2_env.namespace + '{/}');
312
+ this.metadataBox.setLine(2, 'Version ' + '{bold}' + proc.pm2_env.version + '{/}');
313
+ this.metadataBox.setLine(3, 'Restarts ' + proc.pm2_env.restart_time);
314
+ this.metadataBox.setLine(4, 'Uptime ' + ((proc.pm2_env.pm_uptime && proc.pm2_env.status == 'online') ? timeSince(proc.pm2_env.pm_uptime) : 0));
315
+ this.metadataBox.setLine(5, 'Script path ' + proc.pm2_env.pm_exec_path);
316
+ this.metadataBox.setLine(6, 'Script args ' + (proc.pm2_env.args ? (typeof proc.pm2_env.args == 'string' ? JSON.parse(proc.pm2_env.args.replace(/'/g, '"')):proc.pm2_env.args).join(' ') : 'N/A'));
317
+ this.metadataBox.setLine(7, 'Interpreter ' + proc.pm2_env.exec_interpreter);
318
+ this.metadataBox.setLine(8, 'Interpreter args ' + (proc.pm2_env.node_args.length != 0 ? proc.pm2_env.node_args : 'N/A'));
319
+ this.metadataBox.setLine(9, 'Exec mode ' + (proc.pm2_env.exec_mode == 'fork_mode' ? '{bold}fork{/}' : '{blue-fg}{bold}cluster{/}'));
320
+ this.metadataBox.setLine(10, 'Node.js version ' + proc.pm2_env.node_version);
321
+ this.metadataBox.setLine(11, 'watch & reload ' + (proc.pm2_env.watch ? '{green-fg}{bold}✔{/}' : '{red-fg}{bold}✘{/}'));
322
+ this.metadataBox.setLine(12, 'Unstable restarts ' + proc.pm2_env.unstable_restarts);
323
+
324
+ this.metadataBox.setLine(13, 'Comment ' + ((proc.pm2_env.versioning) ? proc.pm2_env.versioning.comment : 'N/A'));
325
+ this.metadataBox.setLine(14, 'Revision ' + ((proc.pm2_env.versioning) ? proc.pm2_env.versioning.revision : 'N/A'));
326
+ this.metadataBox.setLine(15, 'Branch ' + ((proc.pm2_env.versioning) ? proc.pm2_env.versioning.branch : 'N/A'));
327
+ this.metadataBox.setLine(16, 'Remote url ' + ((proc.pm2_env.versioning) ? proc.pm2_env.versioning.url : 'N/A'));
328
+ this.metadataBox.deleteLine(17)
329
+ this.metadataBox.setLine(17, 'Last update ' + ((proc.pm2_env.versioning) ? proc.pm2_env.versioning.update_time : 'N/A'));
330
+
331
+ if (Object.keys(proc.pm2_env.axm_monitor).length != this.metricsBox.items.length) {
332
+ this.metricsBox.clearItems();
333
+ }
334
+ var j = 0;
335
+ for (var key in proc.pm2_env.axm_monitor) {
336
+ var metric_name = proc.pm2_env.axm_monitor[key].hasOwnProperty('value') ? proc.pm2_env.axm_monitor[key].value : proc.pm2_env.axm_monitor[key]
337
+ var metric_unit = proc.pm2_env.axm_monitor[key].hasOwnProperty('unit') ? proc.pm2_env.axm_monitor[key].unit : null
338
+ var probe = `{bold}${key}{/} {|} ${metric_name}${metric_unit == null ? '' : ' ' + metric_unit}`
339
+
340
+ if (this.metricsBox.getItem(j)) {
341
+ this.metricsBox.setItem(j, probe);
342
+ }
343
+ else {
344
+ this.metricsBox.pushItem(probe);
345
+ }
346
+ j++;
347
+ }
348
+
349
+ this.screen.render();
350
+ }
351
+
352
+ return this;
353
+ }
354
+
355
+ /**
356
+ * Put Log
357
+ * @method log
358
+ * @param {} data
359
+ * @return this
360
+ */
361
+ Dashboard.log = function(type, data) {
362
+ var that = this;
363
+
364
+ if(typeof(this.logLines[data.process.pm_id]) == "undefined"){
365
+ this.logLines[data.process.pm_id]=[];
366
+ }
367
+ // Logs colors
368
+ switch (type) {
369
+ case 'PM2':
370
+ var color = '{blue-fg}';
371
+ break;
372
+ case 'out':
373
+ var color = '{green-fg}';
374
+ break;
375
+ case 'err':
376
+ var color = '{red-fg}';
377
+ break;
378
+ default:
379
+ var color = '{white-fg}';
380
+ }
381
+
382
+ var logs = data.data.split('\n')
383
+
384
+ logs.forEach((log) => {
385
+ if (log.length > 0) {
386
+ this.logLines[data.process.pm_id].push(color + data.process.name + '{/} > ' + log)
387
+
388
+
389
+ //removing logs if longer than limit
390
+ let count = 0;
391
+ let max_count = 0;
392
+ let leading_process_id = -1;
393
+
394
+ for(var process_id in this.logLines){
395
+ count += this.logLines[process_id].length;
396
+ if( this.logLines[process_id].length > max_count){
397
+ leading_process_id = process_id;
398
+ max_count = this.logLines[process_id].length;
399
+ }
400
+ }
401
+
402
+ if (count > 200) {
403
+ this.logLines[leading_process_id].shift()
404
+ }
405
+ }
406
+ })
407
+
408
+ return this;
409
+ }
410
+
411
+ module.exports = Dashboard;
412
+
413
+ function timeSince(date) {
414
+
415
+ var seconds = Math.floor((new Date() - date) / 1000);
416
+
417
+ var interval = Math.floor(seconds / 31536000);
418
+
419
+ if (interval > 1) {
420
+ return interval + 'Y';
421
+ }
422
+ interval = Math.floor(seconds / 2592000);
423
+ if (interval > 1) {
424
+ return interval + 'M';
425
+ }
426
+ interval = Math.floor(seconds / 86400);
427
+ if (interval > 1) {
428
+ return interval + 'D';
429
+ }
430
+ interval = Math.floor(seconds / 3600);
431
+ if (interval > 1) {
432
+ return interval + 'h';
433
+ }
434
+ interval = Math.floor(seconds / 60);
435
+ if (interval > 1) {
436
+ return interval + 'm';
437
+ }
438
+ return Math.floor(seconds) + 's';
439
+ }
440
+
441
+ /* Args :
442
+ * p : Percent 0 - 100
443
+ * rgb_ : Array of rgb [255, 255, 255]
444
+ * Return :
445
+ * Hexa #FFFFFF
446
+ */
447
+ function gradient(p, rgb_beginning, rgb_end) {
448
+
449
+ var w = (p / 100) * 2 - 1;
450
+
451
+ var w1 = (w + 1) / 2.0;
452
+ var w2 = 1 - w1;
453
+
454
+ var rgb = [parseInt(rgb_beginning[0] * w1 + rgb_end[0] * w2),
455
+ parseInt(rgb_beginning[1] * w1 + rgb_end[1] * w2),
456
+ parseInt(rgb_beginning[2] * w1 + rgb_end[2] * w2)];
457
+
458
+ return "#" + ((1 << 24) + (rgb[0] << 16) + (rgb[1] << 8) + rgb[2]).toString(16).slice(1);
459
+ }
@@ -0,0 +1,117 @@
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 fs = require('fs');
8
+ var cst = require('../../constants.js');
9
+ var Utility = require('../Utility.js');
10
+ var Common = require('../Common.js');
11
+
12
+ function deployHelper() {
13
+ console.log('');
14
+ console.log('-----> Helper: Deployment with PM2');
15
+ console.log('');
16
+ console.log(' Generate a sample ecosystem.config.js with the command');
17
+ console.log(' $ pm2 ecosystem');
18
+ console.log(' Then edit the file depending on your needs');
19
+ console.log('');
20
+ console.log(' Commands:');
21
+ console.log(' setup run remote setup commands');
22
+ console.log(' update update deploy to the latest release');
23
+ console.log(' revert [n] revert to [n]th last deployment or 1');
24
+ console.log(' curr[ent] output current release commit');
25
+ console.log(' prev[ious] output previous release commit');
26
+ console.log(' exec|run <cmd> execute the given <cmd>');
27
+ console.log(' list list previous deploy commits');
28
+ console.log(' [ref] deploy to [ref], the "ref" setting, or latest tag');
29
+ console.log('');
30
+ console.log('');
31
+ console.log(' Basic Examples:');
32
+ console.log('');
33
+ console.log(' First initialize remote production host:');
34
+ console.log(' $ pm2 deploy ecosystem.config.js production setup');
35
+ console.log('');
36
+ console.log(' Then deploy new code:');
37
+ console.log(' $ pm2 deploy ecosystem.config.js production');
38
+ console.log('');
39
+ console.log(' If I want to revert to the previous commit:');
40
+ console.log(' $ pm2 deploy ecosystem.config.js production revert 1');
41
+ console.log('');
42
+ console.log(' Execute a command on remote server:');
43
+ console.log(' $ pm2 deploy ecosystem.config.js production exec "pm2 restart all"');
44
+ console.log('');
45
+ console.log(' PM2 will look by default to the ecosystem.config.js file so you dont need to give the file name:');
46
+ console.log(' $ pm2 deploy production');
47
+ console.log(' Else you have to tell PM2 the name of your ecosystem file');
48
+ console.log('');
49
+ console.log(' More examples in https://github.com/Unitech/pm2');
50
+ console.log('');
51
+ };
52
+
53
+ module.exports = function(CLI) {
54
+ CLI.prototype.deploy = function(file, commands, cb) {
55
+ var that = this;
56
+
57
+ if (file == 'help') {
58
+ deployHelper();
59
+ return cb ? cb() : that.exitCli(cst.SUCCESS_EXIT);
60
+ }
61
+
62
+ var args = commands.rawArgs;
63
+ var env;
64
+
65
+ args.splice(0, args.indexOf('deploy') + 1);
66
+
67
+ // Find ecosystem file by default
68
+ if (!Common.isConfigFile(file)) {
69
+ env = args[0];
70
+ var defaultConfigNames = [ ...Common.getConfigFileCandidates('ecosystem'), 'ecosystem.json5', 'package.json'];
71
+
72
+ file = Utility.whichFileExists(defaultConfigNames);
73
+
74
+ if (!file) {
75
+ Common.printError('Not any default deployment file exists.'+
76
+ ' Allowed default config file names are: ' + defaultConfigNames.join(', '));
77
+ return cb ? cb('Not any default ecosystem file present') : that.exitCli(cst.ERROR_EXIT);
78
+ }
79
+ }
80
+ else
81
+ env = args[1];
82
+
83
+ var json_conf = null;
84
+
85
+ try {
86
+ json_conf = Common.parseConfig(fs.readFileSync(file), file);
87
+ } catch (e) {
88
+ Common.printError(e);
89
+ return cb ? cb(e) : that.exitCli(cst.ERROR_EXIT);
90
+ }
91
+
92
+ if (!env) {
93
+ deployHelper();
94
+ return cb ? cb() : that.exitCli(cst.SUCCESS_EXIT);
95
+ }
96
+
97
+ if (!json_conf.deploy || !json_conf.deploy[env]) {
98
+ Common.printError('%s environment is not defined in %s file', env, file);
99
+ return cb ? cb('%s environment is not defined in %s file') : that.exitCli(cst.ERROR_EXIT);
100
+ }
101
+
102
+ if (!json_conf.deploy[env]['post-deploy']) {
103
+ json_conf.deploy[env]['post-deploy'] = 'pm2 startOrRestart ' + file + ' --env ' + env;
104
+ }
105
+
106
+ require('pm2-deploy').deployForEnv(json_conf.deploy, env, args, function(err, data) {
107
+ if (err) {
108
+ Common.printError('Deploy failed');
109
+ Common.printError(err.message || err);
110
+ return cb ? cb(err) : that.exitCli(cst.ERROR_EXIT);
111
+ }
112
+ Common.printOut('--> Success');
113
+ return cb ? cb(null, data) : that.exitCli(cst.SUCCESS_EXIT);
114
+ });
115
+ };
116
+
117
+ };