@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
package/lib/Daemon.js
ADDED
|
@@ -0,0 +1,468 @@
|
|
|
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
|
+
if (typeof process.setSourceMapsEnabled === 'function')
|
|
8
|
+
process.setSourceMapsEnabled(true);
|
|
9
|
+
|
|
10
|
+
var debug = require('debug')('pm2:daemon');
|
|
11
|
+
var pkg = require('../package.json');
|
|
12
|
+
var cst = require('../constants.js');
|
|
13
|
+
var rpc = require('../modules/pm2-axon-rpc');
|
|
14
|
+
var axon = require('../modules/pm2-axon');
|
|
15
|
+
var domain = require('domain');
|
|
16
|
+
var Utility = require('./Utility.js');
|
|
17
|
+
var util = require('util');
|
|
18
|
+
var fs = require('fs');
|
|
19
|
+
var God = require('./God');
|
|
20
|
+
var eachLimit = require('async/eachLimit');
|
|
21
|
+
var fmt = require('./tools/fmt.js');
|
|
22
|
+
|
|
23
|
+
var Daemon = module.exports = function(opts) {
|
|
24
|
+
if (!opts) opts = {};
|
|
25
|
+
|
|
26
|
+
this.ignore_signals = opts.ignore_signals || false;
|
|
27
|
+
this.rpc_socket_ready = false;
|
|
28
|
+
this.pub_socket_ready = false;
|
|
29
|
+
|
|
30
|
+
this.pub_socket_file = opts.pub_socket_file || cst.DAEMON_PUB_PORT;
|
|
31
|
+
this.rpc_socket_file = opts.rpc_socket_file || cst.DAEMON_RPC_PORT;
|
|
32
|
+
|
|
33
|
+
this.pid_path = opts.pid_file || cst.PM2_PID_FILE_PATH;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
Daemon.prototype.start = function() {
|
|
37
|
+
var that = this;
|
|
38
|
+
var d = domain.create();
|
|
39
|
+
|
|
40
|
+
d.once('error', function(err) {
|
|
41
|
+
fmt.sep();
|
|
42
|
+
fmt.title('PM2 global error caught');
|
|
43
|
+
fmt.field('Time', new Date());
|
|
44
|
+
console.error(err.message);
|
|
45
|
+
console.error(err.stack);
|
|
46
|
+
fmt.sep();
|
|
47
|
+
|
|
48
|
+
console.error('[PM2] Resurrecting PM2');
|
|
49
|
+
|
|
50
|
+
var path = cst.IS_WINDOWS ? __dirname + '/../bin/pm2' : process.env['_'];
|
|
51
|
+
var fork_new_pm2 = require('child_process').spawn('node', [path, 'update'], {
|
|
52
|
+
detached: true,
|
|
53
|
+
windowsHide: true,
|
|
54
|
+
stdio: 'inherit'
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
fork_new_pm2.on('close', function() {
|
|
58
|
+
console.log('PM2 successfully forked');
|
|
59
|
+
process.exit(0);
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
d.run(function() {
|
|
65
|
+
that.innerStart();
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
Daemon.prototype.innerStart = function(cb) {
|
|
70
|
+
var that = this;
|
|
71
|
+
|
|
72
|
+
if (!cb) cb = function() {
|
|
73
|
+
fmt.sep();
|
|
74
|
+
fmt.title('New PM2 Daemon started');
|
|
75
|
+
fmt.field('Time', new Date());
|
|
76
|
+
fmt.field('PM2 version', pkg.version);
|
|
77
|
+
fmt.field('Node.js version', process.versions.node);
|
|
78
|
+
fmt.field('Current arch', process.arch);
|
|
79
|
+
fmt.field('PM2 home', cst.PM2_HOME);
|
|
80
|
+
fmt.field('PM2 PID file', that.pid_path);
|
|
81
|
+
fmt.field('RPC socket file', that.rpc_socket_file);
|
|
82
|
+
fmt.field('BUS socket file', that.pub_socket_file);
|
|
83
|
+
fmt.field('Application log path', cst.DEFAULT_LOG_PATH);
|
|
84
|
+
fmt.field('Worker Interval', cst.WORKER_INTERVAL);
|
|
85
|
+
fmt.field('Process dump file', cst.DUMP_FILE_PATH);
|
|
86
|
+
fmt.field('Concurrent actions', cst.CONCURRENT_ACTIONS);
|
|
87
|
+
fmt.field('SIGTERM timeout', cst.KILL_TIMEOUT);
|
|
88
|
+
fmt.field('Runtime Binary', process.execPath);
|
|
89
|
+
fmt.sep();
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
// Write Daemon PID into file
|
|
93
|
+
try {
|
|
94
|
+
fs.writeFileSync(that.pid_path, process.pid.toString());
|
|
95
|
+
} catch (e) {
|
|
96
|
+
console.error(e.stack || e);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (this.ignore_signals != true)
|
|
100
|
+
this.handleSignals();
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Pub system for real time notifications
|
|
104
|
+
*/
|
|
105
|
+
this.pub = axon.socket('pub-emitter');
|
|
106
|
+
|
|
107
|
+
this.pub_socket = this.pub.bind(this.pub_socket_file);
|
|
108
|
+
|
|
109
|
+
// Only unix socket files can be chmod'ed/chown'ed; skip for tcp:// addresses
|
|
110
|
+
// (openharmony transport).
|
|
111
|
+
var pub_is_tcp = String(this.pub_socket_file).indexOf('tcp://') === 0;
|
|
112
|
+
|
|
113
|
+
this.pub_socket.once('bind', function() {
|
|
114
|
+
if (!pub_is_tcp) {
|
|
115
|
+
fs.chmod(that.pub_socket_file, '775', function(e) {
|
|
116
|
+
if (e) console.error(e);
|
|
117
|
+
|
|
118
|
+
try {
|
|
119
|
+
if (process.env.PM2_SOCKET_USER && process.env.PM2_SOCKET_GROUP)
|
|
120
|
+
fs.chown(that.pub_socket_file,
|
|
121
|
+
parseInt(process.env.PM2_SOCKET_USER),
|
|
122
|
+
parseInt(process.env.PM2_SOCKET_GROUP), function(e) {
|
|
123
|
+
if (e) console.error(e);
|
|
124
|
+
});
|
|
125
|
+
} catch(e) {
|
|
126
|
+
console.error(e);
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
that.pub_socket_ready = true;
|
|
132
|
+
that.sendReady(cb);
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Rep/Req - RPC system to interact with God
|
|
137
|
+
*/
|
|
138
|
+
this.rep = axon.socket('rep');
|
|
139
|
+
|
|
140
|
+
var server = new rpc.Server(this.rep);
|
|
141
|
+
|
|
142
|
+
this.rpc_socket = this.rep.bind(this.rpc_socket_file);
|
|
143
|
+
|
|
144
|
+
// Only unix socket files can be chmod'ed/chown'ed; skip for tcp:// addresses
|
|
145
|
+
// (openharmony transport).
|
|
146
|
+
var rpc_is_tcp = String(this.rpc_socket_file).indexOf('tcp://') === 0;
|
|
147
|
+
|
|
148
|
+
this.rpc_socket.once('bind', function() {
|
|
149
|
+
if (!rpc_is_tcp) {
|
|
150
|
+
fs.chmod(that.rpc_socket_file, '775', function(e) {
|
|
151
|
+
if (e) console.error(e);
|
|
152
|
+
|
|
153
|
+
try {
|
|
154
|
+
if (process.env.PM2_SOCKET_USER && process.env.PM2_SOCKET_GROUP)
|
|
155
|
+
fs.chown(that.rpc_socket_file,
|
|
156
|
+
parseInt(process.env.PM2_SOCKET_USER),
|
|
157
|
+
parseInt(process.env.PM2_SOCKET_GROUP), function(e) {
|
|
158
|
+
if (e) console.error(e);
|
|
159
|
+
});
|
|
160
|
+
} catch(e) {
|
|
161
|
+
console.error(e);
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
that.rpc_socket_ready = true;
|
|
168
|
+
that.sendReady(cb);
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Memory Snapshot
|
|
174
|
+
*/
|
|
175
|
+
function profile(type, msg, cb) {
|
|
176
|
+
var cmd
|
|
177
|
+
|
|
178
|
+
if (type === 'cpu') {
|
|
179
|
+
cmd = {
|
|
180
|
+
enable: 'Profiler.enable',
|
|
181
|
+
start: 'Profiler.start',
|
|
182
|
+
stop: 'Profiler.stop',
|
|
183
|
+
disable: 'Profiler.disable'
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
if (type == 'mem') {
|
|
187
|
+
cmd = {
|
|
188
|
+
enable: 'HeapProfiler.enable',
|
|
189
|
+
start: 'HeapProfiler.startSampling',
|
|
190
|
+
stop: 'HeapProfiler.stopSampling',
|
|
191
|
+
disable: 'HeapProfiler.disable'
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
const inspector = require('inspector')
|
|
196
|
+
var session = new inspector.Session()
|
|
197
|
+
|
|
198
|
+
session.connect()
|
|
199
|
+
|
|
200
|
+
var timeout = msg.timeout || 5000
|
|
201
|
+
|
|
202
|
+
session.post(cmd.enable, (err, data) => {
|
|
203
|
+
if (err) return cb(null, { error: err.message || err })
|
|
204
|
+
|
|
205
|
+
console.log(`Starting ${cmd.start}`)
|
|
206
|
+
session.post(cmd.start, (err, data) => {
|
|
207
|
+
if (err) return cb(null, { error: err.message || err })
|
|
208
|
+
|
|
209
|
+
setTimeout(() => {
|
|
210
|
+
session.post(cmd.stop, (err, data) => {
|
|
211
|
+
if (err) return cb(null, { error: err.message || err })
|
|
212
|
+
const profile = data.profile
|
|
213
|
+
|
|
214
|
+
console.log(`Stopping ${cmd.stop}`)
|
|
215
|
+
session.post(cmd.disable)
|
|
216
|
+
|
|
217
|
+
fs.writeFile(msg.pwd, JSON.stringify(profile), (err) => {
|
|
218
|
+
if (err) return cb(null, { error: err.message || err })
|
|
219
|
+
return cb(null, { file : msg.pwd })
|
|
220
|
+
})
|
|
221
|
+
})
|
|
222
|
+
}, timeout)
|
|
223
|
+
})
|
|
224
|
+
})
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
server.expose({
|
|
228
|
+
killMe : that.close.bind(this),
|
|
229
|
+
profileCPU : profile.bind(this, 'cpu'),
|
|
230
|
+
profileMEM : profile.bind(this, 'mem'),
|
|
231
|
+
prepare : God.prepare,
|
|
232
|
+
getMonitorData : God.getMonitorData,
|
|
233
|
+
getSystemData : God.getSystemData,
|
|
234
|
+
|
|
235
|
+
startProcessId : God.startProcessId,
|
|
236
|
+
stopProcessId : God.stopProcessId,
|
|
237
|
+
restartProcessId : God.restartProcessId,
|
|
238
|
+
deleteProcessId : God.deleteProcessId,
|
|
239
|
+
|
|
240
|
+
sendLineToStdin : God.sendLineToStdin,
|
|
241
|
+
softReloadProcessId : God.softReloadProcessId,
|
|
242
|
+
reloadProcessId : God.reloadProcessId,
|
|
243
|
+
duplicateProcessId : God.duplicateProcessId,
|
|
244
|
+
resetMetaProcessId : God.resetMetaProcessId,
|
|
245
|
+
stopWatch : God.stopWatch,
|
|
246
|
+
startWatch : God.startWatch,
|
|
247
|
+
toggleWatch : God.toggleWatch,
|
|
248
|
+
notifyByProcessId : God.notifyByProcessId,
|
|
249
|
+
|
|
250
|
+
notifyKillPM2 : God.notifyKillPM2,
|
|
251
|
+
monitor : God.monitor,
|
|
252
|
+
unmonitor : God.unmonitor,
|
|
253
|
+
|
|
254
|
+
msgProcess : God.msgProcess,
|
|
255
|
+
sendDataToProcessId : God.sendDataToProcessId,
|
|
256
|
+
sendSignalToProcessId : God.sendSignalToProcessId,
|
|
257
|
+
sendSignalToProcessName : God.sendSignalToProcessName,
|
|
258
|
+
|
|
259
|
+
ping : God.ping,
|
|
260
|
+
getVersion : God.getVersion,
|
|
261
|
+
getReport : God.getReport,
|
|
262
|
+
reloadLogs : God.reloadLogs
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
this.startLogic();
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
Daemon.prototype.close = function(opts, cb) {
|
|
269
|
+
var that = this;
|
|
270
|
+
|
|
271
|
+
God.bus.emit('pm2:kill', {
|
|
272
|
+
status : 'killed',
|
|
273
|
+
msg : 'pm2 has been killed via CLI'
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
if (God.system_infos_proc !== null)
|
|
277
|
+
God.system_infos_proc.kill()
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* Cleanly kill pm2
|
|
281
|
+
*/
|
|
282
|
+
that.rpc_socket.close(function() {
|
|
283
|
+
that.pub_socket.close(function() {
|
|
284
|
+
|
|
285
|
+
// notify cli that the daemon is shuting down (only under unix since windows doesnt handle signals)
|
|
286
|
+
if (cst.IS_WINDOWS === false) {
|
|
287
|
+
try {
|
|
288
|
+
process.kill(parseInt(opts.pid), 'SIGQUIT');
|
|
289
|
+
} catch(e) {
|
|
290
|
+
console.error('Could not send SIGQUIT to CLI');
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
try {
|
|
295
|
+
fs.unlinkSync(that.pid_path);
|
|
296
|
+
} catch(e) {}
|
|
297
|
+
|
|
298
|
+
console.log('PM2 successfully stopped');
|
|
299
|
+
setTimeout(function() {
|
|
300
|
+
process.exit(cst.SUCCESS_EXIT);
|
|
301
|
+
}, 2);
|
|
302
|
+
});
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
Daemon.prototype.handleSignals = function() {
|
|
307
|
+
var that = this;
|
|
308
|
+
|
|
309
|
+
process.on('SIGTERM', that.gracefullExit.bind(this));
|
|
310
|
+
process.on('SIGINT', that.gracefullExit.bind(this));
|
|
311
|
+
process.on('SIGHUP', function() {});
|
|
312
|
+
process.on('SIGQUIT', that.gracefullExit.bind(this));
|
|
313
|
+
process.on('SIGUSR2', function() {
|
|
314
|
+
God.reloadLogs({}, function() {});
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
Daemon.prototype.sendReady = function(cb) {
|
|
319
|
+
// Send ready message to Client
|
|
320
|
+
if (this.rpc_socket_ready == true && this.pub_socket_ready == true) {
|
|
321
|
+
cb(null, {
|
|
322
|
+
pid : process.pid,
|
|
323
|
+
pm2_version : pkg.version
|
|
324
|
+
});
|
|
325
|
+
if (typeof(process.send) != 'function')
|
|
326
|
+
return false;
|
|
327
|
+
|
|
328
|
+
process.send({
|
|
329
|
+
online : true,
|
|
330
|
+
success : true,
|
|
331
|
+
pid : process.pid,
|
|
332
|
+
pm2_version : pkg.version
|
|
333
|
+
});
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
Daemon.prototype.gracefullExit = function() {
|
|
338
|
+
var that = this;
|
|
339
|
+
|
|
340
|
+
// never execute multiple gracefullExit simultaneously
|
|
341
|
+
// this can lead to loss of some apps in dump file
|
|
342
|
+
if (this.isExiting) return
|
|
343
|
+
|
|
344
|
+
this.isExiting = true
|
|
345
|
+
|
|
346
|
+
God.bus.emit('pm2:kill', {
|
|
347
|
+
status : 'killed',
|
|
348
|
+
msg : 'pm2 has been killed by SIGNAL'
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
console.log('pm2 has been killed by signal, dumping process list before exit...');
|
|
352
|
+
|
|
353
|
+
if (God.system_infos_proc !== null)
|
|
354
|
+
God.system_infos_proc.kill()
|
|
355
|
+
|
|
356
|
+
God.dumpProcessList(function() {
|
|
357
|
+
|
|
358
|
+
var processes = God.getFormatedProcesses();
|
|
359
|
+
|
|
360
|
+
eachLimit(processes, 1, function(proc, next) {
|
|
361
|
+
console.log('Deleting process %s', proc.pm2_env.pm_id);
|
|
362
|
+
God.deleteProcessId(proc.pm2_env.pm_id, function() {
|
|
363
|
+
return next();
|
|
364
|
+
});
|
|
365
|
+
}, function(err) {
|
|
366
|
+
try {
|
|
367
|
+
fs.unlinkSync(that.pid_path);
|
|
368
|
+
} catch(e) {}
|
|
369
|
+
setTimeout(function() {
|
|
370
|
+
that.isExiting = false
|
|
371
|
+
console.log('Exited peacefully');
|
|
372
|
+
process.exit(cst.SUCCESS_EXIT);
|
|
373
|
+
}, 2);
|
|
374
|
+
});
|
|
375
|
+
});
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
Daemon.prototype.startLogic = function() {
|
|
379
|
+
var that = this;
|
|
380
|
+
|
|
381
|
+
/**
|
|
382
|
+
* Action treatment specifics
|
|
383
|
+
* Attach actions to pm2_env.axm_actions variables (name + options)
|
|
384
|
+
*/
|
|
385
|
+
God.bus.on('axm:action', function axmActions(msg) {
|
|
386
|
+
var pm2_env = msg.process;
|
|
387
|
+
var exists = false;
|
|
388
|
+
var axm_action = msg.data;
|
|
389
|
+
|
|
390
|
+
if (!pm2_env || !God.clusters_db[pm2_env.pm_id])
|
|
391
|
+
return console.error('AXM ACTION Unknown id %s', pm2_env.pm_id);
|
|
392
|
+
|
|
393
|
+
if (!God.clusters_db[pm2_env.pm_id].pm2_env.axm_actions)
|
|
394
|
+
God.clusters_db[pm2_env.pm_id].pm2_env.axm_actions = [];
|
|
395
|
+
|
|
396
|
+
God.clusters_db[pm2_env.pm_id].pm2_env.axm_actions.forEach(function(actions) {
|
|
397
|
+
if (actions.action_name == axm_action.action_name)
|
|
398
|
+
exists = true;
|
|
399
|
+
});
|
|
400
|
+
|
|
401
|
+
if (exists === false) {
|
|
402
|
+
debug('Adding action', axm_action);
|
|
403
|
+
God.clusters_db[pm2_env.pm_id].pm2_env.axm_actions.push(axm_action);
|
|
404
|
+
}
|
|
405
|
+
msg = null;
|
|
406
|
+
});
|
|
407
|
+
|
|
408
|
+
/**
|
|
409
|
+
* Configure module
|
|
410
|
+
*/
|
|
411
|
+
God.bus.on('axm:option:configuration', function axmMonitor(msg) {
|
|
412
|
+
if (!msg.process)
|
|
413
|
+
return console.error('[axm:option:configuration] no process defined');
|
|
414
|
+
|
|
415
|
+
if (!God.clusters_db[msg.process.pm_id])
|
|
416
|
+
return console.error('[axm:option:configuration] Unknown id %s', msg.process.pm_id);
|
|
417
|
+
|
|
418
|
+
try {
|
|
419
|
+
// Application Name nverride
|
|
420
|
+
if (msg.data.name)
|
|
421
|
+
God.clusters_db[msg.process.pm_id].pm2_env.name = msg.data.name;
|
|
422
|
+
|
|
423
|
+
Object.keys(msg.data).forEach(function(conf_key) {
|
|
424
|
+
God.clusters_db[msg.process.pm_id].pm2_env.axm_options[conf_key] = Utility.clone(msg.data[conf_key]);
|
|
425
|
+
});
|
|
426
|
+
} catch(e) {
|
|
427
|
+
console.error(e.stack || e);
|
|
428
|
+
}
|
|
429
|
+
msg = null;
|
|
430
|
+
});
|
|
431
|
+
|
|
432
|
+
/**
|
|
433
|
+
* Process monitoring data (probes)
|
|
434
|
+
*/
|
|
435
|
+
God.bus.on('axm:monitor', function axmMonitor(msg) {
|
|
436
|
+
if (!msg.process)
|
|
437
|
+
return console.error('[axm:monitor] no process defined');
|
|
438
|
+
|
|
439
|
+
if (!msg.process || !God.clusters_db[msg.process.pm_id])
|
|
440
|
+
return console.error('AXM MONITOR Unknown id %s', msg.process.pm_id);
|
|
441
|
+
|
|
442
|
+
Object.assign(God.clusters_db[msg.process.pm_id].pm2_env.axm_monitor, Utility.clone(msg.data));
|
|
443
|
+
msg = null;
|
|
444
|
+
});
|
|
445
|
+
|
|
446
|
+
/**
|
|
447
|
+
* Broadcast messages
|
|
448
|
+
*/
|
|
449
|
+
God.bus.onAny(function(event, data_v) {
|
|
450
|
+
if (['axm:action',
|
|
451
|
+
'axm:monitor',
|
|
452
|
+
'axm:option:setPID',
|
|
453
|
+
'axm:option:configuration'].indexOf(event) > -1) {
|
|
454
|
+
data_v = null;
|
|
455
|
+
return false;
|
|
456
|
+
}
|
|
457
|
+
that.pub.emit(event, Utility.clone(data_v));
|
|
458
|
+
data_v = null;
|
|
459
|
+
});
|
|
460
|
+
};
|
|
461
|
+
|
|
462
|
+
if (require.main === module) {
|
|
463
|
+
process.title = process.env.PM2_DAEMON_TITLE || 'PM2 v' + pkg.version + ': God Daemon (' + process.env.PM2_HOME + ')';
|
|
464
|
+
|
|
465
|
+
var daemon = new Daemon();
|
|
466
|
+
|
|
467
|
+
daemon.start();
|
|
468
|
+
}
|
package/lib/Event.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
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 Utility = require('./Utility.js');
|
|
8
|
+
|
|
9
|
+
module.exports = function(God) {
|
|
10
|
+
|
|
11
|
+
God.notify = function(action_name, data, manually) {
|
|
12
|
+
God.bus.emit('process:event', {
|
|
13
|
+
event : action_name,
|
|
14
|
+
manually : typeof(manually) == 'undefined' ? false : true,
|
|
15
|
+
process : Utility.formatCLU(data),
|
|
16
|
+
at : Utility.getDate()
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
God.notifyByProcessId = function(opts, cb) {
|
|
21
|
+
if (typeof(opts.id) === 'undefined') { return cb(new Error('process id missing')); }
|
|
22
|
+
var proc = God.clusters_db[opts.id];
|
|
23
|
+
if (!proc) { return cb(new Error('process id doesnt exists')); }
|
|
24
|
+
|
|
25
|
+
God.bus.emit('process:event', {
|
|
26
|
+
event : opts.action_name,
|
|
27
|
+
manually : typeof(opts.manually) == 'undefined' ? false : true,
|
|
28
|
+
process : Utility.formatCLU(proc),
|
|
29
|
+
at : Utility.getDate()
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
process.nextTick(function() {
|
|
33
|
+
return cb ? cb(null) : false;
|
|
34
|
+
});
|
|
35
|
+
return false;
|
|
36
|
+
};
|
|
37
|
+
};
|