@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,75 @@
|
|
|
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 http = require('http');
|
|
7
|
+
var os = require('os');
|
|
8
|
+
var pm2 = require('../index.js');
|
|
9
|
+
var urlT = require('url');
|
|
10
|
+
var cst = require('../constants.js');
|
|
11
|
+
|
|
12
|
+
// Default, attach to default local PM2
|
|
13
|
+
|
|
14
|
+
pm2.connect(function() {
|
|
15
|
+
startWebServer(pm2);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
function startWebServer(pm2) {
|
|
19
|
+
http.createServer(function (req, res) {
|
|
20
|
+
// Add CORS headers to allow browsers to fetch data directly
|
|
21
|
+
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
22
|
+
res.setHeader('Access-Control-Allow-Headers', 'Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With');
|
|
23
|
+
res.setHeader('Access-Control-Allow-Methods', 'GET');
|
|
24
|
+
|
|
25
|
+
// We always send json
|
|
26
|
+
res.setHeader('Content-Type','application/json');
|
|
27
|
+
|
|
28
|
+
var path = urlT.parse(req.url).pathname;
|
|
29
|
+
|
|
30
|
+
if (path == '/') {
|
|
31
|
+
// Main monit route
|
|
32
|
+
pm2.list(function(err, list) {
|
|
33
|
+
if (err) {
|
|
34
|
+
return res.send(err);
|
|
35
|
+
}
|
|
36
|
+
var data = {
|
|
37
|
+
system_info: { hostname: os.hostname(),
|
|
38
|
+
uptime: os.uptime()
|
|
39
|
+
},
|
|
40
|
+
monit: { loadavg: os.loadavg(),
|
|
41
|
+
total_mem: os.totalmem(),
|
|
42
|
+
free_mem: os.freemem(),
|
|
43
|
+
cpu: os.cpus(),
|
|
44
|
+
interfaces: os.networkInterfaces()
|
|
45
|
+
},
|
|
46
|
+
processes: list
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
if (cst.WEB_STRIP_ENV_VARS) {
|
|
50
|
+
for (var i = data.processes.length - 1; i >= 0; i--) {
|
|
51
|
+
var proc = data.processes[i];
|
|
52
|
+
|
|
53
|
+
if (typeof proc.pm2_env === 'undefined' || typeof proc.pm2_env.env === 'undefined') continue;
|
|
54
|
+
|
|
55
|
+
delete proc.pm2_env.env;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
res.statusCode = 200;
|
|
60
|
+
res.write(JSON.stringify(data));
|
|
61
|
+
return res.end();
|
|
62
|
+
|
|
63
|
+
})
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
// 404
|
|
67
|
+
res.statusCode = 404;
|
|
68
|
+
res.write(JSON.stringify({err : '404'}));
|
|
69
|
+
return res.end();
|
|
70
|
+
}
|
|
71
|
+
}).listen(process.env.PM2_WEB_PORT || cst.WEB_PORT, cst.WEB_IPADDR, function() {
|
|
72
|
+
console.log('Web interface listening on %s:%s', cst.WEB_IPADDR, cst.WEB_PORT);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
var path = require('path')
|
|
4
|
+
var execSync = require('child_process').execSync
|
|
5
|
+
var Common = require('./Common')
|
|
6
|
+
var cst = require('../constants')
|
|
7
|
+
var which = require('./tools/which')
|
|
8
|
+
|
|
9
|
+
var PM2_ROOT = path.join(__dirname, '..')
|
|
10
|
+
|
|
11
|
+
// Versions are pinned: OTel releases regularly break semantic conventions
|
|
12
|
+
// (e.g. instrumentation-http 0.220.0 dropped http.target/http.method tags)
|
|
13
|
+
var OTEL_PACKAGES = [
|
|
14
|
+
'@opentelemetry/api@1.9.1',
|
|
15
|
+
'@opentelemetry/sdk-node@0.221.0',
|
|
16
|
+
'@opentelemetry/auto-instrumentations-node@0.79.0',
|
|
17
|
+
'@opentelemetry/core@2.10.0',
|
|
18
|
+
'@opentelemetry/sdk-trace-base@2.10.0',
|
|
19
|
+
'@opentelemetry/semantic-conventions@1.43.0'
|
|
20
|
+
]
|
|
21
|
+
|
|
22
|
+
module.exports = {
|
|
23
|
+
OTEL_PACKAGES: OTEL_PACKAGES,
|
|
24
|
+
|
|
25
|
+
isInstalled: function() {
|
|
26
|
+
try {
|
|
27
|
+
require.resolve('@opentelemetry/sdk-node')
|
|
28
|
+
return true
|
|
29
|
+
} catch(e) {
|
|
30
|
+
return false
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
|
|
34
|
+
install: function() {
|
|
35
|
+
var pm = which('npm') ? 'npm' : which('bun') ? 'bun' : null
|
|
36
|
+
if (!pm) {
|
|
37
|
+
throw new Error('npm or bun is required to install OpenTelemetry packages')
|
|
38
|
+
}
|
|
39
|
+
Common.printOut(cst.PREFIX_MSG + 'Installing OpenTelemetry tracing packages...')
|
|
40
|
+
execSync(pm + ' install --no-save ' + OTEL_PACKAGES.join(' '), {
|
|
41
|
+
cwd: PM2_ROOT,
|
|
42
|
+
stdio: 'inherit'
|
|
43
|
+
})
|
|
44
|
+
Common.printOut(cst.PREFIX_MSG + 'OpenTelemetry tracing packages installed successfully')
|
|
45
|
+
},
|
|
46
|
+
|
|
47
|
+
uninstall: function() {
|
|
48
|
+
var pm = which('npm') ? 'npm' : which('bun') ? 'bun' : null
|
|
49
|
+
if (!pm) {
|
|
50
|
+
throw new Error('npm or bun is required to uninstall OpenTelemetry packages')
|
|
51
|
+
}
|
|
52
|
+
Common.printOut(cst.PREFIX_MSG + 'Removing OpenTelemetry tracing packages...')
|
|
53
|
+
var names = OTEL_PACKAGES.map(function(pkg) {
|
|
54
|
+
return pkg.replace(/@[^@/]+$/, '')
|
|
55
|
+
})
|
|
56
|
+
execSync(pm + ' remove --no-save ' + names.join(' '), {
|
|
57
|
+
cwd: PM2_ROOT,
|
|
58
|
+
stdio: 'inherit'
|
|
59
|
+
})
|
|
60
|
+
Common.printOut(cst.PREFIX_MSG + 'OpenTelemetry tracing packages removed')
|
|
61
|
+
},
|
|
62
|
+
|
|
63
|
+
ensureInstalled: function() {
|
|
64
|
+
if (this.isInstalled()) return true
|
|
65
|
+
try {
|
|
66
|
+
this.install()
|
|
67
|
+
return true
|
|
68
|
+
} catch(e) {
|
|
69
|
+
Common.printError(cst.PREFIX_MSG_ERR + 'Failed to install OpenTelemetry packages: ' + e.message)
|
|
70
|
+
Common.printError(cst.PREFIX_MSG_ERR + 'Install manually with: pm2 install-otel')
|
|
71
|
+
return false
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -0,0 +1,321 @@
|
|
|
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
|
+
* This file wrap target application
|
|
7
|
+
* - redirect stdin, stderr to bus + log files
|
|
8
|
+
* - rename process
|
|
9
|
+
* - pid
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
var p = require('path');
|
|
13
|
+
var cst = require('../constants');
|
|
14
|
+
var Utility = require('./Utility.js');
|
|
15
|
+
var ProcessUtils = require('./ProcessUtils');
|
|
16
|
+
var Url = require('url');
|
|
17
|
+
|
|
18
|
+
// Load all env-vars from master.
|
|
19
|
+
var pm2_env = JSON.parse(process.env.pm2_env);
|
|
20
|
+
for(var k in pm2_env) {
|
|
21
|
+
process.env[k] = pm2_env[k];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (pm2_env.disable_source_map_support !== true &&
|
|
25
|
+
typeof process.setSourceMapsEnabled === 'function')
|
|
26
|
+
process.setSourceMapsEnabled(true);
|
|
27
|
+
|
|
28
|
+
// Rename process
|
|
29
|
+
process.title = process.env.PROCESS_TITLE || 'node ' + pm2_env.pm_exec_path;
|
|
30
|
+
|
|
31
|
+
delete process.env.pm2_env;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Main entrance to wrap the desired code
|
|
35
|
+
*/
|
|
36
|
+
(function ProcessContainer() {
|
|
37
|
+
var fs = require('fs');
|
|
38
|
+
|
|
39
|
+
ProcessUtils.injectModules()
|
|
40
|
+
|
|
41
|
+
var stdFile = pm2_env.pm_log_path;
|
|
42
|
+
var outFile = pm2_env.pm_out_log_path;
|
|
43
|
+
var errFile = pm2_env.pm_err_log_path;
|
|
44
|
+
var pidFile = pm2_env.pm_pid_path;
|
|
45
|
+
var script = pm2_env.pm_exec_path;
|
|
46
|
+
|
|
47
|
+
var original_send = process.send;
|
|
48
|
+
|
|
49
|
+
process.send = function() {
|
|
50
|
+
if (process.connected)
|
|
51
|
+
original_send.apply(this, arguments);
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
//send node version
|
|
55
|
+
if (process.versions && process.versions.node) {
|
|
56
|
+
process.send({
|
|
57
|
+
'node_version': process.versions.node
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (cst.MODIFY_REQUIRE)
|
|
62
|
+
require.main.filename = pm2_env.pm_exec_path;
|
|
63
|
+
|
|
64
|
+
// Resets global paths for require()
|
|
65
|
+
require('module')._initPaths();
|
|
66
|
+
|
|
67
|
+
try {
|
|
68
|
+
var pid = process.pid
|
|
69
|
+
if (typeof(pid) !== 'undefined')
|
|
70
|
+
fs.writeFileSync(pidFile, process.pid.toString());
|
|
71
|
+
} catch (e) {
|
|
72
|
+
console.error(e.stack || e);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Add args to process if args specified on start
|
|
76
|
+
if (process.env.args != null)
|
|
77
|
+
process.argv = process.argv.concat(pm2_env.args);
|
|
78
|
+
|
|
79
|
+
// stdio, including: out, err and entire (both out and err if necessary).
|
|
80
|
+
var stds = {
|
|
81
|
+
out: outFile,
|
|
82
|
+
err: errFile
|
|
83
|
+
};
|
|
84
|
+
stdFile && (stds.std = stdFile);
|
|
85
|
+
|
|
86
|
+
// uid/gid management
|
|
87
|
+
if (pm2_env.uid || pm2_env.gid) {
|
|
88
|
+
try {
|
|
89
|
+
if (process.env.gid)
|
|
90
|
+
process.setgid(pm2_env.gid);
|
|
91
|
+
if (pm2_env.uid)
|
|
92
|
+
process.setuid(pm2_env.uid);
|
|
93
|
+
} catch(e) {
|
|
94
|
+
setTimeout(function() {
|
|
95
|
+
console.error('%s on call %s', e.message, e.syscall);
|
|
96
|
+
console.error('%s is not accessible', pm2_env.uid);
|
|
97
|
+
return process.exit(1);
|
|
98
|
+
}, 100);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
exec(script, stds);
|
|
103
|
+
})();
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Description
|
|
107
|
+
* @method exec
|
|
108
|
+
* @param {} script
|
|
109
|
+
* @param {} stds
|
|
110
|
+
* @return
|
|
111
|
+
*/
|
|
112
|
+
function exec(script, stds) {
|
|
113
|
+
ProcessUtils.enableTypeScript(script, pm2_env.pm_cwd);
|
|
114
|
+
|
|
115
|
+
process.on('message', function (msg) {
|
|
116
|
+
if (msg.type === 'log:reload') {
|
|
117
|
+
for (var k in stds){
|
|
118
|
+
if (typeof stds[k] == 'object' && !isNaN(stds[k].fd)){
|
|
119
|
+
if (stds[k].end) stds[k].end();
|
|
120
|
+
else if (stds[k].destroy) stds[k].destroy();
|
|
121
|
+
else if (stds[k].close) stds[k].close();
|
|
122
|
+
stds[k] = stds[k]._file;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
Utility.startLogging(stds, function (err) {
|
|
126
|
+
if (err)
|
|
127
|
+
return console.error('Failed to reload logs:', err.stack);
|
|
128
|
+
console.log('Reloading log...');
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
var dayjs = null;
|
|
134
|
+
|
|
135
|
+
if (pm2_env.log_date_format)
|
|
136
|
+
dayjs = require('dayjs');
|
|
137
|
+
|
|
138
|
+
// Prefix every line of a (possibly multi-line) write with the date
|
|
139
|
+
function prefixLogWithDate(string) {
|
|
140
|
+
var ts = dayjs().format(pm2_env.log_date_format);
|
|
141
|
+
var text = string.toString();
|
|
142
|
+
var trailing = text.endsWith('\n');
|
|
143
|
+
var lines = trailing ? text.slice(0, -1).split('\n') : text.split('\n');
|
|
144
|
+
return lines.map(line => `${ts}: ${line}`).join('\n') + (trailing ? '\n' : '');
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
Utility.startLogging(stds, function (err) {
|
|
148
|
+
if (err) {
|
|
149
|
+
process.send({
|
|
150
|
+
type : 'process:exception',
|
|
151
|
+
data : {
|
|
152
|
+
message: err.message,
|
|
153
|
+
syscall: 'ProcessContainer.startLogging'
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
throw err;
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// fd 1/2 are pipes to the daemon (cluster silent mode) and libuv made
|
|
161
|
+
// them O_NONBLOCK when process.stdout/stderr got instantiated. Writes
|
|
162
|
+
// that bypass the hooks below (fs.writeSync(1), pino/sonic-boom, native
|
|
163
|
+
// addons, V8/inspector messages) would then be partial past the pipe
|
|
164
|
+
// buffer (64 KB) and lose data silently, and the flag is shared with
|
|
165
|
+
// children spawned with stdio 'inherit'. Make them blocking again, as
|
|
166
|
+
// Node does on Windows: the hooks never write to the pipe, so console.log
|
|
167
|
+
// keeps going straight to the log files and the pipe only carries raw
|
|
168
|
+
// writes, which behave like the file fd they used to be
|
|
169
|
+
[process.stdout, process.stderr].forEach(function(stream) {
|
|
170
|
+
if (stream._handle && typeof stream._handle.setBlocking === 'function')
|
|
171
|
+
stream._handle.setBlocking(true);
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
process.stderr.write = (function(write) {
|
|
175
|
+
return function(string, encoding, cb) {
|
|
176
|
+
var log_data = null;
|
|
177
|
+
|
|
178
|
+
// Disable logs if specified
|
|
179
|
+
if (pm2_env.disable_logs === true) {
|
|
180
|
+
return cb ? cb() : false;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
if (pm2_env.log_type && pm2_env.log_type === 'json') {
|
|
184
|
+
log_data = JSON.stringify({
|
|
185
|
+
message : string.toString(),
|
|
186
|
+
timestamp : pm2_env.log_date_format && dayjs ?
|
|
187
|
+
dayjs().format(pm2_env.log_date_format) : new Date().toISOString(),
|
|
188
|
+
type : 'err',
|
|
189
|
+
process_id : pm2_env.pm_id,
|
|
190
|
+
app_name : pm2_env.name
|
|
191
|
+
}) + '\n';
|
|
192
|
+
}
|
|
193
|
+
else if (pm2_env.log_date_format && dayjs)
|
|
194
|
+
log_data = prefixLogWithDate(string);
|
|
195
|
+
else
|
|
196
|
+
log_data = string.toString();
|
|
197
|
+
|
|
198
|
+
process.send({
|
|
199
|
+
type : 'log:err',
|
|
200
|
+
topic : 'log:err',
|
|
201
|
+
data : log_data
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
if (Utility.checkPathIsNull(pm2_env.pm_err_log_path) &&
|
|
205
|
+
(!pm2_env.pm_log_path || Utility.checkPathIsNull(pm2_env.pm_log_path)))
|
|
206
|
+
return cb ? cb() : false;
|
|
207
|
+
|
|
208
|
+
stds.std && stds.std.write && stds.std.write(log_data, encoding);
|
|
209
|
+
stds.err && stds.err.write && stds.err.write(log_data, encoding, cb);
|
|
210
|
+
};
|
|
211
|
+
})(process.stderr.write);
|
|
212
|
+
|
|
213
|
+
process.stdout.write = (function(write) {
|
|
214
|
+
return function(string, encoding, cb) {
|
|
215
|
+
var log_data = null;
|
|
216
|
+
|
|
217
|
+
// Disable logs if specified
|
|
218
|
+
if (pm2_env.disable_logs === true) {
|
|
219
|
+
return cb ? cb() : false;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
if (pm2_env.log_type && pm2_env.log_type === 'json') {
|
|
223
|
+
log_data = JSON.stringify({
|
|
224
|
+
message : string.toString(),
|
|
225
|
+
timestamp : pm2_env.log_date_format && dayjs ?
|
|
226
|
+
dayjs().format(pm2_env.log_date_format) : new Date().toISOString(),
|
|
227
|
+
type : 'out',
|
|
228
|
+
process_id : pm2_env.pm_id,
|
|
229
|
+
app_name : pm2_env.name
|
|
230
|
+
}) + '\n';
|
|
231
|
+
}
|
|
232
|
+
else if (pm2_env.log_date_format && dayjs)
|
|
233
|
+
log_data = prefixLogWithDate(string);
|
|
234
|
+
else
|
|
235
|
+
log_data = string.toString();
|
|
236
|
+
|
|
237
|
+
process.send({
|
|
238
|
+
type : 'log:out',
|
|
239
|
+
data : log_data
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
if (Utility.checkPathIsNull(pm2_env.pm_out_log_path) &&
|
|
243
|
+
(!pm2_env.pm_log_path || Utility.checkPathIsNull(pm2_env.pm_log_path)))
|
|
244
|
+
return cb ? cb() : null;
|
|
245
|
+
|
|
246
|
+
stds.std && stds.std.write && stds.std.write(log_data, encoding);
|
|
247
|
+
stds.out && stds.out.write && stds.out.write(log_data, encoding, cb);
|
|
248
|
+
};
|
|
249
|
+
})(process.stdout.write);
|
|
250
|
+
|
|
251
|
+
function getUncaughtExceptionListener(listener) {
|
|
252
|
+
return function uncaughtListener(err) {
|
|
253
|
+
var error = err && err.stack ? err.stack : err;
|
|
254
|
+
|
|
255
|
+
if (listener === 'unhandledRejection') {
|
|
256
|
+
error = 'You have triggered an unhandledRejection, you may have forgotten to catch a Promise rejection:\n' + error;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
logError(['std', 'err'], error);
|
|
260
|
+
|
|
261
|
+
// Notify master that an uncaughtException has been catched
|
|
262
|
+
try {
|
|
263
|
+
if (err) {
|
|
264
|
+
var errObj = {};
|
|
265
|
+
|
|
266
|
+
Object.getOwnPropertyNames(err).forEach(function(key) {
|
|
267
|
+
errObj[key] = err[key];
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
process.send({
|
|
272
|
+
type : 'log:err',
|
|
273
|
+
topic : 'log:err',
|
|
274
|
+
data : '\n' + error + '\n'
|
|
275
|
+
});
|
|
276
|
+
process.send({
|
|
277
|
+
type : 'process:exception',
|
|
278
|
+
data : errObj !== undefined ? errObj : {message: 'No error but ' + listener + ' was caught!'}
|
|
279
|
+
});
|
|
280
|
+
} catch(e) {
|
|
281
|
+
logError(['std', 'err'], 'Channel is already closed can\'t broadcast error:\n' + e.stack);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
if (!process.listeners(listener).filter(function (listener) {
|
|
285
|
+
return listener !== uncaughtListener;
|
|
286
|
+
}).length) {
|
|
287
|
+
if (listener == 'uncaughtException') {
|
|
288
|
+
process.emit('disconnect');
|
|
289
|
+
process.exit(cst.CODE_UNCAUGHTEXCEPTION);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
process.on('uncaughtException', getUncaughtExceptionListener('uncaughtException'));
|
|
296
|
+
process.on('unhandledRejection', getUncaughtExceptionListener('unhandledRejection'));
|
|
297
|
+
|
|
298
|
+
// Change dir to fix process.cwd
|
|
299
|
+
process.chdir(pm2_env.pm_cwd || process.env.PWD || p.dirname(script));
|
|
300
|
+
|
|
301
|
+
if (ProcessUtils.isESModule(script) === true)
|
|
302
|
+
import(Url.pathToFileURL(process.env.pm_exec_path));
|
|
303
|
+
else {
|
|
304
|
+
if (cst.IS_BUN) {
|
|
305
|
+
require(script);
|
|
306
|
+
}
|
|
307
|
+
else {
|
|
308
|
+
require('module')._load(script, null, true);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
function logError(types, error){
|
|
313
|
+
try {
|
|
314
|
+
types.forEach(function(type){
|
|
315
|
+
stds[type] && typeof stds[type].write == 'function' && stds[type].write(error + '\n');
|
|
316
|
+
});
|
|
317
|
+
} catch(e) { }
|
|
318
|
+
}
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
}
|