@ohos-ports/pm2 0.0.0-stage → 7.1.2-beta.0
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.
- package/CHANGELOG.md +2607 -0
- package/CONTRIBUTING.md +124 -0
- package/GNU-AGPL-3.0.txt +665 -0
- package/LICENSE +1 -0
- package/README.md +255 -2
- package/SECURITY.md +41 -0
- package/bin/pm2 +3 -0
- package/bin/pm2-dev +3 -0
- package/bin/pm2-docker +3 -0
- package/bin/pm2-runtime +3 -0
- package/bin/pm2.ps1 +3 -0
- package/constants.js +113 -0
- package/index.js +12 -0
- package/lib/API/Configuration.js +212 -0
- package/lib/API/Containerizer.js +335 -0
- package/lib/API/Dashboard.js +726 -0
- package/lib/API/Deploy.js +117 -0
- package/lib/API/Extra.js +798 -0
- package/lib/API/ExtraMgmt/Docker.js +30 -0
- package/lib/API/Log.js +388 -0
- package/lib/API/LogManagement.js +351 -0
- package/lib/API/Modules/LOCAL.js +122 -0
- package/lib/API/Modules/Modularizer.js +148 -0
- package/lib/API/Modules/NPM.js +443 -0
- package/lib/API/Modules/TAR.js +368 -0
- package/lib/API/Modules/flagExt.js +46 -0
- package/lib/API/Modules/index.js +120 -0
- package/lib/API/Monit.js +247 -0
- package/lib/API/Serve.js +497 -0
- package/lib/API/Startup.js +630 -0
- package/lib/API/UX/helpers.js +213 -0
- package/lib/API/UX/index.js +9 -0
- package/lib/API/UX/pm2-describe.js +197 -0
- package/lib/API/UX/pm2-ls-minimal.js +31 -0
- package/lib/API/UX/pm2-ls.js +581 -0
- package/lib/API/Version.js +383 -0
- package/lib/API/interpreter.json +12 -0
- package/lib/API/pm2-plus/PM2IO.js +381 -0
- package/lib/API/pm2-plus/auth-strategies/CliAuth.js +306 -0
- package/lib/API/pm2-plus/auth-strategies/WebAuth.js +195 -0
- package/lib/API/pm2-plus/helpers.js +97 -0
- package/lib/API/pm2-plus/link.js +126 -0
- package/lib/API/pm2-plus/pres/motd +16 -0
- package/lib/API/pm2-plus/pres/motd.update +26 -0
- package/lib/API/pm2-plus/pres/welcome +28 -0
- package/lib/API/pm2-plus/process-selector.js +52 -0
- package/lib/API/schema.json +375 -0
- package/lib/API.js +1980 -0
- package/lib/Client.js +793 -0
- package/lib/Common.js +949 -0
- package/lib/Configuration.js +309 -0
- package/lib/Daemon.js +468 -0
- package/lib/Event.js +37 -0
- package/lib/God/ActionMethods.js +955 -0
- package/lib/God/ClusterMode.js +192 -0
- package/lib/God/ForkMode.js +205 -0
- package/lib/God/Methods.js +292 -0
- package/lib/God/Reload.js +300 -0
- package/lib/God/StdioLogger.js +239 -0
- package/lib/God.js +653 -0
- package/lib/HttpInterface.js +75 -0
- package/lib/OtelManager.js +74 -0
- package/lib/ProcessContainer.js +321 -0
- package/lib/ProcessContainerBun.js +355 -0
- package/lib/ProcessContainerFork.js +42 -0
- package/lib/ProcessContainerForkBun.js +31 -0
- package/lib/ProcessUtils.js +74 -0
- package/lib/TreeKill.js +111 -0
- package/lib/Utility.js +304 -0
- package/lib/VersionCheck.js +46 -0
- package/lib/Watcher.js +117 -0
- package/lib/Worker.js +200 -0
- package/lib/binaries/CLI.js +1092 -0
- package/lib/binaries/DevCLI.js +183 -0
- package/lib/binaries/Runtime.js +101 -0
- package/lib/binaries/Runtime4Docker.js +192 -0
- package/lib/completion.js +229 -0
- package/lib/completion.sh +40 -0
- package/lib/motd +36 -0
- package/lib/templates/Dockerfiles/Dockerfile-nodejs.tpl +8 -0
- package/lib/templates/ecosystem-es.tpl +24 -0
- package/lib/templates/ecosystem-simple-es.tpl +8 -0
- package/lib/templates/ecosystem-simple.tpl +6 -0
- package/lib/templates/ecosystem.tpl +22 -0
- package/lib/templates/init-scripts/launchd.tpl +35 -0
- package/lib/templates/init-scripts/openrc.tpl +52 -0
- package/lib/templates/init-scripts/pm2-init-amazon.sh +86 -0
- package/lib/templates/init-scripts/rcd-openbsd.tpl +41 -0
- package/lib/templates/init-scripts/rcd.tpl +44 -0
- package/lib/templates/init-scripts/smf.tpl +43 -0
- package/lib/templates/init-scripts/systemd-online.tpl +22 -0
- package/lib/templates/init-scripts/systemd.tpl +22 -0
- package/lib/templates/init-scripts/upstart.tpl +103 -0
- package/lib/templates/logrotate.d/pm2 +10 -0
- package/lib/templates/sample-apps/http-server/README.md +14 -0
- package/lib/templates/sample-apps/http-server/api.js +9 -0
- package/lib/templates/sample-apps/http-server/ecosystem.config.js +14 -0
- package/lib/templates/sample-apps/http-server/package.json +11 -0
- package/lib/templates/sample-apps/pm2-plus-metrics-actions/README.md +45 -0
- package/lib/templates/sample-apps/pm2-plus-metrics-actions/custom-metrics.js +66 -0
- package/lib/templates/sample-apps/pm2-plus-metrics-actions/ecosystem.config.js +12 -0
- package/lib/templates/sample-apps/pm2-plus-metrics-actions/package.json +11 -0
- package/lib/templates/sample-apps/python-app/README.md +4 -0
- package/lib/templates/sample-apps/python-app/echo.py +7 -0
- package/lib/templates/sample-apps/python-app/ecosystem.config.js +12 -0
- package/lib/templates/sample-apps/python-app/package.json +11 -0
- package/lib/tools/Config.js +251 -0
- package/lib/tools/SysMetrics.js +375 -0
- package/lib/tools/copydirSync.js +101 -0
- package/lib/tools/deleteFolderRecursive.js +19 -0
- package/lib/tools/find-package-json.js +74 -0
- package/lib/tools/fmt.js +72 -0
- package/lib/tools/interpreter.js +88 -0
- package/lib/tools/isbinaryfile.js +94 -0
- package/lib/tools/json5.js +752 -0
- package/lib/tools/multimeter/bar.js +111 -0
- package/lib/tools/multimeter/charm/encode.js +18 -0
- package/lib/tools/multimeter/charm/index.js +305 -0
- package/lib/tools/multimeter/index.js +76 -0
- package/lib/tools/open.js +56 -0
- package/lib/tools/passwd.js +58 -0
- package/lib/tools/pm2-config-keys.js +165 -0
- package/lib/tools/prompt.js +76 -0
- package/lib/tools/serviceStop.js +149 -0
- package/lib/tools/sexec.js +55 -0
- package/lib/tools/treeify.js +113 -0
- package/lib/tools/typestrip.js +55 -0
- package/lib/tools/which.js +120 -0
- package/lib/tools/xdg-open +861 -0
- package/modules/blessed/LICENSE +20 -0
- package/modules/blessed/README.md +34 -0
- package/modules/blessed/index.js +1 -0
- package/modules/blessed/lib/alias.js +526 -0
- package/modules/blessed/lib/blessed.js +32 -0
- package/modules/blessed/lib/colors.js +530 -0
- package/modules/blessed/lib/events.js +189 -0
- package/modules/blessed/lib/gpmclient.js +221 -0
- package/modules/blessed/lib/helpers.js +165 -0
- package/modules/blessed/lib/keys.js +339 -0
- package/modules/blessed/lib/program.js +4297 -0
- package/modules/blessed/lib/tput.js +3022 -0
- package/modules/blessed/lib/unicode.js +885 -0
- package/modules/blessed/lib/widget.js +32 -0
- package/modules/blessed/lib/widgets/box.js +34 -0
- package/modules/blessed/lib/widgets/element.js +2570 -0
- package/modules/blessed/lib/widgets/list.js +599 -0
- package/modules/blessed/lib/widgets/log.js +83 -0
- package/modules/blessed/lib/widgets/node.js +282 -0
- package/modules/blessed/lib/widgets/screen.js +2298 -0
- package/modules/blessed/lib/widgets/scrollablebox.js +389 -0
- package/modules/blessed/lib/widgets/scrollabletext.js +35 -0
- package/modules/blessed/lib/widgets/text.js +35 -0
- package/modules/blessed/usr/linux +0 -0
- package/modules/blessed/usr/windows-ansi +0 -0
- package/modules/blessed/usr/xterm +0 -0
- package/modules/blessed/usr/xterm-256color +0 -0
- package/modules/blessed/usr/xterm.termcap +243 -0
- package/modules/chokidar/LICENSE +21 -0
- package/modules/chokidar/VENDORED.md +76 -0
- package/modules/chokidar/index.js +979 -0
- package/modules/chokidar/lib/brace-expand.js +180 -0
- package/modules/chokidar/lib/constants.js +66 -0
- package/modules/chokidar/lib/fsevents-handler.js +526 -0
- package/modules/chokidar/lib/nodefs-handler.js +654 -0
- package/modules/fclone.js +49 -0
- package/modules/pm2-axon/index.js +2 -0
- package/modules/pm2-axon/lib/configurable/History.md +5 -0
- package/modules/pm2-axon/lib/configurable/Makefile +7 -0
- package/modules/pm2-axon/lib/configurable/Readme.md +57 -0
- package/modules/pm2-axon/lib/configurable/index.js +2 -0
- package/modules/pm2-axon/lib/configurable/lib/configurable.js +47 -0
- package/modules/pm2-axon/lib/configurable/package.json +68 -0
- package/modules/pm2-axon/lib/index.js +44 -0
- package/modules/pm2-axon/lib/plugins/queue.js +71 -0
- package/modules/pm2-axon/lib/plugins/round-robin.js +55 -0
- package/modules/pm2-axon/lib/sockets/pub-emitter.js +26 -0
- package/modules/pm2-axon/lib/sockets/pub.js +77 -0
- package/modules/pm2-axon/lib/sockets/pull.js +37 -0
- package/modules/pm2-axon/lib/sockets/push.js +32 -0
- package/modules/pm2-axon/lib/sockets/rep.js +73 -0
- package/modules/pm2-axon/lib/sockets/req.js +101 -0
- package/modules/pm2-axon/lib/sockets/sock.js +430 -0
- package/modules/pm2-axon/lib/sockets/sub-emitter.js +92 -0
- package/modules/pm2-axon/lib/sockets/sub.js +147 -0
- package/modules/pm2-axon/lib/utils.js +19 -0
- package/modules/pm2-axon-rpc/index.js +3 -0
- package/modules/pm2-axon-rpc/lib/client.js +63 -0
- package/modules/pm2-axon-rpc/lib/server.js +139 -0
- package/modules/pm2-io-agent/LICENSE +661 -0
- package/modules/pm2-io-agent/README.md +62 -0
- package/modules/pm2-io-agent/config.js +30 -0
- package/modules/pm2-io-agent/constants.js +118 -0
- package/modules/pm2-io-agent/index.js +2 -0
- package/modules/pm2-io-agent/src/InteractorClient.js +513 -0
- package/modules/pm2-io-agent/src/InteractorDaemon.js +455 -0
- package/modules/pm2-io-agent/src/PM2Client.js +112 -0
- package/modules/pm2-io-agent/src/PM2Interface.js +180 -0
- package/modules/pm2-io-agent/src/TransporterInterface.js +173 -0
- package/modules/pm2-io-agent/src/Utility.js +392 -0
- package/modules/pm2-io-agent/src/WatchDog.js +70 -0
- package/modules/pm2-io-agent/src/push/DataRetriever.js +77 -0
- package/modules/pm2-io-agent/src/push/PushInteractor.js +206 -0
- package/modules/pm2-io-agent/src/push/TransactionAggregator.js +670 -0
- package/modules/pm2-io-agent/src/reverse/ReverseInteractor.js +128 -0
- package/modules/pm2-io-agent/src/transporters/Transporter.js +129 -0
- package/modules/pm2-io-agent/src/transporters/WebsocketTransport.js +202 -0
- package/modules/pm2-io-agent/src/utils/BinaryHeap.js +135 -0
- package/modules/pm2-io-agent/src/utils/EDS.js +111 -0
- package/modules/pm2-io-agent/src/utils/probes/Histogram.js +204 -0
- package/modules/pm2-io-agent/src/utils/units.js +10 -0
- package/modules/pm2-io-bpm/configuration.js +141 -0
- package/modules/pm2-io-bpm/constants.js +10 -0
- package/modules/pm2-io-bpm/featureManager.js +110 -0
- package/modules/pm2-io-bpm/features/dependencies.js +48 -0
- package/modules/pm2-io-bpm/features/events.js +50 -0
- package/modules/pm2-io-bpm/features/metrics.js +102 -0
- package/modules/pm2-io-bpm/features/notify.js +238 -0
- package/modules/pm2-io-bpm/features/profiling.js +70 -0
- package/modules/pm2-io-bpm/features/tracing.js +174 -0
- package/modules/pm2-io-bpm/index.js +11 -0
- package/modules/pm2-io-bpm/metrics/eventLoopMetrics.js +136 -0
- package/modules/pm2-io-bpm/metrics/httpMetrics.js +175 -0
- package/modules/pm2-io-bpm/metrics/network.js +132 -0
- package/modules/pm2-io-bpm/metrics/runtime.js +161 -0
- package/modules/pm2-io-bpm/metrics/v8.js +104 -0
- package/modules/pm2-io-bpm/otel/constants.js +7 -0
- package/modules/pm2-io-bpm/otel/custom-zipkin-exporter/platform/index.js +17 -0
- package/modules/pm2-io-bpm/otel/custom-zipkin-exporter/platform/node/index.js +17 -0
- package/modules/pm2-io-bpm/otel/custom-zipkin-exporter/platform/node/util.js +51 -0
- package/modules/pm2-io-bpm/otel/custom-zipkin-exporter/transform.js +137 -0
- package/modules/pm2-io-bpm/otel/custom-zipkin-exporter/types.js +24 -0
- package/modules/pm2-io-bpm/otel/custom-zipkin-exporter/utils.js +23 -0
- package/modules/pm2-io-bpm/otel/custom-zipkin-exporter/zipkin.js +149 -0
- package/modules/pm2-io-bpm/pmx.js +380 -0
- package/modules/pm2-io-bpm/profilers/addonProfiler.js +193 -0
- package/modules/pm2-io-bpm/profilers/inspectorProfiler.js +302 -0
- package/modules/pm2-io-bpm/serviceManager.js +21 -0
- package/modules/pm2-io-bpm/services/actions.js +159 -0
- package/modules/pm2-io-bpm/services/inspector.js +43 -0
- package/modules/pm2-io-bpm/services/metrics.js +186 -0
- package/modules/pm2-io-bpm/services/runtimeStats.js +54 -0
- package/modules/pm2-io-bpm/services/transport.js +11 -0
- package/modules/pm2-io-bpm/transports/IPCTransport.js +115 -0
- package/modules/pm2-io-bpm/utils/BinaryHeap.js +134 -0
- package/modules/pm2-io-bpm/utils/EDS.js +113 -0
- package/modules/pm2-io-bpm/utils/EWMA.js +32 -0
- package/modules/pm2-io-bpm/utils/autocast.js +61 -0
- package/modules/pm2-io-bpm/utils/metrics/counter.js +33 -0
- package/modules/pm2-io-bpm/utils/metrics/gauge.js +23 -0
- package/modules/pm2-io-bpm/utils/metrics/histogram.js +192 -0
- package/modules/pm2-io-bpm/utils/metrics/meter.js +46 -0
- package/modules/pm2-io-bpm/utils/miscellaneous.js +19 -0
- package/modules/pm2-io-bpm/utils/module.js +67 -0
- package/modules/pm2-io-bpm/utils/shimmer.js +19 -0
- package/modules/pm2-io-bpm/utils/stackParser.js +160 -0
- package/modules/pm2-io-bpm/utils/transactionAggregator.js +429 -0
- package/modules/pm2-io-bpm/utils/units.js +16 -0
- package/modules/vizion/LICENSE +13 -0
- package/modules/vizion/README.md +133 -0
- package/modules/vizion/index.js +1 -0
- package/modules/vizion/lib/git/git.js +247 -0
- package/modules/vizion/lib/vizion.js +52 -0
- package/package.json +170 -4
- package/paths.js +121 -0
- package/pm2 +11 -0
- package/types/index.d.ts +732 -0
- package/types/tsconfig.json +14 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
|
|
2
|
+
const util = require('util')
|
|
3
|
+
const spawn = require('child_process').spawn
|
|
4
|
+
const DockerMgmt = {}
|
|
5
|
+
|
|
6
|
+
module.exports = DockerMgmt
|
|
7
|
+
|
|
8
|
+
function execDocker(cmd, cb) {
|
|
9
|
+
var i = spawn('docker', cmd, {
|
|
10
|
+
stdio : 'inherit',
|
|
11
|
+
env: process.env,
|
|
12
|
+
shell : true
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
i.on('close', cb)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
DockerMgmt.processCommand = function(PM2, start_id, select_id, action, cb) {
|
|
19
|
+
PM2.Client.executeRemote('getSystemData', {}, (err, sys_infos) => {
|
|
20
|
+
if (sys_infos.containers && sys_infos.containers.length == 0)
|
|
21
|
+
return cb(new Error(`Process ${select_id} not found`))
|
|
22
|
+
var container = sys_infos.containers[select_id - start_id - 1]
|
|
23
|
+
if (action == 'stopProcessId')
|
|
24
|
+
execDocker(['stop', container.id], cb)
|
|
25
|
+
if (action == 'deleteProcessId')
|
|
26
|
+
execDocker(['rm', container.id], cb)
|
|
27
|
+
if (action == 'restartProcessId')
|
|
28
|
+
execDocker(['restart', container.id], cb)
|
|
29
|
+
})
|
|
30
|
+
}
|
package/lib/API/Log.js
ADDED
|
@@ -0,0 +1,388 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2013-present 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
|
+
var fs = require('fs'),
|
|
7
|
+
util = require('util'),
|
|
8
|
+
chalk = require('ansis'),
|
|
9
|
+
forEachLimit = require('async/forEachLimit'),
|
|
10
|
+
dayjs = require('dayjs');
|
|
11
|
+
|
|
12
|
+
var Log = module.exports = {};
|
|
13
|
+
|
|
14
|
+
var DEFAULT_PADDING = ' ';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Tail logs from file stream.
|
|
18
|
+
* @param {Object} apps_list
|
|
19
|
+
* @param {Number} lines
|
|
20
|
+
* @param {Boolean} raw
|
|
21
|
+
* @param {Function} callback
|
|
22
|
+
* @return
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Read the last N lines of a file. Never throws: a missing, unreadable
|
|
27
|
+
* or empty file yields an empty array.
|
|
28
|
+
* @param {String} filename
|
|
29
|
+
* @param {Number} lines
|
|
30
|
+
* @param {Function} callback (lines: Array<String>)
|
|
31
|
+
*/
|
|
32
|
+
// Read window: starts at ~200 bytes/line, doubles while the window does
|
|
33
|
+
// not hold enough lines, never exceeds MAX_READ_WINDOW bytes
|
|
34
|
+
var LINE_SIZE_HINT = 200;
|
|
35
|
+
var MAX_READ_WINDOW = 10 * 1024 * 1024;
|
|
36
|
+
|
|
37
|
+
Log.getLastLines = function(filename, lines, callback) {
|
|
38
|
+
lines = parseInt(lines, 10);
|
|
39
|
+
if (!filename || !(lines > 0))
|
|
40
|
+
return callback([]);
|
|
41
|
+
|
|
42
|
+
fs.stat(filename, function(err, stat) {
|
|
43
|
+
if (err || !stat.isFile() || stat.size === 0)
|
|
44
|
+
return callback([]);
|
|
45
|
+
|
|
46
|
+
fs.open(filename, 'r', function(err, fd) {
|
|
47
|
+
if (err)
|
|
48
|
+
return callback([]);
|
|
49
|
+
|
|
50
|
+
var finish = function(result) {
|
|
51
|
+
fs.close(fd, function() {});
|
|
52
|
+
callback(result);
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
var attempt = function(window) {
|
|
56
|
+
window = Math.min(window, MAX_READ_WINDOW, stat.size);
|
|
57
|
+
var start = stat.size - window;
|
|
58
|
+
// read one extra byte before the window to know whether the
|
|
59
|
+
// window begins on a line boundary
|
|
60
|
+
var from = start > 0 ? start - 1 : 0;
|
|
61
|
+
var len = stat.size - from;
|
|
62
|
+
var buf = Buffer.alloc(len);
|
|
63
|
+
|
|
64
|
+
fs.read(fd, buf, 0, len, from, function(err, bytes) {
|
|
65
|
+
if (err)
|
|
66
|
+
return finish([]);
|
|
67
|
+
|
|
68
|
+
var text = buf.toString('utf8', 0, bytes);
|
|
69
|
+
var parts = text.split('\n');
|
|
70
|
+
|
|
71
|
+
if (parts.length && parts[parts.length - 1] === '')
|
|
72
|
+
parts.pop();
|
|
73
|
+
// the first segment is either the extra byte '\n' (empty part)
|
|
74
|
+
// or a partial line: drop it in both cases
|
|
75
|
+
if (start > 0 && parts.length)
|
|
76
|
+
parts.shift();
|
|
77
|
+
|
|
78
|
+
if (parts.length < lines && start > 0 && window < MAX_READ_WINDOW)
|
|
79
|
+
return attempt(window * 2);
|
|
80
|
+
|
|
81
|
+
finish(parts.slice(-lines).map(function(line) {
|
|
82
|
+
return line.replace(/\r$/, '');
|
|
83
|
+
}));
|
|
84
|
+
});
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
attempt(lines * LINE_SIZE_HINT);
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
Log.tail = function(apps_list, lines, raw, callback) {
|
|
93
|
+
var that = this;
|
|
94
|
+
|
|
95
|
+
if (lines === 0 || apps_list.length === 0)
|
|
96
|
+
return callback && callback();
|
|
97
|
+
|
|
98
|
+
var count = 0;
|
|
99
|
+
|
|
100
|
+
var getLastLines = Log.getLastLines;
|
|
101
|
+
|
|
102
|
+
apps_list.sort(function(a, b) {
|
|
103
|
+
return (fs.existsSync(a.path) ? fs.statSync(a.path).mtime.valueOf() : 0) -
|
|
104
|
+
(fs.existsSync(b.path) ? fs.statSync(b.path).mtime.valueOf() : 0);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
forEachLimit(apps_list, 1, function(app, next) {
|
|
108
|
+
if (!fs.existsSync(app.path || ''))
|
|
109
|
+
return next();
|
|
110
|
+
|
|
111
|
+
getLastLines(app.path, lines, function(output) {
|
|
112
|
+
console.log(chalk.gray('%s last %d lines:'), app.path, lines);
|
|
113
|
+
output.forEach(function(out) {
|
|
114
|
+
if (raw)
|
|
115
|
+
return app.type === 'err' ? console.error(out) : console.log(out);
|
|
116
|
+
if (app.type === 'out')
|
|
117
|
+
process.stdout.write(chalk.green(pad(DEFAULT_PADDING, app.app_name) + ' | '));
|
|
118
|
+
else if (app.type === 'err')
|
|
119
|
+
process.stdout.write(chalk.red(pad(DEFAULT_PADDING, app.app_name) + ' | '));
|
|
120
|
+
else
|
|
121
|
+
process.stdout.write(chalk.blue(pad(DEFAULT_PADDING, 'PM2') + ' | '));
|
|
122
|
+
console.log(out);
|
|
123
|
+
});
|
|
124
|
+
if (output.length)
|
|
125
|
+
process.stdout.write('\n');
|
|
126
|
+
next();
|
|
127
|
+
});
|
|
128
|
+
}, function() {
|
|
129
|
+
callback && callback();
|
|
130
|
+
});
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Stream logs in realtime from the bus eventemitter.
|
|
135
|
+
* @param {String} id
|
|
136
|
+
* @param {Boolean} raw
|
|
137
|
+
* @return
|
|
138
|
+
*/
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Turn a "/pattern/" CLI argument into a RegExp, null otherwise
|
|
142
|
+
* @param {String} id
|
|
143
|
+
* @return {RegExp|null}
|
|
144
|
+
*/
|
|
145
|
+
Log.parseRegexId = function(id) {
|
|
146
|
+
if (typeof id !== 'string' || id.length < 3 || id[0] !== '/' || id[id.length - 1] !== '/')
|
|
147
|
+
return null;
|
|
148
|
+
try {
|
|
149
|
+
return new RegExp(id.slice(1, -1));
|
|
150
|
+
} catch (e) {
|
|
151
|
+
return null;
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
Log.stream = function(Client, id, raw, timestamp, exclusive, highlight) {
|
|
156
|
+
var that = this;
|
|
157
|
+
var regex = Log.parseRegexId(id);
|
|
158
|
+
|
|
159
|
+
Client.launchBus(function(err, bus, socket) {
|
|
160
|
+
|
|
161
|
+
socket.on('reconnect attempt', function() {
|
|
162
|
+
if (global._auto_exit === true) {
|
|
163
|
+
if (timestamp)
|
|
164
|
+
process.stdout.write(chalk['dim'](chalk.gray(dayjs().format(timestamp) + ' ')));
|
|
165
|
+
process.stdout.write(chalk.blue(pad(DEFAULT_PADDING, 'PM2') + ' | ') + '[[[ Target PM2 killed. ]]]');
|
|
166
|
+
process.exit(0);
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
var min_padding = 3
|
|
171
|
+
|
|
172
|
+
bus.on('log:*', function(type, packet) {
|
|
173
|
+
var isMatchingProcess = id === 'all'
|
|
174
|
+
|| packet.process.name == id
|
|
175
|
+
|| packet.process.pm_id == id
|
|
176
|
+
|| packet.process.namespace == id
|
|
177
|
+
|| (regex !== null && regex.test(packet.process.name));
|
|
178
|
+
|
|
179
|
+
if (!isMatchingProcess)
|
|
180
|
+
return;
|
|
181
|
+
|
|
182
|
+
if ((type === 'out' && exclusive === 'err')
|
|
183
|
+
|| (type === 'err' && exclusive === 'out')
|
|
184
|
+
|| (type === 'PM2' && exclusive !== false))
|
|
185
|
+
return;
|
|
186
|
+
|
|
187
|
+
var lines;
|
|
188
|
+
|
|
189
|
+
if (typeof(packet.data) === 'string')
|
|
190
|
+
lines = (packet.data || '').split('\n');
|
|
191
|
+
else
|
|
192
|
+
return;
|
|
193
|
+
|
|
194
|
+
lines.forEach(function(line) {
|
|
195
|
+
if (!line || line.length === 0) return;
|
|
196
|
+
|
|
197
|
+
if (raw)
|
|
198
|
+
return type === 'err' ? process.stderr.write(util.format(line) + '\n') : process.stdout.write(util.format(line) + '\n');
|
|
199
|
+
|
|
200
|
+
if (timestamp)
|
|
201
|
+
process.stdout.write(chalk['dim'](chalk.gray(dayjs().format(timestamp) + ' ')));
|
|
202
|
+
|
|
203
|
+
var name = packet.process.pm_id + '|' + packet.process.name;
|
|
204
|
+
|
|
205
|
+
if (name.length > min_padding)
|
|
206
|
+
min_padding = name.length + 1
|
|
207
|
+
|
|
208
|
+
if (type === 'out')
|
|
209
|
+
process.stdout.write(chalk.green(pad(' '.repeat(min_padding), name) + ' | '));
|
|
210
|
+
else if (type === 'err')
|
|
211
|
+
process.stdout.write(chalk.red(pad(' '.repeat(min_padding), name) + ' | '));
|
|
212
|
+
else if (!raw && (id === 'all' || id === 'PM2'))
|
|
213
|
+
process.stdout.write(chalk.blue(pad(' '.repeat(min_padding), 'PM2') + ' | '));
|
|
214
|
+
if (highlight)
|
|
215
|
+
process.stdout.write(util.format(line).replace(highlight, chalk.bgBlackBright(highlight)) + '\n');
|
|
216
|
+
else
|
|
217
|
+
process.stdout.write(util.format(line)+ '\n');
|
|
218
|
+
});
|
|
219
|
+
});
|
|
220
|
+
});
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
Log.devStream = function(Client, id, raw, timestamp, exclusive) {
|
|
224
|
+
var that = this;
|
|
225
|
+
|
|
226
|
+
Client.launchBus(function(err, bus) {
|
|
227
|
+
|
|
228
|
+
setTimeout(function() {
|
|
229
|
+
bus.on('process:event', function(packet) {
|
|
230
|
+
if (packet.event == 'online')
|
|
231
|
+
console.log(chalk.green('[rundev] App %s restarted'), packet.process.name);
|
|
232
|
+
});
|
|
233
|
+
}, 1000);
|
|
234
|
+
|
|
235
|
+
var min_padding = 3
|
|
236
|
+
|
|
237
|
+
bus.on('log:*', function(type, packet) {
|
|
238
|
+
if (id !== 'all'
|
|
239
|
+
&& packet.process.name != id
|
|
240
|
+
&& packet.process.pm_id != id)
|
|
241
|
+
return;
|
|
242
|
+
|
|
243
|
+
if ((type === 'out' && exclusive === 'err')
|
|
244
|
+
|| (type === 'err' && exclusive === 'out')
|
|
245
|
+
|| (type === 'PM2' && exclusive !== false))
|
|
246
|
+
return;
|
|
247
|
+
|
|
248
|
+
if (type === 'PM2')
|
|
249
|
+
return;
|
|
250
|
+
|
|
251
|
+
var name = packet.process.pm_id + '|' + packet.process.name;
|
|
252
|
+
|
|
253
|
+
var lines;
|
|
254
|
+
|
|
255
|
+
if (typeof(packet.data) === 'string')
|
|
256
|
+
lines = (packet.data || '').split('\n');
|
|
257
|
+
else
|
|
258
|
+
return;
|
|
259
|
+
|
|
260
|
+
lines.forEach(function(line) {
|
|
261
|
+
if (!line || line.length === 0) return;
|
|
262
|
+
|
|
263
|
+
if (raw)
|
|
264
|
+
return process.stdout.write(util.format(line) + '\n');
|
|
265
|
+
|
|
266
|
+
if (timestamp)
|
|
267
|
+
process.stdout.write(chalk['dim'](chalk.gray(dayjs().format(timestamp) + ' ')));
|
|
268
|
+
|
|
269
|
+
var name = packet.process.name + '-' + packet.process.pm_id;
|
|
270
|
+
|
|
271
|
+
if (name.length > min_padding)
|
|
272
|
+
min_padding = name.length + 1
|
|
273
|
+
|
|
274
|
+
if (type === 'out')
|
|
275
|
+
process.stdout.write(chalk.green(pad(' '.repeat(min_padding), name) + ' | '));
|
|
276
|
+
else if (type === 'err')
|
|
277
|
+
process.stdout.write(chalk.red(pad(' '.repeat(min_padding), name) + ' | '));
|
|
278
|
+
else if (!raw && (id === 'all' || id === 'PM2'))
|
|
279
|
+
process.stdout.write(chalk.blue(pad(' '.repeat(min_padding), 'PM2') + ' | '));
|
|
280
|
+
process.stdout.write(util.format(line) + '\n');
|
|
281
|
+
});
|
|
282
|
+
});
|
|
283
|
+
});
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
Log.jsonStream = function(Client, id) {
|
|
287
|
+
var that = this;
|
|
288
|
+
|
|
289
|
+
Client.launchBus(function(err, bus) {
|
|
290
|
+
if (err) console.error(err);
|
|
291
|
+
|
|
292
|
+
bus.on('process:event', function(packet) {
|
|
293
|
+
process.stdout.write(JSON.stringify({
|
|
294
|
+
timestamp : dayjs(packet.at),
|
|
295
|
+
type : 'process_event',
|
|
296
|
+
status : packet.event,
|
|
297
|
+
app_name : packet.process.name
|
|
298
|
+
}));
|
|
299
|
+
process.stdout.write('\n');
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
bus.on('log:*', function(type, packet) {
|
|
303
|
+
if (id !== 'all'
|
|
304
|
+
&& packet.process.name != id
|
|
305
|
+
&& packet.process.pm_id != id)
|
|
306
|
+
return;
|
|
307
|
+
|
|
308
|
+
if (type === 'PM2')
|
|
309
|
+
return;
|
|
310
|
+
|
|
311
|
+
if (typeof(packet.data) == 'string')
|
|
312
|
+
packet.data = packet.data.replace(/(\r\n|\n|\r)/gm,'');
|
|
313
|
+
|
|
314
|
+
process.stdout.write(JSON.stringify({
|
|
315
|
+
message : packet.data,
|
|
316
|
+
timestamp : dayjs(packet.at),
|
|
317
|
+
type : type,
|
|
318
|
+
process_id : packet.process.pm_id,
|
|
319
|
+
app_name : packet.process.name
|
|
320
|
+
}));
|
|
321
|
+
process.stdout.write('\n');
|
|
322
|
+
});
|
|
323
|
+
});
|
|
324
|
+
};
|
|
325
|
+
|
|
326
|
+
Log.formatStream = function(Client, id, raw, timestamp, exclusive, highlight) {
|
|
327
|
+
var that = this;
|
|
328
|
+
|
|
329
|
+
Client.launchBus(function(err, bus) {
|
|
330
|
+
|
|
331
|
+
bus.on('log:*', function(type, packet) {
|
|
332
|
+
if (id !== 'all'
|
|
333
|
+
&& packet.process.name != id
|
|
334
|
+
&& packet.process.pm_id != id)
|
|
335
|
+
return;
|
|
336
|
+
|
|
337
|
+
if ((type === 'out' && exclusive === 'err')
|
|
338
|
+
|| (type === 'err' && exclusive === 'out')
|
|
339
|
+
|| (type === 'PM2' && exclusive !== false))
|
|
340
|
+
return;
|
|
341
|
+
|
|
342
|
+
if (type === 'PM2' && raw)
|
|
343
|
+
return;
|
|
344
|
+
|
|
345
|
+
var name = packet.process.name + '-' + packet.process.pm_id;
|
|
346
|
+
|
|
347
|
+
var lines;
|
|
348
|
+
|
|
349
|
+
if (typeof(packet.data) === 'string')
|
|
350
|
+
lines = (packet.data || '').split('\n');
|
|
351
|
+
else
|
|
352
|
+
return;
|
|
353
|
+
|
|
354
|
+
lines.forEach(function(line) {
|
|
355
|
+
if (!line || line.length === 0) return;
|
|
356
|
+
|
|
357
|
+
if (!raw) {
|
|
358
|
+
if (timestamp)
|
|
359
|
+
process.stdout.write('timestamp=' + dayjs().format(timestamp) + ' ');
|
|
360
|
+
if (packet.process.name === 'PM2')
|
|
361
|
+
process.stdout.write('app=pm2 ');
|
|
362
|
+
if (packet.process.name !== 'PM2')
|
|
363
|
+
process.stdout.write('app=' + packet.process.name + ' id=' + packet.process.pm_id + ' ');
|
|
364
|
+
if (type === 'out')
|
|
365
|
+
process.stdout.write('type=out ');
|
|
366
|
+
else if (type === 'err')
|
|
367
|
+
process.stdout.write('type=error ');
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
process.stdout.write('message=');
|
|
371
|
+
if (highlight)
|
|
372
|
+
process.stdout.write(util.format(line).replace(highlight, chalk.bgBlackBright(highlight)) + '\n');
|
|
373
|
+
else
|
|
374
|
+
process.stdout.write(util.format(line) + '\n');
|
|
375
|
+
});
|
|
376
|
+
});
|
|
377
|
+
});
|
|
378
|
+
};
|
|
379
|
+
|
|
380
|
+
function pad(pad, str, padLeft) {
|
|
381
|
+
if (typeof str === 'undefined')
|
|
382
|
+
return pad;
|
|
383
|
+
if (padLeft) {
|
|
384
|
+
return (pad + str).slice(-pad.length);
|
|
385
|
+
} else {
|
|
386
|
+
return (str + pad).substring(0, pad.length);
|
|
387
|
+
}
|
|
388
|
+
}
|