@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,351 @@
|
|
|
1
|
+
var chalk = require('ansis');
|
|
2
|
+
var util = require('util');
|
|
3
|
+
var fs = require('fs');
|
|
4
|
+
var exec = require('child_process').exec;
|
|
5
|
+
var path = require('path');
|
|
6
|
+
|
|
7
|
+
var Log = require('./Log');
|
|
8
|
+
var cst = require('../../constants.js');
|
|
9
|
+
var Common = require('../Common.js');
|
|
10
|
+
|
|
11
|
+
module.exports = function(CLI) {
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Description
|
|
15
|
+
* @method flush
|
|
16
|
+
* @return
|
|
17
|
+
*/
|
|
18
|
+
CLI.prototype.flush = function(api, cb) {
|
|
19
|
+
var that = this;
|
|
20
|
+
|
|
21
|
+
if (!api) {
|
|
22
|
+
Common.printOut(cst.PREFIX_MSG + 'Flushing ' + cst.PM2_LOG_FILE_PATH);
|
|
23
|
+
fs.closeSync(fs.openSync(cst.PM2_LOG_FILE_PATH, 'w'));
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
that.Client.executeRemote('getMonitorData', {}, function(err, list) {
|
|
27
|
+
if (err) {
|
|
28
|
+
Common.printError(err);
|
|
29
|
+
return cb ? cb(Common.retErr(err)) : that.exitCli(cst.ERROR_EXIT);
|
|
30
|
+
}
|
|
31
|
+
list.forEach(function(l) {
|
|
32
|
+
if (typeof api == 'undefined') {
|
|
33
|
+
Common.printOut(cst.PREFIX_MSG + 'Flushing:');
|
|
34
|
+
Common.printOut(cst.PREFIX_MSG + l.pm2_env.pm_out_log_path);
|
|
35
|
+
Common.printOut(cst.PREFIX_MSG + l.pm2_env.pm_err_log_path);
|
|
36
|
+
|
|
37
|
+
if (l.pm2_env.pm_log_path) {
|
|
38
|
+
Common.printOut(cst.PREFIX_MSG + l.pm2_env.pm_log_path);
|
|
39
|
+
fs.closeSync(fs.openSync(l.pm2_env.pm_log_path, 'w'));
|
|
40
|
+
}
|
|
41
|
+
fs.closeSync(fs.openSync(l.pm2_env.pm_out_log_path, 'w'));
|
|
42
|
+
fs.closeSync(fs.openSync(l.pm2_env.pm_err_log_path, 'w'));
|
|
43
|
+
}
|
|
44
|
+
else if (l.pm2_env.pm_id == api || l.pm2_env.name === api) {
|
|
45
|
+
Common.printOut(cst.PREFIX_MSG + 'Flushing:');
|
|
46
|
+
|
|
47
|
+
if (l.pm2_env.pm_log_path && fs.existsSync(l.pm2_env.pm_log_path)) {
|
|
48
|
+
Common.printOut(cst.PREFIX_MSG + l.pm2_env.pm_log_path);
|
|
49
|
+
fs.closeSync(fs.openSync(l.pm2_env.pm_log_path, 'w'));
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (l.pm2_env.pm_out_log_path && fs.existsSync(l.pm2_env.pm_out_log_path)) {
|
|
53
|
+
Common.printOut(cst.PREFIX_MSG + l.pm2_env.pm_out_log_path);
|
|
54
|
+
fs.closeSync(fs.openSync(l.pm2_env.pm_out_log_path, 'w'));
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (l.pm2_env.pm_err_log_path && fs.existsSync(l.pm2_env.pm_err_log_path)) {
|
|
58
|
+
Common.printOut(cst.PREFIX_MSG + l.pm2_env.pm_err_log_path);
|
|
59
|
+
fs.closeSync(fs.openSync(l.pm2_env.pm_err_log_path, 'w'));
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
Common.printOut(cst.PREFIX_MSG + 'Logs flushed');
|
|
65
|
+
return cb ? cb(null, list) : that.exitCli(cst.SUCCESS_EXIT);
|
|
66
|
+
});
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
CLI.prototype.logrotate = function(opts, cb) {
|
|
70
|
+
var that = this;
|
|
71
|
+
|
|
72
|
+
if (process.getuid() != 0) {
|
|
73
|
+
return exec('whoami', function(err, stdout, stderr) {
|
|
74
|
+
Common.printError(cst.PREFIX_MSG + 'You have to run this command as root. Execute the following command:');
|
|
75
|
+
Common.printError(cst.PREFIX_MSG + chalk.gray(' sudo env PATH=$PATH:' + path.dirname(process.execPath) + ' pm2 logrotate -u ' + stdout.trim()));
|
|
76
|
+
|
|
77
|
+
cb ? cb(Common.retErr('You have to run this with elevated rights')) : that.exitCli(cst.ERROR_EXIT);
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (!fs.existsSync('/etc/logrotate.d')) {
|
|
82
|
+
Common.printError(cst.PREFIX_MSG + '/etc/logrotate.d does not exist we can not copy the default configuration.');
|
|
83
|
+
return cb ? cb(Common.retErr('/etc/logrotate.d does not exist')) : that.exitCli(cst.ERROR_EXIT);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
var templatePath = path.join(cst.TEMPLATE_FOLDER, cst.LOGROTATE_SCRIPT);
|
|
87
|
+
Common.printOut(cst.PREFIX_MSG + 'Getting logrorate template ' + templatePath);
|
|
88
|
+
var script = fs.readFileSync(templatePath, {encoding: 'utf8'});
|
|
89
|
+
|
|
90
|
+
var user = opts.user || 'root';
|
|
91
|
+
|
|
92
|
+
script = script.replace(/%HOME_PATH%/g, cst.PM2_ROOT_PATH)
|
|
93
|
+
.replace(/%USER%/g, user);
|
|
94
|
+
|
|
95
|
+
try {
|
|
96
|
+
fs.writeFileSync('/etc/logrotate.d/pm2-'+user, script);
|
|
97
|
+
} catch (e) {
|
|
98
|
+
console.error(e.stack || e);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
Common.printOut(cst.PREFIX_MSG + 'Logrotate configuration added to /etc/logrotate.d/pm2');
|
|
102
|
+
return cb ? cb(null, {success:true}) : that.exitCli(cst.SUCCESS_EXIT);
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Description
|
|
107
|
+
* @method reloadLogs
|
|
108
|
+
* @return
|
|
109
|
+
*/
|
|
110
|
+
CLI.prototype.reloadLogs = function(cb) {
|
|
111
|
+
var that = this;
|
|
112
|
+
|
|
113
|
+
Common.printOut('Reloading all logs...');
|
|
114
|
+
that.Client.executeRemote('reloadLogs', {}, function(err, logs) {
|
|
115
|
+
if (err) {
|
|
116
|
+
Common.printError(err);
|
|
117
|
+
return cb ? cb(Common.retErr(err)) : that.exitCli(cst.ERROR_EXIT);
|
|
118
|
+
}
|
|
119
|
+
Common.printOut('All logs reloaded');
|
|
120
|
+
return cb ? cb(null, logs) : that.exitCli(cst.SUCCESS_EXIT);
|
|
121
|
+
});
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Description
|
|
126
|
+
* @method streamLogs
|
|
127
|
+
* @param {String} id
|
|
128
|
+
* @param {Number} lines
|
|
129
|
+
* @param {Boolean} raw
|
|
130
|
+
* @return
|
|
131
|
+
*/
|
|
132
|
+
CLI.prototype.streamLogs = function(id, lines, raw, timestamp, exclusive, highlight) {
|
|
133
|
+
var that = this;
|
|
134
|
+
var files_list = [];
|
|
135
|
+
|
|
136
|
+
// If no argument is given, we stream logs for all running apps
|
|
137
|
+
id = id || 'all';
|
|
138
|
+
lines = lines !== undefined ? lines : 20;
|
|
139
|
+
lines = lines < 0 ? -(lines) : lines;
|
|
140
|
+
|
|
141
|
+
// Avoid duplicates and check if path is different from '/dev/null'
|
|
142
|
+
var pushIfUnique = function(entry) {
|
|
143
|
+
var exists = false;
|
|
144
|
+
|
|
145
|
+
if (entry.path.toLowerCase
|
|
146
|
+
&& entry.path.toLowerCase() !== '/dev/null') {
|
|
147
|
+
|
|
148
|
+
files_list.some(function(file) {
|
|
149
|
+
if (file.path === entry.path)
|
|
150
|
+
exists = true;
|
|
151
|
+
return exists;
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
if (exists)
|
|
155
|
+
return;
|
|
156
|
+
|
|
157
|
+
files_list.push(entry);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// Get the list of all running apps
|
|
162
|
+
that.Client.executeRemote('getMonitorData', {}, function(err, list) {
|
|
163
|
+
var regex = Log.parseRegexId(id);
|
|
164
|
+
|
|
165
|
+
if (err) {
|
|
166
|
+
Common.printError(err);
|
|
167
|
+
that.exitCli(cst.ERROR_EXIT);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
if (lines === 0)
|
|
171
|
+
return Log.stream(that.Client, id, raw, timestamp, exclusive, highlight);
|
|
172
|
+
|
|
173
|
+
Common.printOut(chalk.bold.gray(util.format.call(this, '[TAILING] Tailing last %d lines for [%s] process%s (change the value with --lines option)', lines, id, id === 'all' ? 'es' : '')));
|
|
174
|
+
|
|
175
|
+
// Populate the array `files_list` with the paths of all files we need to tail
|
|
176
|
+
list.forEach(function(proc) {
|
|
177
|
+
if (proc.pm2_env && (id === 'all' ||
|
|
178
|
+
proc.pm2_env.name == id ||
|
|
179
|
+
proc.pm2_env.pm_id == id)) {
|
|
180
|
+
if (proc.pm2_env.pm_out_log_path && exclusive !== 'err')
|
|
181
|
+
pushIfUnique({
|
|
182
|
+
path : proc.pm2_env.pm_out_log_path,
|
|
183
|
+
app_name :proc.pm2_env.pm_id + '|' + proc.pm2_env.name,
|
|
184
|
+
type : 'out'});
|
|
185
|
+
if (proc.pm2_env.pm_err_log_path && exclusive !== 'out')
|
|
186
|
+
pushIfUnique({
|
|
187
|
+
path : proc.pm2_env.pm_err_log_path,
|
|
188
|
+
app_name : proc.pm2_env.pm_id + '|' + proc.pm2_env.name,
|
|
189
|
+
type : 'err'
|
|
190
|
+
});
|
|
191
|
+
} else if(proc.pm2_env && proc.pm2_env.namespace == id) {
|
|
192
|
+
if (proc.pm2_env.pm_out_log_path && exclusive !== 'err')
|
|
193
|
+
pushIfUnique({
|
|
194
|
+
path : proc.pm2_env.pm_out_log_path,
|
|
195
|
+
app_name :proc.pm2_env.pm_id + '|' + proc.pm2_env.name,
|
|
196
|
+
type : 'out'});
|
|
197
|
+
if (proc.pm2_env.pm_err_log_path && exclusive !== 'out')
|
|
198
|
+
pushIfUnique({
|
|
199
|
+
path : proc.pm2_env.pm_err_log_path,
|
|
200
|
+
app_name : proc.pm2_env.pm_id + '|' + proc.pm2_env.name,
|
|
201
|
+
type : 'err'
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
// Populate the array `files_list` with the paths of all files we need to tail, when log in put is a regex
|
|
205
|
+
else if(proc.pm2_env && regex !== null) {
|
|
206
|
+
if(regex.test(proc.pm2_env.name)) {
|
|
207
|
+
if (proc.pm2_env.pm_out_log_path && exclusive !== 'err')
|
|
208
|
+
pushIfUnique({
|
|
209
|
+
path : proc.pm2_env.pm_out_log_path,
|
|
210
|
+
app_name : proc.pm2_env.pm_id + '|' + proc.pm2_env.name,
|
|
211
|
+
type : 'out'});
|
|
212
|
+
if (proc.pm2_env.pm_err_log_path && exclusive !== 'out')
|
|
213
|
+
pushIfUnique({
|
|
214
|
+
path : proc.pm2_env.pm_err_log_path,
|
|
215
|
+
app_name : proc.pm2_env.pm_id + '|' + proc.pm2_env.name,
|
|
216
|
+
type : 'err'
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
//for fixing issue https://github.com/Unitech/pm2/issues/3506
|
|
223
|
+
/* if (files_list && files_list.length == 0) {
|
|
224
|
+
Common.printError(cst.PREFIX_MSG_ERR + 'No file to stream for app [%s], exiting.', id);
|
|
225
|
+
return process.exit(cst.ERROR_EXIT);
|
|
226
|
+
}*/
|
|
227
|
+
|
|
228
|
+
if (!raw && (id === 'all' || id === 'PM2') && exclusive === false) {
|
|
229
|
+
Log.tail([{
|
|
230
|
+
path : cst.PM2_LOG_FILE_PATH,
|
|
231
|
+
app_name : 'PM2',
|
|
232
|
+
type : 'PM2'
|
|
233
|
+
}], lines, raw, function() {
|
|
234
|
+
Log.tail(files_list, lines, raw, function() {
|
|
235
|
+
Log.stream(that.Client, id, raw, timestamp, exclusive, highlight);
|
|
236
|
+
});
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
else {
|
|
240
|
+
Log.tail(files_list, lines, raw, function() {
|
|
241
|
+
Log.stream(that.Client, id, raw, timestamp, exclusive, highlight);
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Description
|
|
249
|
+
* @method printLogs
|
|
250
|
+
* @param {String} id
|
|
251
|
+
* @param {Number} lines
|
|
252
|
+
* @param {Boolean} raw
|
|
253
|
+
* @return
|
|
254
|
+
*/
|
|
255
|
+
CLI.prototype.printLogs = function(id, lines, raw, timestamp, exclusive) {
|
|
256
|
+
var that = this;
|
|
257
|
+
var files_list = [];
|
|
258
|
+
|
|
259
|
+
// If no argument is given, we stream logs for all running apps
|
|
260
|
+
id = id || 'all';
|
|
261
|
+
lines = lines !== undefined ? lines : 20;
|
|
262
|
+
lines = lines < 0 ? -(lines) : lines;
|
|
263
|
+
|
|
264
|
+
// Avoid duplicates and check if path is different from '/dev/null'
|
|
265
|
+
var pushIfUnique = function(entry) {
|
|
266
|
+
var exists = false;
|
|
267
|
+
|
|
268
|
+
if (entry.path.toLowerCase
|
|
269
|
+
&& entry.path.toLowerCase() !== '/dev/null') {
|
|
270
|
+
|
|
271
|
+
files_list.some(function(file) {
|
|
272
|
+
if (file.path === entry.path)
|
|
273
|
+
exists = true;
|
|
274
|
+
return exists;
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
if (exists)
|
|
278
|
+
return;
|
|
279
|
+
|
|
280
|
+
files_list.push(entry);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
// Get the list of all running apps
|
|
285
|
+
that.Client.executeRemote('getMonitorData', {}, function(err, list) {
|
|
286
|
+
if (err) {
|
|
287
|
+
Common.printError(err);
|
|
288
|
+
that.exitCli(cst.ERROR_EXIT);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
if (lines <= 0) {
|
|
292
|
+
return that.exitCli(cst.SUCCESS_EXIT)
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
Common.printOut(chalk.bold.gray(util.format.call(this, '[TAILING] Tailing last %d lines for [%s] process%s (change the value with --lines option)', lines, id, id === 'all' ? 'es' : '')));
|
|
296
|
+
|
|
297
|
+
// Populate the array `files_list` with the paths of all files we need to tail
|
|
298
|
+
list.forEach(function(proc) {
|
|
299
|
+
if (proc.pm2_env && (id === 'all' ||
|
|
300
|
+
proc.pm2_env.name == id ||
|
|
301
|
+
proc.pm2_env.pm_id == id)) {
|
|
302
|
+
if (proc.pm2_env.pm_out_log_path && exclusive !== 'err')
|
|
303
|
+
pushIfUnique({
|
|
304
|
+
path : proc.pm2_env.pm_out_log_path,
|
|
305
|
+
app_name :proc.pm2_env.pm_id + '|' + proc.pm2_env.name,
|
|
306
|
+
type : 'out'});
|
|
307
|
+
if (proc.pm2_env.pm_err_log_path && exclusive !== 'out')
|
|
308
|
+
pushIfUnique({
|
|
309
|
+
path : proc.pm2_env.pm_err_log_path,
|
|
310
|
+
app_name : proc.pm2_env.pm_id + '|' + proc.pm2_env.name,
|
|
311
|
+
type : 'err'
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
// Populate the array `files_list` with the paths of all files we need to tail, when log in put is a regex
|
|
315
|
+
else if(proc.pm2_env && (isNaN(id) && id[0] === '/' && id[id.length - 1] === '/')) {
|
|
316
|
+
var regex = new RegExp(id.replace(/\//g, ''));
|
|
317
|
+
if(regex.test(proc.pm2_env.name)) {
|
|
318
|
+
if (proc.pm2_env.pm_out_log_path && exclusive !== 'err')
|
|
319
|
+
pushIfUnique({
|
|
320
|
+
path : proc.pm2_env.pm_out_log_path,
|
|
321
|
+
app_name : proc.pm2_env.pm_id + '|' + proc.pm2_env.name,
|
|
322
|
+
type : 'out'});
|
|
323
|
+
if (proc.pm2_env.pm_err_log_path && exclusive !== 'out')
|
|
324
|
+
pushIfUnique({
|
|
325
|
+
path : proc.pm2_env.pm_err_log_path,
|
|
326
|
+
app_name : proc.pm2_env.pm_id + '|' + proc.pm2_env.name,
|
|
327
|
+
type : 'err'
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
if (!raw && (id === 'all' || id === 'PM2') && exclusive === false) {
|
|
334
|
+
Log.tail([{
|
|
335
|
+
path : cst.PM2_LOG_FILE_PATH,
|
|
336
|
+
app_name : 'PM2',
|
|
337
|
+
type : 'PM2'
|
|
338
|
+
}], lines, raw, function() {
|
|
339
|
+
Log.tail(files_list, lines, raw, function() {
|
|
340
|
+
that.exitCli(cst.SUCCESS_EXIT);
|
|
341
|
+
});
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
else {
|
|
345
|
+
Log.tail(files_list, lines, raw, function() {
|
|
346
|
+
that.exitCli(cst.SUCCESS_EXIT);
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
});
|
|
350
|
+
};
|
|
351
|
+
};
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
|
|
2
|
+
var path = require('path');
|
|
3
|
+
var fs = require('fs');
|
|
4
|
+
var os = require('os');
|
|
5
|
+
var spawn = require('child_process').spawn;
|
|
6
|
+
var chalk = require('ansis');
|
|
7
|
+
var parallel = require('async/parallel');
|
|
8
|
+
|
|
9
|
+
var Configuration = require('../../Configuration.js');
|
|
10
|
+
var cst = require('../../../constants.js');
|
|
11
|
+
var Common = require('../../Common');
|
|
12
|
+
var Utility = require('../../Utility.js');
|
|
13
|
+
var readline = require('readline')
|
|
14
|
+
|
|
15
|
+
var INTERNAL_MODULES = {
|
|
16
|
+
'deep-monitoring': {
|
|
17
|
+
dependencies: [{name: 'v8-profiler-node8'}, {name: 'gc-stats'}, {name: 'event-loop-inspector'}]
|
|
18
|
+
},
|
|
19
|
+
'gc-stats': {name: 'gc-stats'},
|
|
20
|
+
'event-loop-inspector': {name: 'event-loop-inspector'},
|
|
21
|
+
'v8-profiler': {name: 'v8-profiler-node8'},
|
|
22
|
+
'profiler': {name: 'v8-profiler-node8'},
|
|
23
|
+
'typescript': {dependencies: [{name: 'typescript'}, {name: 'ts-node@latest'}]},
|
|
24
|
+
'livescript': {name: 'livescript'},
|
|
25
|
+
'coffee-script': {name: 'coffee-script', message: 'Coffeescript v1 support'},
|
|
26
|
+
'coffeescript': {name: 'coffeescript', message: 'Coffeescript v2 support'}
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
module.exports = {
|
|
30
|
+
install,
|
|
31
|
+
INTERNAL_MODULES,
|
|
32
|
+
installMultipleModules
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
function install(module, cb, verbose) {
|
|
37
|
+
if (!module || !module.name || module.name.length === 0) {
|
|
38
|
+
return cb(new Error('No module name !'));
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (typeof verbose === 'undefined') {
|
|
42
|
+
verbose = true;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
installLangModule(module.name, function (err) {
|
|
46
|
+
var display = module.message || module.name;
|
|
47
|
+
if (err) {
|
|
48
|
+
if (verbose) { Common.printError(cst.PREFIX_MSG_MOD_ERR + chalk.bold.green(display + ' installation has FAILED (checkout previous logs)')); }
|
|
49
|
+
return cb(err);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (verbose) { Common.printOut(cst.PREFIX_MSG + chalk.bold.green(display + ' ENABLED')); }
|
|
53
|
+
return cb();
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function installMultipleModules(modules, cb, post_install) {
|
|
58
|
+
var functionList = [];
|
|
59
|
+
for (var i = 0; i < modules.length; i++) {
|
|
60
|
+
functionList.push((function (index) {
|
|
61
|
+
return function (callback) {
|
|
62
|
+
var module = modules[index];
|
|
63
|
+
if (typeof modules[index] === 'string') {
|
|
64
|
+
module = {name: modules[index]};
|
|
65
|
+
}
|
|
66
|
+
install(module, function ($post_install, err, $index, $modules) {
|
|
67
|
+
try {
|
|
68
|
+
var install_instance = spawn(post_install[modules[index]], {
|
|
69
|
+
stdio : 'inherit',
|
|
70
|
+
windowsHide: true,
|
|
71
|
+
env: process.env,
|
|
72
|
+
shell : true,
|
|
73
|
+
cwd : process.cwd()
|
|
74
|
+
});
|
|
75
|
+
Common.printOut(cst.PREFIX_MSG_MOD + 'Running configuraton script.');
|
|
76
|
+
}
|
|
77
|
+
catch(e)
|
|
78
|
+
{
|
|
79
|
+
Common.printOut(cst.PREFIX_MSG_MOD + 'No configuraton script found.');
|
|
80
|
+
}
|
|
81
|
+
callback(null, { module: module, err: err });
|
|
82
|
+
}, false);
|
|
83
|
+
};
|
|
84
|
+
})(i));
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
parallel(functionList, function (err, results) {
|
|
88
|
+
for (var i = 0; i < results.length; i++) {
|
|
89
|
+
var display = results[i].module.message || results[i].module.name;
|
|
90
|
+
if (results[i].err) {
|
|
91
|
+
err = results[i].err;
|
|
92
|
+
Common.printError(cst.PREFIX_MSG_MOD_ERR + chalk.bold.green(display + ' installation has FAILED (checkout previous logs)'));
|
|
93
|
+
} else {
|
|
94
|
+
Common.printOut(cst.PREFIX_MSG + chalk.bold.green(display + ' ENABLED'));
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if(cb) cb(err);
|
|
99
|
+
});
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
function installLangModule(module_name, cb) {
|
|
103
|
+
var node_module_path = path.resolve(path.join(__dirname, '../../../'));
|
|
104
|
+
Common.printOut(cst.PREFIX_MSG_MOD + 'Calling ' + chalk.bold.red('[NPM]') + ' to install ' + module_name + ' ...');
|
|
105
|
+
|
|
106
|
+
var install_instance = spawn(cst.IS_WINDOWS ? 'npm.cmd' : 'npm', ['install', module_name, '--loglevel=error'], {
|
|
107
|
+
stdio : 'inherit',
|
|
108
|
+
env: process.env,
|
|
109
|
+
cwd : node_module_path,
|
|
110
|
+
shell : cst.IS_WINDOWS
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
install_instance.on('close', function(code) {
|
|
114
|
+
if (code > 0)
|
|
115
|
+
return cb(new Error('Module install failed'));
|
|
116
|
+
return cb(null);
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
install_instance.on('error', function (err) {
|
|
120
|
+
console.error(err.stack || err);
|
|
121
|
+
});
|
|
122
|
+
};
|
|
@@ -0,0 +1,148 @@
|
|
|
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 path = require('path');
|
|
7
|
+
var eachLimit = require('async/eachLimit');
|
|
8
|
+
var forEachLimit = require('async/forEachLimit');
|
|
9
|
+
|
|
10
|
+
var Configuration = require('../../Configuration.js');
|
|
11
|
+
var cst = require('../../../constants.js');
|
|
12
|
+
var Common = require('../../Common');
|
|
13
|
+
var NPM = require('./NPM.js')
|
|
14
|
+
var TAR = require('./TAR.js')
|
|
15
|
+
var LOCAL = require('./LOCAL.js')
|
|
16
|
+
|
|
17
|
+
var Modularizer = module.exports = {};
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* PM2 Module System.
|
|
21
|
+
*/
|
|
22
|
+
Modularizer.install = function (CLI, module_name, opts, cb) {
|
|
23
|
+
module_name = module_name.replace(/[;`|]/g, "");
|
|
24
|
+
if (typeof(opts) == 'function') {
|
|
25
|
+
cb = opts;
|
|
26
|
+
opts = {};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (LOCAL.INTERNAL_MODULES.hasOwnProperty(module_name)) {
|
|
30
|
+
Common.logMod(`Adding dependency ${module_name} to PM2 Runtime`);
|
|
31
|
+
var currentModule = LOCAL.INTERNAL_MODULES[module_name];
|
|
32
|
+
if (currentModule && currentModule.hasOwnProperty('dependencies')) {
|
|
33
|
+
LOCAL.installMultipleModules(currentModule.dependencies, cb);
|
|
34
|
+
} else {
|
|
35
|
+
LOCAL.install(currentModule, cb);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
else if (module_name == '.') {
|
|
39
|
+
Common.logMod(`Installing local NPM module`);
|
|
40
|
+
return NPM.localStart(CLI, opts, cb)
|
|
41
|
+
}
|
|
42
|
+
else if (opts.tarball || /\.tar\.gz$/i.test(module_name)) {
|
|
43
|
+
Common.logMod(`Installing TAR module`);
|
|
44
|
+
TAR.install(CLI, module_name, opts, cb)
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
Common.logMod(`Installing NPM ${module_name} module`);
|
|
48
|
+
NPM.install(CLI, module_name, opts, cb)
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Launch All Modules
|
|
54
|
+
* Used PM2 at startup
|
|
55
|
+
*/
|
|
56
|
+
Modularizer.launchModules = function(CLI, cb) {
|
|
57
|
+
var modules = Modularizer.listModules();
|
|
58
|
+
|
|
59
|
+
if (!modules) return cb();
|
|
60
|
+
|
|
61
|
+
// 1#
|
|
62
|
+
function launchNPMModules(cb) {
|
|
63
|
+
if (!modules.npm_modules) return launchTARModules(cb)
|
|
64
|
+
|
|
65
|
+
eachLimit(Object.keys(modules.npm_modules), 1, function(module_name, next) {
|
|
66
|
+
NPM.start(CLI, modules, module_name, next)
|
|
67
|
+
}, function() {
|
|
68
|
+
launchTARModules(cb)
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// 2#
|
|
73
|
+
function launchTARModules(cb) {
|
|
74
|
+
if (!modules.tar_modules) return cb()
|
|
75
|
+
|
|
76
|
+
eachLimit(Object.keys(modules.tar_modules), 1, function(module_name, next) {
|
|
77
|
+
TAR.start(CLI, module_name, next)
|
|
78
|
+
}, function() {
|
|
79
|
+
return cb ? cb(null) : false;
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
launchNPMModules(cb)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
Modularizer.package = function(CLI, module_path, cb) {
|
|
87
|
+
var fullpath = process.cwd()
|
|
88
|
+
if (module_path)
|
|
89
|
+
fullpath = require('path').resolve(module_path)
|
|
90
|
+
TAR.packager(fullpath, process.cwd(), cb)
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Uninstall module
|
|
95
|
+
*/
|
|
96
|
+
Modularizer.uninstall = function(CLI, module_name, cb) {
|
|
97
|
+
Common.printOut(cst.PREFIX_MSG_MOD + 'Uninstalling module ' + module_name);
|
|
98
|
+
var modules_list = Modularizer.listModules();
|
|
99
|
+
|
|
100
|
+
if (module_name == 'all') {
|
|
101
|
+
if (!modules_list) return cb();
|
|
102
|
+
|
|
103
|
+
return forEachLimit(Object.keys(modules_list.npm_modules), 1, function(module_name, next) {
|
|
104
|
+
NPM.uninstall(CLI, module_name, next)
|
|
105
|
+
}, () => {
|
|
106
|
+
forEachLimit(Object.keys(modules_list.tar_modules), 1, function(module_name, next) {
|
|
107
|
+
TAR.uninstall(CLI, module_name, next)
|
|
108
|
+
}, cb)
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (modules_list.npm_modules[module_name]) {
|
|
113
|
+
NPM.uninstall(CLI, module_name, cb)
|
|
114
|
+
} else if (modules_list.tar_modules[module_name]) {
|
|
115
|
+
TAR.uninstall(CLI, module_name, cb)
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
Common.errMod('Unknown module')
|
|
119
|
+
CLI.exitCli(1)
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* List modules based on modules present in ~/.pm2/modules/ folder
|
|
125
|
+
*/
|
|
126
|
+
Modularizer.listModules = function() {
|
|
127
|
+
return {
|
|
128
|
+
npm_modules: Configuration.getSync(cst.MODULE_CONF_PREFIX) || {},
|
|
129
|
+
tar_modules: Configuration.getSync(cst.MODULE_CONF_PREFIX_TAR) || {}
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
Modularizer.getAdditionalConf = function(app_name) {
|
|
134
|
+
return NPM.getModuleConf(app_name)
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
Modularizer.publish = function(PM2, folder, opts, cb) {
|
|
138
|
+
if (opts.npm == true) {
|
|
139
|
+
NPM.publish(opts, cb)
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
TAR.publish(PM2, folder, cb)
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
Modularizer.generateSample = function(app_name, cb) {
|
|
147
|
+
NPM.generateSample(app_name, cb)
|
|
148
|
+
};
|