@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,355 @@
|
|
|
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
|
+
|
|
7
|
+
var p = require('path');
|
|
8
|
+
var cst = require('../constants');
|
|
9
|
+
var Utility = require('./Utility.js');
|
|
10
|
+
var ProcessUtils = require('./ProcessUtils');
|
|
11
|
+
var util = require('util')
|
|
12
|
+
|
|
13
|
+
// Load all env-vars from master.
|
|
14
|
+
var pm2_env = JSON.parse(process.env.pm2_env);
|
|
15
|
+
for(var k in pm2_env) {
|
|
16
|
+
process.env[k] = pm2_env[k];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (pm2_env.disable_source_map_support !== true &&
|
|
20
|
+
typeof process.setSourceMapsEnabled === 'function')
|
|
21
|
+
process.setSourceMapsEnabled(true);
|
|
22
|
+
|
|
23
|
+
// Rename process
|
|
24
|
+
process.title = process.env.PROCESS_TITLE || 'bun ' + pm2_env.pm_exec_path;
|
|
25
|
+
|
|
26
|
+
delete process.env.pm2_env;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Main entrance to wrap the desired code
|
|
30
|
+
*/
|
|
31
|
+
(function ProcessContainer() {
|
|
32
|
+
var fs = require('fs');
|
|
33
|
+
|
|
34
|
+
ProcessUtils.injectModules()
|
|
35
|
+
|
|
36
|
+
var stdFile = pm2_env.pm_log_path;
|
|
37
|
+
var outFile = pm2_env.pm_out_log_path;
|
|
38
|
+
var errFile = pm2_env.pm_err_log_path;
|
|
39
|
+
var pidFile = pm2_env.pm_pid_path;
|
|
40
|
+
var script = pm2_env.pm_exec_path;
|
|
41
|
+
|
|
42
|
+
var original_send = process.send;
|
|
43
|
+
|
|
44
|
+
process.send = function() {
|
|
45
|
+
if (process.connected)
|
|
46
|
+
original_send.apply(this, arguments);
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
//send node version
|
|
50
|
+
if (process.versions && process.versions.node) {
|
|
51
|
+
process.send({
|
|
52
|
+
'node_version': process.versions.node
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (cst.MODIFY_REQUIRE)
|
|
57
|
+
require.main.filename = pm2_env.pm_exec_path;
|
|
58
|
+
|
|
59
|
+
// Resets global paths for require()
|
|
60
|
+
require('module')._initPaths();
|
|
61
|
+
|
|
62
|
+
try {
|
|
63
|
+
var pid = process.pid
|
|
64
|
+
if (typeof(pid) !== 'undefined')
|
|
65
|
+
fs.writeFileSync(pidFile, process.pid.toString());
|
|
66
|
+
} catch (e) {
|
|
67
|
+
console.error(e.stack || e);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Add args to process if args specified on start
|
|
71
|
+
if (process.env.args != null)
|
|
72
|
+
process.argv = process.argv.concat(pm2_env.args);
|
|
73
|
+
|
|
74
|
+
// stdio, including: out, err and entire (both out and err if necessary).
|
|
75
|
+
var stds = {
|
|
76
|
+
out: outFile,
|
|
77
|
+
err: errFile
|
|
78
|
+
};
|
|
79
|
+
stdFile && (stds.std = stdFile);
|
|
80
|
+
|
|
81
|
+
// uid/gid management
|
|
82
|
+
if (pm2_env.uid || pm2_env.gid) {
|
|
83
|
+
try {
|
|
84
|
+
if (process.env.gid)
|
|
85
|
+
process.setgid(pm2_env.gid);
|
|
86
|
+
if (pm2_env.uid)
|
|
87
|
+
process.setuid(pm2_env.uid);
|
|
88
|
+
} catch(e) {
|
|
89
|
+
setTimeout(function() {
|
|
90
|
+
console.error('%s on call %s', e.message, e.syscall);
|
|
91
|
+
console.error('%s is not accessible', pm2_env.uid);
|
|
92
|
+
return process.exit(1);
|
|
93
|
+
}, 100);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
exec(script, stds);
|
|
98
|
+
})();
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Description
|
|
102
|
+
* @method exec
|
|
103
|
+
* @param {} script
|
|
104
|
+
* @param {} stds
|
|
105
|
+
* @return
|
|
106
|
+
*/
|
|
107
|
+
function exec(script, stds) {
|
|
108
|
+
process.on('message', function (msg) {
|
|
109
|
+
if (msg.type === 'log:reload') {
|
|
110
|
+
for (var k in stds){
|
|
111
|
+
if (typeof stds[k] == 'object' && !isNaN(stds[k].fd)){
|
|
112
|
+
if (stds[k].destroy) stds[k].destroy();
|
|
113
|
+
else if (stds[k].end) stds[k].end();
|
|
114
|
+
else if (stds[k].close) stds[k].close();
|
|
115
|
+
stds[k] = stds[k]._file;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
Utility.startLogging(stds, function (err) {
|
|
119
|
+
if (err)
|
|
120
|
+
return console.error('Failed to reload logs:', err.stack);
|
|
121
|
+
console.log('Reloading log...');
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
var dayjs = null;
|
|
127
|
+
|
|
128
|
+
if (pm2_env.log_date_format)
|
|
129
|
+
dayjs = require('dayjs');
|
|
130
|
+
|
|
131
|
+
Utility.startLogging(stds, function (err) {
|
|
132
|
+
if (err) {
|
|
133
|
+
process.send({
|
|
134
|
+
type : 'process:exception',
|
|
135
|
+
data : {
|
|
136
|
+
message: err.message,
|
|
137
|
+
syscall: 'ProcessContainer.startLogging'
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
throw err;
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
['warn', 'error'].forEach((method) => {
|
|
145
|
+
console[method] = (...args) => {
|
|
146
|
+
let log_data = null;
|
|
147
|
+
|
|
148
|
+
const msg = util.format(...args);
|
|
149
|
+
|
|
150
|
+
if (pm2_env.disable_logs === true) {
|
|
151
|
+
return false;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if (pm2_env.log_type && pm2_env.log_type === 'json') {
|
|
155
|
+
log_data = JSON.stringify({
|
|
156
|
+
message : msg,
|
|
157
|
+
timestamp : pm2_env.log_date_format && dayjs ?
|
|
158
|
+
dayjs().format(pm2_env.log_date_format) : new Date().toISOString(),
|
|
159
|
+
type : 'err',
|
|
160
|
+
process_id : pm2_env.pm_id,
|
|
161
|
+
app_name : pm2_env.name
|
|
162
|
+
}) + '\n';
|
|
163
|
+
}
|
|
164
|
+
else if (pm2_env.log_date_format && dayjs)
|
|
165
|
+
log_data = `${dayjs().format(pm2_env.log_date_format)}: ${msg}`;
|
|
166
|
+
else
|
|
167
|
+
log_data = msg.endsWith('\n') ? msg : msg + '\n';
|
|
168
|
+
|
|
169
|
+
// Send the log message to the master process
|
|
170
|
+
process.send({
|
|
171
|
+
type: 'log:err',
|
|
172
|
+
data: log_data,
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
stds.std && stds.std.write && stds.std.write(log_data);
|
|
176
|
+
stds.err && stds.err.write && stds.err.write(log_data);
|
|
177
|
+
};
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
['log', 'info'].forEach((method) => {
|
|
181
|
+
console[method] = (...args) => {
|
|
182
|
+
let log_data = null;
|
|
183
|
+
|
|
184
|
+
const msg = util.format(...args);
|
|
185
|
+
|
|
186
|
+
if (pm2_env.disable_logs === true) {
|
|
187
|
+
return false;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
if (pm2_env.log_type && pm2_env.log_type === 'json') {
|
|
191
|
+
log_data = JSON.stringify({
|
|
192
|
+
message : msg,
|
|
193
|
+
timestamp : pm2_env.log_date_format && dayjs ?
|
|
194
|
+
dayjs().format(pm2_env.log_date_format) : new Date().toISOString(),
|
|
195
|
+
type : 'out',
|
|
196
|
+
process_id : pm2_env.pm_id,
|
|
197
|
+
app_name : pm2_env.name
|
|
198
|
+
}) + '\n';
|
|
199
|
+
}
|
|
200
|
+
else if (pm2_env.log_date_format && dayjs)
|
|
201
|
+
log_data = `${dayjs().format(pm2_env.log_date_format)}: ${msg}`;
|
|
202
|
+
else
|
|
203
|
+
log_data = msg.endsWith('\n') ? msg : msg + '\n';
|
|
204
|
+
|
|
205
|
+
// Send the log message to the master process
|
|
206
|
+
process.send({
|
|
207
|
+
type: 'log:out',
|
|
208
|
+
data: log_data,
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
stds.std && stds.std.write && stds.std.write(log_data);
|
|
212
|
+
stds.out && stds.out.write && stds.out.write(log_data);
|
|
213
|
+
};
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
process.stderr.write = (function(write) {
|
|
217
|
+
return function(string, encoding, cb) {
|
|
218
|
+
var log_data = null;
|
|
219
|
+
|
|
220
|
+
// Disable logs if specified
|
|
221
|
+
if (pm2_env.disable_logs === true) {
|
|
222
|
+
return cb ? cb() : false;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
if (pm2_env.log_type && pm2_env.log_type === 'json') {
|
|
226
|
+
log_data = JSON.stringify({
|
|
227
|
+
message : string.toString(),
|
|
228
|
+
timestamp : pm2_env.log_date_format && dayjs ?
|
|
229
|
+
dayjs().format(pm2_env.log_date_format) : new Date().toISOString(),
|
|
230
|
+
type : 'err',
|
|
231
|
+
process_id : pm2_env.pm_id,
|
|
232
|
+
app_name : pm2_env.name
|
|
233
|
+
}) + '\n';
|
|
234
|
+
}
|
|
235
|
+
else if (pm2_env.log_date_format && dayjs)
|
|
236
|
+
log_data = `${dayjs().format(pm2_env.log_date_format)}: ${string.toString()}`;
|
|
237
|
+
else
|
|
238
|
+
log_data = string.toString();
|
|
239
|
+
|
|
240
|
+
process.send({
|
|
241
|
+
type : 'log:err',
|
|
242
|
+
topic : 'log:err',
|
|
243
|
+
data : log_data
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
if (Utility.checkPathIsNull(pm2_env.pm_err_log_path) &&
|
|
247
|
+
(!pm2_env.pm_log_path || Utility.checkPathIsNull(pm2_env.pm_log_path)))
|
|
248
|
+
return cb ? cb() : false;
|
|
249
|
+
|
|
250
|
+
stds.std && stds.std.write && stds.std.write(log_data, encoding);
|
|
251
|
+
stds.err && stds.err.write && stds.err.write(log_data, encoding, cb);
|
|
252
|
+
};
|
|
253
|
+
})(process.stderr.write);
|
|
254
|
+
|
|
255
|
+
process.stdout.write = (function(write) {
|
|
256
|
+
return function(string, encoding, cb) {
|
|
257
|
+
var log_data = null;
|
|
258
|
+
|
|
259
|
+
// Disable logs if specified
|
|
260
|
+
if (pm2_env.disable_logs === true) {
|
|
261
|
+
return cb ? cb() : false;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
if (pm2_env.log_type && pm2_env.log_type === 'json') {
|
|
265
|
+
log_data = JSON.stringify({
|
|
266
|
+
message : string.toString(),
|
|
267
|
+
timestamp : pm2_env.log_date_format && dayjs ?
|
|
268
|
+
dayjs().format(pm2_env.log_date_format) : new Date().toISOString(),
|
|
269
|
+
type : 'out',
|
|
270
|
+
process_id : pm2_env.pm_id,
|
|
271
|
+
app_name : pm2_env.name
|
|
272
|
+
}) + '\n';
|
|
273
|
+
}
|
|
274
|
+
else if (pm2_env.log_date_format && dayjs)
|
|
275
|
+
log_data = `${dayjs().format(pm2_env.log_date_format)}: ${string.toString()}`;
|
|
276
|
+
else
|
|
277
|
+
log_data = string.toString();
|
|
278
|
+
|
|
279
|
+
process.send({
|
|
280
|
+
type : 'log:out',
|
|
281
|
+
data : log_data
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
if (Utility.checkPathIsNull(pm2_env.pm_out_log_path) &&
|
|
285
|
+
(!pm2_env.pm_log_path || Utility.checkPathIsNull(pm2_env.pm_log_path)))
|
|
286
|
+
return cb ? cb() : null;
|
|
287
|
+
|
|
288
|
+
stds.std && stds.std.write && stds.std.write(log_data, encoding);
|
|
289
|
+
stds.out && stds.out.write && stds.out.write(log_data, encoding, cb);
|
|
290
|
+
};
|
|
291
|
+
})(process.stdout.write);
|
|
292
|
+
|
|
293
|
+
function getUncaughtExceptionListener(listener) {
|
|
294
|
+
return function uncaughtListener(err) {
|
|
295
|
+
var error = err && err.stack ? err.stack : err;
|
|
296
|
+
|
|
297
|
+
if (listener === 'unhandledRejection') {
|
|
298
|
+
error = 'You have triggered an unhandledRejection, you may have forgotten to catch a Promise rejection:\n' + error;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
logError(['std', 'err'], error);
|
|
302
|
+
|
|
303
|
+
// Notify master that an uncaughtException has been catched
|
|
304
|
+
try {
|
|
305
|
+
if (err) {
|
|
306
|
+
var errObj = {};
|
|
307
|
+
|
|
308
|
+
Object.getOwnPropertyNames(err).forEach(function(key) {
|
|
309
|
+
errObj[key] = err[key];
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
process.send({
|
|
314
|
+
type : 'log:err',
|
|
315
|
+
topic : 'log:err',
|
|
316
|
+
data : '\n' + error + '\n'
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
process.send({
|
|
320
|
+
type : 'process:exception',
|
|
321
|
+
data : errObj !== undefined ? errObj : {message: 'No error but ' + listener + ' was caught!'}
|
|
322
|
+
});
|
|
323
|
+
} catch(e) {
|
|
324
|
+
logError(['std', 'err'], 'Channel is already closed can\'t broadcast error:\n' + e.stack);
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
if (!process.listeners(listener).filter(function (listener) {
|
|
328
|
+
return listener !== uncaughtListener;
|
|
329
|
+
}).length) {
|
|
330
|
+
if (listener == 'uncaughtException') {
|
|
331
|
+
process.emit('disconnect');
|
|
332
|
+
process.exit(cst.CODE_UNCAUGHTEXCEPTION);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
process.on('uncaughtException', getUncaughtExceptionListener('uncaughtException'));
|
|
339
|
+
process.on('unhandledRejection', getUncaughtExceptionListener('unhandledRejection'));
|
|
340
|
+
|
|
341
|
+
// Change dir to fix process.cwd
|
|
342
|
+
process.chdir(pm2_env.pm_cwd || process.env.PWD || p.dirname(script));
|
|
343
|
+
|
|
344
|
+
require(script);
|
|
345
|
+
|
|
346
|
+
function logError(types, error){
|
|
347
|
+
try {
|
|
348
|
+
types.forEach(function(type){
|
|
349
|
+
stds[type] && typeof stds[type].write == 'function' && stds[type].write(error + '\n');
|
|
350
|
+
});
|
|
351
|
+
} catch(e) { }
|
|
352
|
+
}
|
|
353
|
+
});
|
|
354
|
+
|
|
355
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
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
|
+
if (process.env.disable_source_map_support !== 'true' &&
|
|
7
|
+
typeof process.setSourceMapsEnabled === 'function')
|
|
8
|
+
process.setSourceMapsEnabled(true);
|
|
9
|
+
|
|
10
|
+
// Inject custom modules
|
|
11
|
+
var url = require('url')
|
|
12
|
+
var ProcessUtils = require('./ProcessUtils')
|
|
13
|
+
ProcessUtils.injectModules()
|
|
14
|
+
|
|
15
|
+
// Rename the process
|
|
16
|
+
process.title = process.env.PROCESS_TITLE || 'node ' + process.env.pm_exec_path;
|
|
17
|
+
|
|
18
|
+
if (process.connected &&
|
|
19
|
+
process.send &&
|
|
20
|
+
process.versions &&
|
|
21
|
+
process.versions.node)
|
|
22
|
+
process.send({
|
|
23
|
+
'node_version': process.versions.node
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
// Require the real application
|
|
27
|
+
if (process.env.pm_exec_path) {
|
|
28
|
+
ProcessUtils.enableTypeScript(process.env.pm_exec_path, process.env.pm_cwd);
|
|
29
|
+
if (ProcessUtils.isESModule(process.env.pm_exec_path) === true) {
|
|
30
|
+
import(url.pathToFileURL(process.env.pm_exec_path));
|
|
31
|
+
}
|
|
32
|
+
else
|
|
33
|
+
require('module')._load(process.env.pm_exec_path, null, true);
|
|
34
|
+
}
|
|
35
|
+
else
|
|
36
|
+
throw new Error('Could not _load() the script');
|
|
37
|
+
|
|
38
|
+
// Change some values to make node think that the user's application
|
|
39
|
+
// was started directly such as `node app.js`
|
|
40
|
+
process.mainModule = process.mainModule || {};
|
|
41
|
+
process.mainModule.loaded = false;
|
|
42
|
+
require.main = process.mainModule;
|
|
@@ -0,0 +1,31 @@
|
|
|
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
|
+
if (process.env.disable_source_map_support !== 'true' &&
|
|
7
|
+
typeof process.setSourceMapsEnabled === 'function')
|
|
8
|
+
process.setSourceMapsEnabled(true);
|
|
9
|
+
|
|
10
|
+
// Inject custom modules
|
|
11
|
+
var ProcessUtils = require('./ProcessUtils')
|
|
12
|
+
ProcessUtils.injectModules()
|
|
13
|
+
|
|
14
|
+
// Rename the process
|
|
15
|
+
process.title = process.env.PROCESS_TITLE || 'bun ' + process.env.pm_exec_path;
|
|
16
|
+
|
|
17
|
+
if (process.connected &&
|
|
18
|
+
process.send &&
|
|
19
|
+
process.versions &&
|
|
20
|
+
process.versions.node)
|
|
21
|
+
process.send({
|
|
22
|
+
'node_version': process.versions.node
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
require(process.env.pm_exec_path);
|
|
26
|
+
|
|
27
|
+
// Change some values to make node think that the user's application
|
|
28
|
+
// was started directly such as `node app.js`
|
|
29
|
+
process.mainModule = process.mainModule || {};
|
|
30
|
+
process.mainModule.loaded = false;
|
|
31
|
+
require.main = process.mainModule;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
module.exports = {
|
|
4
|
+
injectModules: function() {
|
|
5
|
+
if (process.env.pmx !== 'false') {
|
|
6
|
+
const pmx = require('../modules/pm2-io-bpm')
|
|
7
|
+
|
|
8
|
+
let conf = {}
|
|
9
|
+
const hasSpecificConfig = typeof process.env.io === 'string' || process.env.trace === 'true'
|
|
10
|
+
// pmx is already init, no need to do it twice
|
|
11
|
+
if (hasSpecificConfig === false) return
|
|
12
|
+
|
|
13
|
+
if (process.env.io) {
|
|
14
|
+
const io = JSON.parse(process.env.io)
|
|
15
|
+
conf = io.conf ? io.conf : conf
|
|
16
|
+
}
|
|
17
|
+
pmx.init(Object.assign({
|
|
18
|
+
tracing: process.env.trace === 'true' || false
|
|
19
|
+
}, conf))
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
enableTypeScript(exec_path, cwd) {
|
|
23
|
+
var path = require('path')
|
|
24
|
+
var ext = path.extname(exec_path || '')
|
|
25
|
+
|
|
26
|
+
if (ext !== '.ts' && ext !== '.tsx')
|
|
27
|
+
return
|
|
28
|
+
|
|
29
|
+
// .ts needs nothing when the runtime already strips types
|
|
30
|
+
// (enabled by default on node >= 22.18 / >= 23.6, or via flag);
|
|
31
|
+
// .tsx always needs a transformer
|
|
32
|
+
var stripping = (process.features && process.features.typescript) ||
|
|
33
|
+
process.execArgv.indexOf('--experimental-strip-types') !== -1 ||
|
|
34
|
+
process.execArgv.indexOf('--experimental-transform-types') !== -1
|
|
35
|
+
if (ext === '.ts' && stripping)
|
|
36
|
+
return
|
|
37
|
+
|
|
38
|
+
// Resolve ts-node from the application dependencies, not from PM2's
|
|
39
|
+
try {
|
|
40
|
+
require(require.resolve('ts-node/register', { paths: [cwd || path.dirname(exec_path)] }))
|
|
41
|
+
} catch (e) {
|
|
42
|
+
console.error('TypeScript support unavailable: install ts-node in your project or use Node.js >= 22.18 (%s)', e.message || e)
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
isESModule(exec_path) {
|
|
46
|
+
var fs = require('fs')
|
|
47
|
+
var path = require('path')
|
|
48
|
+
var data
|
|
49
|
+
|
|
50
|
+
var findPackageJson = function(directory) {
|
|
51
|
+
var file = path.join(directory, 'package.json')
|
|
52
|
+
if (fs.existsSync(file) && fs.statSync(file).isFile()) {
|
|
53
|
+
return file;
|
|
54
|
+
}
|
|
55
|
+
var parent = path.resolve(directory, '..')
|
|
56
|
+
if (parent === directory) {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
return findPackageJson(parent)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (path.extname(exec_path) === '.mjs')
|
|
63
|
+
return true
|
|
64
|
+
|
|
65
|
+
try {
|
|
66
|
+
data = JSON.parse(fs.readFileSync(findPackageJson(path.dirname(exec_path))))
|
|
67
|
+
if (data.type === 'module')
|
|
68
|
+
return true
|
|
69
|
+
else
|
|
70
|
+
return false
|
|
71
|
+
} catch(e) {
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
package/lib/TreeKill.js
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var childProcess = require('child_process');
|
|
4
|
+
var exec = childProcess.exec;
|
|
5
|
+
var psWarned = false;
|
|
6
|
+
|
|
7
|
+
module.exports = function (pid, signal, callback) {
|
|
8
|
+
pid = parseInt(pid, 10);
|
|
9
|
+
if (isNaN(pid)) {
|
|
10
|
+
if (callback) return callback(new Error('pid must be a number'));
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
if (process.platform === 'win32') {
|
|
15
|
+
exec('taskkill /pid ' + pid + ' /T /F', { windowsHide: true }, function (err) {
|
|
16
|
+
if (callback) return callback(err, [pid]);
|
|
17
|
+
});
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// Unix (Linux, macOS, FreeBSD)
|
|
22
|
+
// 1) Snapshot all processes in one ps call
|
|
23
|
+
// 2) Build the descendant tree in JS
|
|
24
|
+
// 3) Kill bottom-up (deepest children first)
|
|
25
|
+
var allData = '';
|
|
26
|
+
var finished = false;
|
|
27
|
+
var ps;
|
|
28
|
+
|
|
29
|
+
// A failed spawn (no `ps` binary, e.g. slim Docker images) emits 'error'
|
|
30
|
+
// then 'close': only the first one may conclude (#6171)
|
|
31
|
+
function done(err, pids) {
|
|
32
|
+
if (finished) return;
|
|
33
|
+
finished = true;
|
|
34
|
+
if (callback) return callback(err, pids);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Without ps the tree cannot be walked: fall back to killing the root pid
|
|
38
|
+
function noPs(err) {
|
|
39
|
+
if (!psWarned) {
|
|
40
|
+
psWarned = true;
|
|
41
|
+
console.error('[TreeKill] ps unavailable (%s): only the root pid is killed, children may be orphaned', err.code || err.message);
|
|
42
|
+
}
|
|
43
|
+
killPid(pid, signal);
|
|
44
|
+
return done();
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Bun throws synchronously when the binary is missing, Node emits 'error'
|
|
48
|
+
try {
|
|
49
|
+
ps = childProcess.spawn('ps', ['-e', '-o', 'pid=,ppid=']);
|
|
50
|
+
} catch (err) {
|
|
51
|
+
return noPs(err);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
ps.on('error', noPs);
|
|
55
|
+
|
|
56
|
+
if (ps.stdout) {
|
|
57
|
+
ps.stdout.on('data', function (data) {
|
|
58
|
+
allData += data.toString('ascii');
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
ps.on('close', function (code) {
|
|
63
|
+
if (finished) return;
|
|
64
|
+
if (code !== 0 && allData.length === 0) {
|
|
65
|
+
killPid(pid, signal);
|
|
66
|
+
return done();
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
var childrenMap = {};
|
|
70
|
+
var lines = allData.trim().split('\n');
|
|
71
|
+
|
|
72
|
+
lines.forEach(function (line) {
|
|
73
|
+
var parts = line.trim().split(/\s+/);
|
|
74
|
+
if (parts.length < 2) return;
|
|
75
|
+
var cpid = parseInt(parts[0], 10);
|
|
76
|
+
var ppid = parseInt(parts[1], 10);
|
|
77
|
+
if (isNaN(cpid) || isNaN(ppid)) return;
|
|
78
|
+
if (!childrenMap[ppid]) childrenMap[ppid] = [];
|
|
79
|
+
childrenMap[ppid].push(cpid);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
// Collect all descendants depth-first
|
|
83
|
+
var descendants = [];
|
|
84
|
+
function collect(parentPid) {
|
|
85
|
+
var kids = childrenMap[parentPid];
|
|
86
|
+
if (!kids) return;
|
|
87
|
+
kids.forEach(function (kid) {
|
|
88
|
+
collect(kid);
|
|
89
|
+
descendants.push(kid);
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
collect(pid);
|
|
93
|
+
|
|
94
|
+
// Kill bottom-up: deepest children first, then root
|
|
95
|
+
var allPids = descendants.concat(pid);
|
|
96
|
+
allPids.forEach(function (dpid) {
|
|
97
|
+
killPid(dpid, signal);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
return done(null, allPids);
|
|
101
|
+
});
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
function killPid(pid, signal) {
|
|
105
|
+
try {
|
|
106
|
+
process.kill(parseInt(pid, 10), signal);
|
|
107
|
+
} catch (err) {
|
|
108
|
+
if (err.code !== 'ESRCH')
|
|
109
|
+
console.error(err);
|
|
110
|
+
}
|
|
111
|
+
}
|