@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.
Files changed (267) hide show
  1. package/CHANGELOG.md +2607 -0
  2. package/CONTRIBUTING.md +124 -0
  3. package/GNU-AGPL-3.0.txt +665 -0
  4. package/LICENSE +1 -0
  5. package/README.md +255 -2
  6. package/SECURITY.md +41 -0
  7. package/bin/pm2 +3 -0
  8. package/bin/pm2-dev +3 -0
  9. package/bin/pm2-docker +3 -0
  10. package/bin/pm2-runtime +3 -0
  11. package/bin/pm2.ps1 +3 -0
  12. package/constants.js +113 -0
  13. package/index.js +12 -0
  14. package/lib/API/Configuration.js +212 -0
  15. package/lib/API/Containerizer.js +335 -0
  16. package/lib/API/Dashboard.js +726 -0
  17. package/lib/API/Deploy.js +117 -0
  18. package/lib/API/Extra.js +798 -0
  19. package/lib/API/ExtraMgmt/Docker.js +30 -0
  20. package/lib/API/Log.js +388 -0
  21. package/lib/API/LogManagement.js +351 -0
  22. package/lib/API/Modules/LOCAL.js +122 -0
  23. package/lib/API/Modules/Modularizer.js +148 -0
  24. package/lib/API/Modules/NPM.js +443 -0
  25. package/lib/API/Modules/TAR.js +368 -0
  26. package/lib/API/Modules/flagExt.js +46 -0
  27. package/lib/API/Modules/index.js +120 -0
  28. package/lib/API/Monit.js +247 -0
  29. package/lib/API/Serve.js +497 -0
  30. package/lib/API/Startup.js +630 -0
  31. package/lib/API/UX/helpers.js +213 -0
  32. package/lib/API/UX/index.js +9 -0
  33. package/lib/API/UX/pm2-describe.js +197 -0
  34. package/lib/API/UX/pm2-ls-minimal.js +31 -0
  35. package/lib/API/UX/pm2-ls.js +581 -0
  36. package/lib/API/Version.js +383 -0
  37. package/lib/API/interpreter.json +12 -0
  38. package/lib/API/pm2-plus/PM2IO.js +381 -0
  39. package/lib/API/pm2-plus/auth-strategies/CliAuth.js +306 -0
  40. package/lib/API/pm2-plus/auth-strategies/WebAuth.js +195 -0
  41. package/lib/API/pm2-plus/helpers.js +97 -0
  42. package/lib/API/pm2-plus/link.js +126 -0
  43. package/lib/API/pm2-plus/pres/motd +16 -0
  44. package/lib/API/pm2-plus/pres/motd.update +26 -0
  45. package/lib/API/pm2-plus/pres/welcome +28 -0
  46. package/lib/API/pm2-plus/process-selector.js +52 -0
  47. package/lib/API/schema.json +375 -0
  48. package/lib/API.js +1980 -0
  49. package/lib/Client.js +793 -0
  50. package/lib/Common.js +949 -0
  51. package/lib/Configuration.js +309 -0
  52. package/lib/Daemon.js +468 -0
  53. package/lib/Event.js +37 -0
  54. package/lib/God/ActionMethods.js +955 -0
  55. package/lib/God/ClusterMode.js +192 -0
  56. package/lib/God/ForkMode.js +205 -0
  57. package/lib/God/Methods.js +292 -0
  58. package/lib/God/Reload.js +300 -0
  59. package/lib/God/StdioLogger.js +239 -0
  60. package/lib/God.js +653 -0
  61. package/lib/HttpInterface.js +75 -0
  62. package/lib/OtelManager.js +74 -0
  63. package/lib/ProcessContainer.js +321 -0
  64. package/lib/ProcessContainerBun.js +355 -0
  65. package/lib/ProcessContainerFork.js +42 -0
  66. package/lib/ProcessContainerForkBun.js +31 -0
  67. package/lib/ProcessUtils.js +74 -0
  68. package/lib/TreeKill.js +111 -0
  69. package/lib/Utility.js +304 -0
  70. package/lib/VersionCheck.js +46 -0
  71. package/lib/Watcher.js +117 -0
  72. package/lib/Worker.js +200 -0
  73. package/lib/binaries/CLI.js +1092 -0
  74. package/lib/binaries/DevCLI.js +183 -0
  75. package/lib/binaries/Runtime.js +101 -0
  76. package/lib/binaries/Runtime4Docker.js +192 -0
  77. package/lib/completion.js +229 -0
  78. package/lib/completion.sh +40 -0
  79. package/lib/motd +36 -0
  80. package/lib/templates/Dockerfiles/Dockerfile-nodejs.tpl +8 -0
  81. package/lib/templates/ecosystem-es.tpl +24 -0
  82. package/lib/templates/ecosystem-simple-es.tpl +8 -0
  83. package/lib/templates/ecosystem-simple.tpl +6 -0
  84. package/lib/templates/ecosystem.tpl +22 -0
  85. package/lib/templates/init-scripts/launchd.tpl +35 -0
  86. package/lib/templates/init-scripts/openrc.tpl +52 -0
  87. package/lib/templates/init-scripts/pm2-init-amazon.sh +86 -0
  88. package/lib/templates/init-scripts/rcd-openbsd.tpl +41 -0
  89. package/lib/templates/init-scripts/rcd.tpl +44 -0
  90. package/lib/templates/init-scripts/smf.tpl +43 -0
  91. package/lib/templates/init-scripts/systemd-online.tpl +22 -0
  92. package/lib/templates/init-scripts/systemd.tpl +22 -0
  93. package/lib/templates/init-scripts/upstart.tpl +103 -0
  94. package/lib/templates/logrotate.d/pm2 +10 -0
  95. package/lib/templates/sample-apps/http-server/README.md +14 -0
  96. package/lib/templates/sample-apps/http-server/api.js +9 -0
  97. package/lib/templates/sample-apps/http-server/ecosystem.config.js +14 -0
  98. package/lib/templates/sample-apps/http-server/package.json +11 -0
  99. package/lib/templates/sample-apps/pm2-plus-metrics-actions/README.md +45 -0
  100. package/lib/templates/sample-apps/pm2-plus-metrics-actions/custom-metrics.js +66 -0
  101. package/lib/templates/sample-apps/pm2-plus-metrics-actions/ecosystem.config.js +12 -0
  102. package/lib/templates/sample-apps/pm2-plus-metrics-actions/package.json +11 -0
  103. package/lib/templates/sample-apps/python-app/README.md +4 -0
  104. package/lib/templates/sample-apps/python-app/echo.py +7 -0
  105. package/lib/templates/sample-apps/python-app/ecosystem.config.js +12 -0
  106. package/lib/templates/sample-apps/python-app/package.json +11 -0
  107. package/lib/tools/Config.js +251 -0
  108. package/lib/tools/SysMetrics.js +375 -0
  109. package/lib/tools/copydirSync.js +101 -0
  110. package/lib/tools/deleteFolderRecursive.js +19 -0
  111. package/lib/tools/find-package-json.js +74 -0
  112. package/lib/tools/fmt.js +72 -0
  113. package/lib/tools/interpreter.js +88 -0
  114. package/lib/tools/isbinaryfile.js +94 -0
  115. package/lib/tools/json5.js +752 -0
  116. package/lib/tools/multimeter/bar.js +111 -0
  117. package/lib/tools/multimeter/charm/encode.js +18 -0
  118. package/lib/tools/multimeter/charm/index.js +305 -0
  119. package/lib/tools/multimeter/index.js +76 -0
  120. package/lib/tools/open.js +56 -0
  121. package/lib/tools/passwd.js +58 -0
  122. package/lib/tools/pm2-config-keys.js +165 -0
  123. package/lib/tools/prompt.js +76 -0
  124. package/lib/tools/serviceStop.js +149 -0
  125. package/lib/tools/sexec.js +55 -0
  126. package/lib/tools/treeify.js +113 -0
  127. package/lib/tools/typestrip.js +55 -0
  128. package/lib/tools/which.js +120 -0
  129. package/lib/tools/xdg-open +861 -0
  130. package/modules/blessed/LICENSE +20 -0
  131. package/modules/blessed/README.md +34 -0
  132. package/modules/blessed/index.js +1 -0
  133. package/modules/blessed/lib/alias.js +526 -0
  134. package/modules/blessed/lib/blessed.js +32 -0
  135. package/modules/blessed/lib/colors.js +530 -0
  136. package/modules/blessed/lib/events.js +189 -0
  137. package/modules/blessed/lib/gpmclient.js +221 -0
  138. package/modules/blessed/lib/helpers.js +165 -0
  139. package/modules/blessed/lib/keys.js +339 -0
  140. package/modules/blessed/lib/program.js +4297 -0
  141. package/modules/blessed/lib/tput.js +3022 -0
  142. package/modules/blessed/lib/unicode.js +885 -0
  143. package/modules/blessed/lib/widget.js +32 -0
  144. package/modules/blessed/lib/widgets/box.js +34 -0
  145. package/modules/blessed/lib/widgets/element.js +2570 -0
  146. package/modules/blessed/lib/widgets/list.js +599 -0
  147. package/modules/blessed/lib/widgets/log.js +83 -0
  148. package/modules/blessed/lib/widgets/node.js +282 -0
  149. package/modules/blessed/lib/widgets/screen.js +2298 -0
  150. package/modules/blessed/lib/widgets/scrollablebox.js +389 -0
  151. package/modules/blessed/lib/widgets/scrollabletext.js +35 -0
  152. package/modules/blessed/lib/widgets/text.js +35 -0
  153. package/modules/blessed/usr/linux +0 -0
  154. package/modules/blessed/usr/windows-ansi +0 -0
  155. package/modules/blessed/usr/xterm +0 -0
  156. package/modules/blessed/usr/xterm-256color +0 -0
  157. package/modules/blessed/usr/xterm.termcap +243 -0
  158. package/modules/chokidar/LICENSE +21 -0
  159. package/modules/chokidar/VENDORED.md +76 -0
  160. package/modules/chokidar/index.js +979 -0
  161. package/modules/chokidar/lib/brace-expand.js +180 -0
  162. package/modules/chokidar/lib/constants.js +66 -0
  163. package/modules/chokidar/lib/fsevents-handler.js +526 -0
  164. package/modules/chokidar/lib/nodefs-handler.js +654 -0
  165. package/modules/fclone.js +49 -0
  166. package/modules/pm2-axon/index.js +2 -0
  167. package/modules/pm2-axon/lib/configurable/History.md +5 -0
  168. package/modules/pm2-axon/lib/configurable/Makefile +7 -0
  169. package/modules/pm2-axon/lib/configurable/Readme.md +57 -0
  170. package/modules/pm2-axon/lib/configurable/index.js +2 -0
  171. package/modules/pm2-axon/lib/configurable/lib/configurable.js +47 -0
  172. package/modules/pm2-axon/lib/configurable/package.json +68 -0
  173. package/modules/pm2-axon/lib/index.js +44 -0
  174. package/modules/pm2-axon/lib/plugins/queue.js +71 -0
  175. package/modules/pm2-axon/lib/plugins/round-robin.js +55 -0
  176. package/modules/pm2-axon/lib/sockets/pub-emitter.js +26 -0
  177. package/modules/pm2-axon/lib/sockets/pub.js +77 -0
  178. package/modules/pm2-axon/lib/sockets/pull.js +37 -0
  179. package/modules/pm2-axon/lib/sockets/push.js +32 -0
  180. package/modules/pm2-axon/lib/sockets/rep.js +73 -0
  181. package/modules/pm2-axon/lib/sockets/req.js +101 -0
  182. package/modules/pm2-axon/lib/sockets/sock.js +430 -0
  183. package/modules/pm2-axon/lib/sockets/sub-emitter.js +92 -0
  184. package/modules/pm2-axon/lib/sockets/sub.js +147 -0
  185. package/modules/pm2-axon/lib/utils.js +19 -0
  186. package/modules/pm2-axon-rpc/index.js +3 -0
  187. package/modules/pm2-axon-rpc/lib/client.js +63 -0
  188. package/modules/pm2-axon-rpc/lib/server.js +139 -0
  189. package/modules/pm2-io-agent/LICENSE +661 -0
  190. package/modules/pm2-io-agent/README.md +62 -0
  191. package/modules/pm2-io-agent/config.js +30 -0
  192. package/modules/pm2-io-agent/constants.js +118 -0
  193. package/modules/pm2-io-agent/index.js +2 -0
  194. package/modules/pm2-io-agent/src/InteractorClient.js +513 -0
  195. package/modules/pm2-io-agent/src/InteractorDaemon.js +455 -0
  196. package/modules/pm2-io-agent/src/PM2Client.js +112 -0
  197. package/modules/pm2-io-agent/src/PM2Interface.js +180 -0
  198. package/modules/pm2-io-agent/src/TransporterInterface.js +173 -0
  199. package/modules/pm2-io-agent/src/Utility.js +392 -0
  200. package/modules/pm2-io-agent/src/WatchDog.js +70 -0
  201. package/modules/pm2-io-agent/src/push/DataRetriever.js +77 -0
  202. package/modules/pm2-io-agent/src/push/PushInteractor.js +206 -0
  203. package/modules/pm2-io-agent/src/push/TransactionAggregator.js +670 -0
  204. package/modules/pm2-io-agent/src/reverse/ReverseInteractor.js +128 -0
  205. package/modules/pm2-io-agent/src/transporters/Transporter.js +129 -0
  206. package/modules/pm2-io-agent/src/transporters/WebsocketTransport.js +202 -0
  207. package/modules/pm2-io-agent/src/utils/BinaryHeap.js +135 -0
  208. package/modules/pm2-io-agent/src/utils/EDS.js +111 -0
  209. package/modules/pm2-io-agent/src/utils/probes/Histogram.js +204 -0
  210. package/modules/pm2-io-agent/src/utils/units.js +10 -0
  211. package/modules/pm2-io-bpm/configuration.js +141 -0
  212. package/modules/pm2-io-bpm/constants.js +10 -0
  213. package/modules/pm2-io-bpm/featureManager.js +110 -0
  214. package/modules/pm2-io-bpm/features/dependencies.js +48 -0
  215. package/modules/pm2-io-bpm/features/events.js +50 -0
  216. package/modules/pm2-io-bpm/features/metrics.js +102 -0
  217. package/modules/pm2-io-bpm/features/notify.js +238 -0
  218. package/modules/pm2-io-bpm/features/profiling.js +70 -0
  219. package/modules/pm2-io-bpm/features/tracing.js +174 -0
  220. package/modules/pm2-io-bpm/index.js +11 -0
  221. package/modules/pm2-io-bpm/metrics/eventLoopMetrics.js +136 -0
  222. package/modules/pm2-io-bpm/metrics/httpMetrics.js +175 -0
  223. package/modules/pm2-io-bpm/metrics/network.js +132 -0
  224. package/modules/pm2-io-bpm/metrics/runtime.js +161 -0
  225. package/modules/pm2-io-bpm/metrics/v8.js +104 -0
  226. package/modules/pm2-io-bpm/otel/constants.js +7 -0
  227. package/modules/pm2-io-bpm/otel/custom-zipkin-exporter/platform/index.js +17 -0
  228. package/modules/pm2-io-bpm/otel/custom-zipkin-exporter/platform/node/index.js +17 -0
  229. package/modules/pm2-io-bpm/otel/custom-zipkin-exporter/platform/node/util.js +51 -0
  230. package/modules/pm2-io-bpm/otel/custom-zipkin-exporter/transform.js +137 -0
  231. package/modules/pm2-io-bpm/otel/custom-zipkin-exporter/types.js +24 -0
  232. package/modules/pm2-io-bpm/otel/custom-zipkin-exporter/utils.js +23 -0
  233. package/modules/pm2-io-bpm/otel/custom-zipkin-exporter/zipkin.js +149 -0
  234. package/modules/pm2-io-bpm/pmx.js +380 -0
  235. package/modules/pm2-io-bpm/profilers/addonProfiler.js +193 -0
  236. package/modules/pm2-io-bpm/profilers/inspectorProfiler.js +302 -0
  237. package/modules/pm2-io-bpm/serviceManager.js +21 -0
  238. package/modules/pm2-io-bpm/services/actions.js +159 -0
  239. package/modules/pm2-io-bpm/services/inspector.js +43 -0
  240. package/modules/pm2-io-bpm/services/metrics.js +186 -0
  241. package/modules/pm2-io-bpm/services/runtimeStats.js +54 -0
  242. package/modules/pm2-io-bpm/services/transport.js +11 -0
  243. package/modules/pm2-io-bpm/transports/IPCTransport.js +115 -0
  244. package/modules/pm2-io-bpm/utils/BinaryHeap.js +134 -0
  245. package/modules/pm2-io-bpm/utils/EDS.js +113 -0
  246. package/modules/pm2-io-bpm/utils/EWMA.js +32 -0
  247. package/modules/pm2-io-bpm/utils/autocast.js +61 -0
  248. package/modules/pm2-io-bpm/utils/metrics/counter.js +33 -0
  249. package/modules/pm2-io-bpm/utils/metrics/gauge.js +23 -0
  250. package/modules/pm2-io-bpm/utils/metrics/histogram.js +192 -0
  251. package/modules/pm2-io-bpm/utils/metrics/meter.js +46 -0
  252. package/modules/pm2-io-bpm/utils/miscellaneous.js +19 -0
  253. package/modules/pm2-io-bpm/utils/module.js +67 -0
  254. package/modules/pm2-io-bpm/utils/shimmer.js +19 -0
  255. package/modules/pm2-io-bpm/utils/stackParser.js +160 -0
  256. package/modules/pm2-io-bpm/utils/transactionAggregator.js +429 -0
  257. package/modules/pm2-io-bpm/utils/units.js +16 -0
  258. package/modules/vizion/LICENSE +13 -0
  259. package/modules/vizion/README.md +133 -0
  260. package/modules/vizion/index.js +1 -0
  261. package/modules/vizion/lib/git/git.js +247 -0
  262. package/modules/vizion/lib/vizion.js +52 -0
  263. package/package.json +170 -4
  264. package/paths.js +121 -0
  265. package/pm2 +11 -0
  266. package/types/index.d.ts +732 -0
  267. package/types/tsconfig.json +14 -0
@@ -0,0 +1,1092 @@
1
+ 'use strict';
2
+
3
+ process.env.PM2_USAGE = 'CLI';
4
+
5
+ var cst = require('../../constants.js');
6
+
7
+ var commander = require('commander');
8
+ var chalk = require('ansis');
9
+ var forEachLimit = require('async/forEachLimit');
10
+
11
+ var debug = require('debug')('pm2:cli');
12
+ var PM2 = require('../API.js');
13
+ var pkg = require('../../package.json');
14
+ var tabtab = require('../completion.js');
15
+ var Common = require('../Common.js');
16
+ var PM2ioHandler = require('../API/pm2-plus/PM2IO');
17
+ var ServiceStop = require('../tools/serviceStop.js');
18
+
19
+ var semver = require('semver')
20
+
21
+ if (cst.IS_BUN === true && semver.lt(process.versions.bun, '1.1.25')) {
22
+ throw new Error('PM2 cannot run on Bun version < 1.1.25 (cluster support)')
23
+ }
24
+
25
+ Common.determineSilentCLI();
26
+ Common.printVersion();
27
+
28
+ var pm2 = new PM2();
29
+
30
+ PM2ioHandler.usePM2Client(pm2)
31
+
32
+ commander.version(pkg.version)
33
+ .option('-v --version', 'print pm2 version')
34
+ .option('-s --silent', 'hide all messages', false)
35
+ .option('--ext <extensions>', 'watch only this file extensions')
36
+ .option('-n --name <name>', 'set a name for the process in the process list')
37
+ .option('-m --mini-list', 'display a compacted list without formatting')
38
+ .option('--interpreter <interpreter>', 'set a specific interpreter to use for executing app, default: node')
39
+ .option('--interpreter-args <arguments>', 'set arguments to pass to the interpreter (alias of --node-args)')
40
+ .option('--node-args <node_args>', 'space delimited arguments to pass to node')
41
+ .option('-o --output <path>', 'specify log file for stdout')
42
+ .option('-e --error <path>', 'specify log file for stderr')
43
+ .option('-l --log [path]', 'specify log file which gathers both stdout and stderr')
44
+ .option('--filter-env [envs]', 'filter out outgoing global values that contain provided strings (alone: drop all but PATH, HOME...)', function(v, m) { return v === 'false' ? [] : (v === true || v === 'true' || m === true) ? true : (Array.isArray(m) ? m : []).concat(v); })
45
+ .option('--log-type <type>', 'specify log output style (raw by default, json optional)')
46
+ .option('--log-date-format <date format>', 'add custom prefix timestamp to logs')
47
+ .option('--time', 'enable time logging')
48
+ .option('--disable-logs', 'disable all logs storage')
49
+ .option('--env <environment_name>', 'specify which set of environment variables from ecosystem file must be injected')
50
+ .option('-a --update-env', 'force an update of the environment with restart/reload (-a <=> apply)')
51
+ .option('-f --force', 'force actions')
52
+ .option('-i --instances <number>', 'launch [number] instances (for networked app)(load balanced)')
53
+ .option('--parallel <number>', 'number of parallel actions (for restart/reload)')
54
+ .option('--shutdown-with-message', 'shutdown an application with process.send(\'shutdown\') instead of process.kill(pid, SIGINT)')
55
+ .option('-p --pid <pid>', 'specify pid file')
56
+ .option('-k --kill-timeout <delay>', 'delay before sending final SIGKILL signal to process')
57
+ .option('--listen-timeout <delay>', 'listen timeout on application reload')
58
+ .option('--max-memory-restart <memory>', 'Restart the app if an amount of memory is exceeded (in bytes)')
59
+ .option('--restart-delay <delay>', 'specify a delay between restarts (in milliseconds)')
60
+ .option('--exp-backoff-restart-delay <delay>', 'specify a delay between restarts (in milliseconds)')
61
+ .option('-x --execute-command', 'execute a program using fork system')
62
+ .option('--max-restarts [count]', 'only restart the script COUNT times')
63
+ .option('-u --user <username>', 'define user when generating startup script')
64
+ .option('--uid <uid>', 'run target script with <uid> rights')
65
+ .option('--gid <gid>', 'run target script with <gid> rights')
66
+ .option('--namespace <ns>', 'start application within specified namespace')
67
+ .option('--cwd <path>', 'run target script from path <cwd>')
68
+ .option('--hp <home path>', 'define home path when generating startup script')
69
+ .option('--wait-ip', 'override systemd script to wait for full internet connectivity to launch pm2')
70
+ .option('--service-name <name>', 'define service name when generating startup script')
71
+ .option('-c --cron <cron_pattern>', 'restart a running process based on a cron pattern')
72
+ .option('-c --cron-restart <cron_pattern>', '(alias) restart a running process based on a cron pattern')
73
+ .option('-w --write', 'write configuration in local folder')
74
+ .option('--no-daemon', 'run pm2 daemon in the foreground if it doesn\'t exist already')
75
+ .option('--source-map-support', 'force source map support')
76
+ .option('--only <application-name>', 'with json declaration, allow to only act on one application')
77
+ .option('--disable-source-map-support', 'disable source map support')
78
+ .option('--wait-ready', 'ask pm2 to wait for ready event from your app')
79
+ .option('--merge-logs', 'merge logs from different instances but keep error and out separated')
80
+ .option('--watch [paths]', 'watch application folder for changes', function(v, m) { m.push(v); return m;}, [])
81
+ .option('--ignore-watch <folders|files>', 'List of paths to ignore (name or regex)')
82
+ .option('--watch-delay <delay>', 'specify a restart delay after changing files (--watch-delay 4 (in sec) or 4000ms)')
83
+ .option('--no-color', 'skip colors')
84
+ .option('--no-vizion', 'start an app without vizion feature (versioning control)')
85
+ .option('--no-autostart', 'add an app without automatic start')
86
+ .option('--no-autorestart', 'start an app without automatic restart')
87
+ .option('--stop-exit-codes <exit_codes...>', 'specify a list of exit codes that should skip automatic restart')
88
+ .option('--no-treekill', 'Only kill the main process, not detached children')
89
+ .option('--no-pmx', 'start an app without pmx')
90
+ .option('--no-automation', 'start an app without pmx')
91
+ .option('--trace', 'enable transaction tracing with km')
92
+ .option('--disable-trace', 'disable transaction tracing with km')
93
+ .option('--sort <field_name:sort>', 'sort process according to field\'s name')
94
+ .option('--attach', 'attach logging after your start/restart/stop/reload')
95
+ .option('--v8', 'enable v8 data collecting')
96
+ .option('--event-loop-inspector', 'enable event-loop-inspector dump in pmx')
97
+ .option('--deep-monitoring', 'enable all monitoring tools (equivalent to --v8 --event-loop-inspector --trace)')
98
+ .usage('[cmd] app');
99
+
100
+ function displayUsage() {
101
+ console.log('usage: pm2 [options] <command>')
102
+ console.log('');
103
+ console.log('pm2 -h, --help all available commands and options');
104
+ console.log('pm2 examples display pm2 usage examples');
105
+ console.log('pm2 <command> -h help on a specific command');
106
+ console.log('');
107
+ console.log('Access pm2 files in ~/.pm2');
108
+ }
109
+
110
+ function displayExamples() {
111
+ console.log('- Start and add a process to the pm2 process list:')
112
+ console.log('');
113
+ console.log(chalk.cyan(' $ pm2 start app.js --name app'));
114
+ console.log('');
115
+ console.log('- Show the process list:');
116
+ console.log('');
117
+ console.log(chalk.cyan(' $ pm2 ls'));
118
+ console.log('');
119
+ console.log('- Stop and delete a process from the pm2 process list:');
120
+ console.log('');
121
+ console.log(chalk.cyan(' $ pm2 delete app'));
122
+ console.log('');
123
+ console.log('- Stop, start and restart a process from the process list:');
124
+ console.log('');
125
+ console.log(chalk.cyan(' $ pm2 stop app'));
126
+ console.log(chalk.cyan(' $ pm2 start app'));
127
+ console.log(chalk.cyan(' $ pm2 restart app'));
128
+ console.log('');
129
+ console.log('- Clusterize an app to all CPU cores available:');
130
+ console.log('');
131
+ console.log(chalk.cyan(' $ pm2 start -i max'));
132
+ console.log('');
133
+ console.log('- Update pm2 :');
134
+ console.log('');
135
+ console.log(chalk.cyan(' $ npm install pm2 -g && pm2 update'));
136
+ console.log('');
137
+ console.log('- Install pm2 auto completion:')
138
+ console.log('');
139
+ console.log(chalk.cyan(' $ pm2 completion install'))
140
+ console.log('');
141
+ console.log('Check the full documentation on https://pm2.keymetrics.io/');
142
+ console.log('');
143
+ }
144
+
145
+ function beginCommandProcessing() {
146
+ pm2.getVersion(function(err, remote_version) {
147
+ if (!err && (pkg.version != remote_version)) {
148
+ console.log('');
149
+ console.log(chalk.red.bold('>>>> In-memory PM2 is out-of-date, do:\n>>>> $ pm2 update'));
150
+ console.log('In memory PM2 version:', chalk.blue.bold(remote_version));
151
+ console.log('Local PM2 version:', chalk.blue.bold(pkg.version));
152
+ console.log('');
153
+ }
154
+ });
155
+ commander.parse(process.argv);
156
+ }
157
+
158
+ function checkCompletion(){
159
+ return tabtab.complete('pm2', function(err, data) {
160
+ if(err || !data) return;
161
+ if(/^--\w?/.test(data.last)) return tabtab.log(commander.options.map(function (data) {
162
+ return data.long;
163
+ }), data);
164
+ if(/^-\w?/.test(data.last)) return tabtab.log(commander.options.map(function (data) {
165
+ return data.short;
166
+ }), data);
167
+ // array containing commands after which process name should be listed
168
+ var cmdProcess = ['stop', 'restart', 'scale', 'reload', 'delete', 'reset', 'pull', 'forward', 'backward', 'logs', 'describe', 'desc', 'show'];
169
+
170
+ if (cmdProcess.indexOf(data.prev) > -1) {
171
+ pm2.list(function(err, list){
172
+ tabtab.log(list.map(function(el){ return el.name }), data);
173
+ pm2.disconnect();
174
+ });
175
+ }
176
+ else if (data.prev == 'pm2') {
177
+ tabtab.log(commander.commands.map(function (data) {
178
+ return data._name;
179
+ }), data);
180
+ pm2.disconnect();
181
+ }
182
+ else
183
+ pm2.disconnect();
184
+ });
185
+ };
186
+
187
+ var _arr = process.argv.indexOf('--') > -1 ? process.argv.slice(0, process.argv.indexOf('--')) : process.argv;
188
+
189
+ if (_arr.indexOf('log') > -1) {
190
+ process.argv[_arr.indexOf('log')] = 'logs';
191
+ }
192
+
193
+ // systemd stop command (ExecStop=pm2 kill) run after the daemon exited on its
194
+ // own, e.g. during `pm2 update`: do not touch or spawn another daemon (#5000)
195
+ var stop_ctx = ServiceStop.getStopContext(process.env, _arr.slice(2));
196
+
197
+ if (stop_ctx) {
198
+ ServiceStop.check(stop_ctx, cst.DAEMON_RPC_PORT, function(decision) {
199
+ console.log(cst.PREFIX_MSG + 'systemd stop command: ' + decision.reason);
200
+ if (decision.action === 'skip')
201
+ return process.exit(cst.SUCCESS_EXIT);
202
+ dispatch();
203
+ });
204
+ }
205
+ else
206
+ dispatch();
207
+
208
+ function dispatch() {
209
+ if (_arr.indexOf('--no-daemon') > -1) {
210
+ //
211
+ // Start daemon if it does not exist
212
+ //
213
+ // Function checks if --no-daemon option is present,
214
+ // and starts daemon in the same process if it does not exist
215
+ //
216
+ console.log('pm2 launched in no-daemon mode (you can add DEBUG="*" env variable to get more messages)');
217
+
218
+ var pm2NoDaeamon = new PM2({
219
+ daemon_mode : false
220
+ });
221
+
222
+ pm2NoDaeamon.connect(function() {
223
+ pm2 = pm2NoDaeamon;
224
+ beginCommandProcessing();
225
+ });
226
+
227
+ }
228
+ else if (_arr.indexOf('startup') > -1 || _arr.indexOf('unstartup') > -1) {
229
+ setTimeout(function() {
230
+ commander.parse(process.argv);
231
+ }, 100);
232
+ }
233
+ else {
234
+ // HERE we instanciate the Client object
235
+ pm2.connect(function() {
236
+ debug('Now connected to daemon');
237
+ if (process.argv.slice(2)[0] === 'completion') {
238
+ checkCompletion();
239
+ //Close client if completion related installation
240
+ var third = process.argv.slice(3)[0];
241
+ if ( third == null || third === 'install' || third === 'uninstall')
242
+ pm2.disconnect();
243
+ }
244
+ else {
245
+ beginCommandProcessing();
246
+ }
247
+ });
248
+ }
249
+ }
250
+
251
+ //
252
+ // Helper function to fail when unknown command arguments are passed
253
+ //
254
+ function failOnUnknown(fn) {
255
+ return function(arg) {
256
+ if (arguments.length > 1) {
257
+ console.log(cst.PREFIX_MSG + '\nUnknown command argument: ' + arg);
258
+ commander.outputHelp();
259
+ process.exit(cst.ERROR_EXIT);
260
+ }
261
+ return fn.apply(this, arguments);
262
+ };
263
+ }
264
+
265
+ /**
266
+ * @todo to remove at some point once it's fixed in official commander.js
267
+ * https://github.com/tj/commander.js/issues/475
268
+ *
269
+ * Patch Commander.js Variadic feature
270
+ */
271
+ function patchCommanderArg(cmd) {
272
+ var argsIndex;
273
+ if ((argsIndex = commander.rawArgs.indexOf('--')) >= 0) {
274
+ var optargs = commander.rawArgs.slice(argsIndex + 1);
275
+ cmd = cmd.slice(0, cmd.indexOf(optargs[0]));
276
+ }
277
+ return cmd;
278
+ }
279
+
280
+ //
281
+ // Start command
282
+ //
283
+ commander.command('start [name|namespace|file|ecosystem|id...]')
284
+ .option('--watch', 'Watch folder for changes')
285
+ .option('--fresh', 'Rebuild Dockerfile')
286
+ .option('--daemon', 'Run container in Daemon mode (debug purposes)')
287
+ .option('--container', 'Start application in container mode')
288
+ .option('--dist', 'with --container; change local Dockerfile to containerize all files in current directory')
289
+ .option('--image-name [name]', 'with --dist; set the exported image name')
290
+ .option('--node-version [major]', 'with --container, set a specific major Node.js version')
291
+ .option('--dockerdaemon', 'for debugging purpose')
292
+ .description('start and daemonize an app')
293
+ .action(function(cmd, opts) {
294
+ if (opts.container == true && opts.dist == true)
295
+ return pm2.dockerMode(cmd, opts, 'distribution');
296
+ else if (opts.container == true)
297
+ return pm2.dockerMode(cmd, opts, 'development');
298
+
299
+ if (cmd == "-") {
300
+ process.stdin.resume();
301
+ process.stdin.setEncoding('utf8');
302
+ process.stdin.on('data', function (cmd) {
303
+ process.stdin.pause();
304
+ pm2._startJson(cmd, commander, 'restartProcessId', 'pipe');
305
+ });
306
+ }
307
+ else {
308
+ // Commander.js patch
309
+ cmd = patchCommanderArg(cmd);
310
+ if (cmd.length === 0) {
311
+ cmd = [cst.APP_CONF_DEFAULT_FILE];
312
+ }
313
+ let acc = []
314
+ forEachLimit(cmd, 1, function(script, next) {
315
+ pm2.start(script, commander, (err, apps) => {
316
+ acc = acc.concat(apps)
317
+ next(err)
318
+ });
319
+ }, function(err, dt) {
320
+ if (err && err.message &&
321
+ (err.message.includes('Script not found') === true ||
322
+ err.message.includes('NOT AVAILABLE IN PATH') === true)) {
323
+ pm2.exitCli(1)
324
+ }
325
+ else
326
+ pm2.speedList(err ? 1 : 0, acc);
327
+ });
328
+ }
329
+ });
330
+
331
+ commander.command('trigger <id|proc_name|namespace|all> <action_name> [params]')
332
+ .description('trigger process action')
333
+ .action(function(pm_id, action_name, params) {
334
+ pm2.trigger(pm_id, action_name, params);
335
+ });
336
+
337
+ commander.command('deploy <file|environment>')
338
+ .description('deploy your json')
339
+ .action(function(cmd) {
340
+ pm2.deploy(cmd, commander);
341
+ });
342
+
343
+ commander.command('startOrRestart <json>')
344
+ .description('start or restart JSON file')
345
+ .action(function(file) {
346
+ pm2._startJson(file, commander, 'restartProcessId');
347
+ });
348
+
349
+ commander.command('startOrReload <json>')
350
+ .description('start or gracefully reload JSON file')
351
+ .action(function(file) {
352
+ pm2._startJson(file, commander, 'reloadProcessId');
353
+ });
354
+
355
+ commander.command('pid [app_name]')
356
+ .description('return pid of [app_name] or all')
357
+ .action(function(app) {
358
+ pm2.getPID(app);
359
+ });
360
+
361
+ commander.command('create')
362
+ .description('return pid of [app_name] or all')
363
+ .action(function() {
364
+ pm2.boilerplate()
365
+ });
366
+
367
+ commander.command('startOrGracefulReload <json>')
368
+ .description('start or gracefully reload JSON file')
369
+ .action(function(file) {
370
+ pm2._startJson(file, commander, 'reloadProcessId');
371
+ });
372
+
373
+ //
374
+ // Stop specific id
375
+ //
376
+ commander.command('stop <id|name|namespace|all|json|stdin...>')
377
+ .option('--watch', 'Stop watching folder for changes')
378
+ .description('stop a process')
379
+ .action(function(param) {
380
+ forEachLimit(param, 1, function(script, next) {
381
+ pm2.stop(script, next);
382
+ }, function(err) {
383
+ pm2.speedList(err ? 1 : 0);
384
+ });
385
+ });
386
+
387
+ //
388
+ // Stop All processes
389
+ //
390
+ commander.command('restart <id|name|namespace|all|json|stdin...>')
391
+ .option('--watch', 'Toggle watching folder for changes')
392
+ .description('restart a process')
393
+ .action(function(param) {
394
+ // Commander.js patch
395
+ param = patchCommanderArg(param);
396
+ let acc = []
397
+ forEachLimit(param, 1, function(script, next) {
398
+ pm2.restart(script, commander, (err, apps) => {
399
+ acc = acc.concat(apps)
400
+ next(err)
401
+ });
402
+ }, function(err) {
403
+ pm2.speedList(err ? 1 : 0, acc);
404
+ });
405
+ });
406
+
407
+ //
408
+ // Scale up/down a process in cluster mode
409
+ //
410
+ commander.command('scale <app_name> <number>')
411
+ .description('scale up/down a process in cluster mode depending on total_number param')
412
+ .action(function(app_name, number) {
413
+ pm2.scale(app_name, number);
414
+ });
415
+
416
+ //
417
+ // snapshot PM2
418
+ //
419
+ commander.command('profile:mem [time]')
420
+ .description('Sample PM2 heap memory')
421
+ .action(function(time) {
422
+ pm2.profile('mem', time);
423
+ });
424
+
425
+ //
426
+ // snapshot PM2
427
+ //
428
+ commander.command('profile:cpu [time]')
429
+ .description('Profile PM2 cpu')
430
+ .action(function(time) {
431
+ pm2.profile('cpu', time);
432
+ });
433
+
434
+ //
435
+ // Reload process(es)
436
+ //
437
+ commander.command('reload <id|name|namespace|all>')
438
+ .description('reload processes (note that its for app using HTTP/HTTPS)')
439
+ .action(function(pm2_id) {
440
+ pm2.reload(pm2_id, commander);
441
+ });
442
+
443
+ commander.command('id <name>')
444
+ .description('get process id by name')
445
+ .action(function(name) {
446
+ pm2.getProcessIdByName(name);
447
+ });
448
+
449
+ // Inspect a process
450
+ commander.command('inspect <name>')
451
+ .description('inspect a process')
452
+ .action(function(cmd) {
453
+ pm2.inspect(cmd, commander);
454
+ });
455
+
456
+ //
457
+ // Stop and delete a process by name from database
458
+ //
459
+ commander.command('delete <name|id|namespace|script|all|json|stdin...>')
460
+ .alias('del')
461
+ .description('stop and delete a process from pm2 process list')
462
+ .action(function(name) {
463
+ if (name == "-") {
464
+ process.stdin.resume();
465
+ process.stdin.setEncoding('utf8');
466
+ process.stdin.on('data', function (param) {
467
+ process.stdin.pause();
468
+ pm2.delete(param, 'pipe');
469
+ });
470
+ } else
471
+ forEachLimit(name, 1, function(script, next) {
472
+ pm2.delete(script,'', next);
473
+ }, function(err) {
474
+ pm2.speedList(err ? 1 : 0);
475
+ });
476
+ });
477
+
478
+ //
479
+ // Send system signal to process
480
+ //
481
+ commander.command('sendSignal <signal> <pm2_id|name>')
482
+ .description('send a system signal to the target process')
483
+ .action(function(signal, pm2_id) {
484
+ if (isNaN(parseInt(pm2_id))) {
485
+ console.log(cst.PREFIX_MSG + 'Sending signal to process name ' + pm2_id);
486
+ pm2.sendSignalToProcessName(signal, pm2_id);
487
+ } else {
488
+ console.log(cst.PREFIX_MSG + 'Sending signal to process id ' + pm2_id);
489
+ pm2.sendSignalToProcessId(signal, pm2_id);
490
+ }
491
+ });
492
+
493
+ //
494
+ // Stop and delete a process by name from database
495
+ //
496
+ commander.command('ping')
497
+ .description('ping pm2 daemon - if not up it will launch it')
498
+ .action(function() {
499
+ pm2.ping();
500
+ });
501
+
502
+ commander.command('updatePM2')
503
+ .description('update in-memory PM2 with local PM2')
504
+ .action(function() {
505
+ pm2.update();
506
+ });
507
+ commander.command('update')
508
+ .description('(alias) update in-memory PM2 with local PM2')
509
+ .action(function() {
510
+ pm2.update();
511
+ });
512
+
513
+ /**
514
+ * Module specifics
515
+ */
516
+ commander.command('install <module|git:// url>')
517
+ .alias('module:install')
518
+ .option('--tarball', 'is local tarball')
519
+ .option('--install', 'run yarn install before starting module')
520
+ .option('--docker', 'is docker container')
521
+ .option('--v1', 'install module in v1 manner (do not use it)')
522
+ .option('--safe [time]', 'keep module backup, if new module fail = restore with previous')
523
+ .description('install or update a module and run it forever')
524
+ .action(function(plugin_name, opts) {
525
+ Object.assign(commander, opts);
526
+ pm2.install(plugin_name, commander);
527
+ });
528
+
529
+ commander.command('module:update <module|git:// url>')
530
+ .option('--tarball', 'is local tarball')
531
+ .description('update a module and run it forever')
532
+ .action(function(plugin_name, opts) {
533
+ Object.assign(commander, opts);
534
+ pm2.install(plugin_name, commander);
535
+ });
536
+
537
+
538
+ commander.command('module:generate [app_name]')
539
+ .description('Generate a sample module in current folder')
540
+ .action(function(app_name) {
541
+ pm2.generateModuleSample(app_name);
542
+ });
543
+
544
+ commander.command('uninstall <module>')
545
+ .alias('module:uninstall')
546
+ .description('stop and uninstall a module')
547
+ .action(function(plugin_name) {
548
+ pm2.uninstall(plugin_name);
549
+ });
550
+
551
+ commander.command('package [target]')
552
+ .description('Check & Package TAR type module')
553
+ .action(function(target) {
554
+ pm2.package(target);
555
+ });
556
+
557
+ commander.command('publish [folder]')
558
+ .option('--npm', 'publish on npm')
559
+ .alias('module:publish')
560
+ .description('Publish the module you are currently on')
561
+ .action(function(folder, opts) {
562
+ pm2.publish(folder, opts);
563
+ });
564
+
565
+ commander.command('set [key] [value]')
566
+ .description('sets the specified config <key> <value>')
567
+ .action(function(key, value) {
568
+ pm2.set(key, value);
569
+ });
570
+
571
+ commander.command('multiset <value>')
572
+ .description('multiset eg "key1 val1 key2 val2')
573
+ .action(function(str) {
574
+ pm2.multiset(str);
575
+ });
576
+
577
+ commander.command('get [key]')
578
+ .description('get value for <key>')
579
+ .action(function(key) {
580
+ pm2.get(key);
581
+ });
582
+
583
+ commander.command('conf [key] [value]')
584
+ .description('get / set module config values')
585
+ .action(function(key, value) {
586
+ pm2.get()
587
+ });
588
+
589
+ commander.command('config <key> [value]')
590
+ .description('get / set module config values')
591
+ .action(function(key, value) {
592
+ pm2.conf(key, value);
593
+ });
594
+
595
+ commander.command('unset <key>')
596
+ .description('clears the specified config <key>')
597
+ .action(function(key) {
598
+ pm2.unset(key);
599
+ });
600
+
601
+ commander.command('report')
602
+ .description('give a full pm2 report for https://github.com/Unitech/pm2/issues')
603
+ .action(function(key) {
604
+ pm2.report();
605
+ });
606
+
607
+ //
608
+ // PM2 I/O
609
+ //
610
+ commander.command('link [secret] [public] [name]')
611
+ .option('--info-node [url]', 'set url info node')
612
+ .description('link with the pm2 monitoring dashboard')
613
+ .action(pm2.linkManagement.bind(pm2));
614
+
615
+ commander.command('unlink')
616
+ .description('unlink with the pm2 monitoring dashboard')
617
+ .action(function() {
618
+ pm2.unlink();
619
+ });
620
+
621
+ commander.command('monitor [name]')
622
+ .description('monitor target process')
623
+ .action(function(name) {
624
+ if (name === undefined) {
625
+ return plusHandler()
626
+ }
627
+ pm2.monitorState('monitor', name);
628
+ });
629
+
630
+ commander.command('unmonitor [name]')
631
+ .description('unmonitor target process')
632
+ .action(function(name) {
633
+ pm2.monitorState('unmonitor', name);
634
+ });
635
+
636
+ commander.command('open')
637
+ .description('open the pm2 monitoring dashboard')
638
+ .action(function(name) {
639
+ pm2.openDashboard();
640
+ });
641
+
642
+ function plusHandler (command, opts) {
643
+ if (opts && opts.infoNode) {
644
+ process.env.KEYMETRICS_NODE = opts.infoNode
645
+ }
646
+
647
+ return PM2ioHandler.launch(command, opts)
648
+ }
649
+
650
+ commander.command('plus [command] [option]')
651
+ .alias('register')
652
+ .option('--info-node [url]', 'set url info node for on-premise pm2 plus')
653
+ .option('-d --discrete', 'silent mode')
654
+ .option('-a --install-all', 'install all modules (force yes)')
655
+ .description('enable pm2 plus')
656
+ .action(plusHandler);
657
+
658
+ commander.command('login')
659
+ .description('Login to pm2 plus')
660
+ .action(function() {
661
+ return plusHandler('login')
662
+ });
663
+
664
+ commander.command('logout')
665
+ .description('Logout from pm2 plus')
666
+ .action(function() {
667
+ return plusHandler('logout')
668
+ });
669
+
670
+ //
671
+ // Save processes to file
672
+ //
673
+ commander.command('dump')
674
+ .alias('save')
675
+ .option('--force', 'force deletion of dump file, even if empty')
676
+ .description('dump all processes for resurrecting them later')
677
+ .action(failOnUnknown(function(opts) {
678
+ pm2.dump(commander.force)
679
+ }));
680
+
681
+ //
682
+ // Delete dump file
683
+ //
684
+ commander.command('cleardump')
685
+ .description('Create empty dump file')
686
+ .action(failOnUnknown(function() {
687
+ pm2.clearDump();
688
+ }));
689
+
690
+ //
691
+ // Save processes to file
692
+ //
693
+ commander.command('send <pm_id> <line>')
694
+ .description('send stdin to <pm_id>')
695
+ .action(function(pm_id, line) {
696
+ pm2.sendLineToStdin(pm_id, line);
697
+ });
698
+
699
+ //
700
+ // Attach to stdin/stdout
701
+ // Not TTY ready
702
+ //
703
+ commander.command('attach <pm_id> [command separator]')
704
+ .description('attach stdin/stdout to application identified by <pm_id>')
705
+ .action(function(pm_id, separator) {
706
+ pm2.attach(pm_id, separator);
707
+ });
708
+
709
+ //
710
+ // Resurrect
711
+ //
712
+ commander.command('resurrect')
713
+ .description('resurrect previously dumped processes')
714
+ .action(failOnUnknown(function() {
715
+ console.log(cst.PREFIX_MSG + 'Resurrecting');
716
+ pm2.resurrect();
717
+ }));
718
+
719
+ //
720
+ // Set pm2 to startup
721
+ //
722
+ commander.command('unstartup [platform]')
723
+ .description('disable the pm2 startup hook')
724
+ .action(function(platform) {
725
+ pm2.uninstallStartup(platform, commander);
726
+ });
727
+
728
+ //
729
+ // Set pm2 to startup
730
+ //
731
+ commander.command('startup [platform]')
732
+ .description('enable the pm2 startup hook')
733
+ .action(function(platform) {
734
+ pm2.startup(platform, commander);
735
+ });
736
+
737
+ //
738
+ // Logrotate
739
+ //
740
+ commander.command('logrotate')
741
+ .description('copy default logrotate configuration')
742
+ .action(function(cmd) {
743
+ pm2.logrotate(commander);
744
+ });
745
+
746
+ //
747
+ // Sample generate
748
+ //
749
+
750
+ commander.command('ecosystem [mode]')
751
+ .alias('init')
752
+ .description('generate a process conf file. (mode = null or simple)')
753
+ .action(function(mode) {
754
+ pm2.generateSample(mode);
755
+ });
756
+
757
+ commander.command('reset <name|id|all>')
758
+ .description('reset counters for process')
759
+ .action(function(proc_id) {
760
+ pm2.reset(proc_id);
761
+ });
762
+
763
+ commander.command('describe <name|id>')
764
+ .description('describe all parameters of a process')
765
+ .action(function(proc_id) {
766
+ pm2.describe(proc_id);
767
+ });
768
+
769
+ commander.command('desc <name|id>')
770
+ .description('(alias) describe all parameters of a process')
771
+ .action(function(proc_id) {
772
+ pm2.describe(proc_id);
773
+ });
774
+
775
+ commander.command('info <name|id>')
776
+ .description('(alias) describe all parameters of a process')
777
+ .action(function(proc_id) {
778
+ pm2.describe(proc_id);
779
+ });
780
+
781
+ commander.command('show <name|id>')
782
+ .description('(alias) describe all parameters of a process')
783
+ .action(function(proc_id) {
784
+ pm2.describe(proc_id);
785
+ });
786
+
787
+ commander.command('env <id>')
788
+ .description('list all environment variables of a process id')
789
+ .action(function(proc_id) {
790
+ pm2.env(proc_id);
791
+ });
792
+
793
+ //
794
+ // List command
795
+ //
796
+ commander
797
+ .command('list')
798
+ .alias('ls')
799
+ .description('list all processes')
800
+ .action(function() {
801
+ pm2.list(commander)
802
+ });
803
+
804
+ commander.command('l')
805
+ .description('(alias) list all processes')
806
+ .action(function() {
807
+ pm2.list()
808
+ });
809
+
810
+ commander.command('ps')
811
+ .description('(alias) list all processes')
812
+ .action(function() {
813
+ pm2.list()
814
+ });
815
+
816
+ commander.command('status')
817
+ .description('(alias) list all processes')
818
+ .action(function() {
819
+ pm2.list()
820
+ });
821
+
822
+
823
+ // List in raw json
824
+ commander.command('jlist')
825
+ .description('list all processes in JSON format')
826
+ .action(function() {
827
+ pm2.jlist()
828
+ });
829
+
830
+ commander.command('slist')
831
+ .alias('sysinfos')
832
+ .option('-t --tree', 'show as tree')
833
+ .description('list system infos in JSON')
834
+ .action(function(opts) {
835
+ pm2.slist(opts.tree)
836
+ })
837
+
838
+ // List in prettified Json
839
+ commander.command('prettylist')
840
+ .description('print json in a prettified JSON')
841
+ .action(failOnUnknown(function() {
842
+ pm2.jlist(true);
843
+ }));
844
+
845
+ //
846
+ // Dashboard command
847
+ //
848
+ commander.command('monit')
849
+ .option('--lines <n>', 'number of log lines to display per process (default: 200)')
850
+ .description('launch termcaps monitoring')
851
+ .action(function(cmd) {
852
+ pm2.dashboard({ lines: cmd.lines });
853
+ });
854
+
855
+ commander.command('imonit')
856
+ .description('launch legacy termcaps monitoring')
857
+ .action(function() {
858
+ pm2.monit();
859
+ });
860
+
861
+ commander.command('dashboard')
862
+ .alias('dash')
863
+ .option('--lines <n>', 'number of log lines to display per process (default: 200)')
864
+ .description('launch dashboard with monitoring and logs')
865
+ .action(function(cmd) {
866
+ pm2.dashboard({ lines: cmd.lines });
867
+ });
868
+
869
+
870
+ //
871
+ // Flushing command
872
+ //
873
+
874
+ commander.command('flush [api]')
875
+ .description('flush logs')
876
+ .action(function(api) {
877
+ pm2.flush(api);
878
+ });
879
+
880
+ /* old version
881
+ commander.command('flush')
882
+ .description('flush logs')
883
+ .action(failOnUnknown(function() {
884
+ pm2.flush();
885
+ }));
886
+ */
887
+ //
888
+ // Reload all logs
889
+ //
890
+ commander.command('reloadLogs')
891
+ .description('reload all logs')
892
+ .action(function() {
893
+ pm2.reloadLogs();
894
+ });
895
+
896
+ //
897
+ // Log streaming
898
+ //
899
+ commander.command('logs [id|name|namespace]')
900
+ .option('--json', 'json log output')
901
+ .option('--format', 'formatted log output')
902
+ .option('--raw', 'raw output')
903
+ .option('--err', 'only shows error output')
904
+ .option('--out', 'only shows standard output')
905
+ .option('--lines <n>', 'output the last N lines, instead of the last 15 by default')
906
+ .option('--timestamp [format]', 'add timestamps (default format YYYY-MM-DD-HH:mm:ss)')
907
+ .option('--nostream', 'print logs without launching the log stream')
908
+ .option('--highlight [value]', 'highlights the given value')
909
+ .description('stream logs file. Default stream all logs')
910
+ .action(function(id, cmd) {
911
+ var Logs = require('../API/Log.js');
912
+
913
+ if (!id) id = 'all';
914
+
915
+ var line = 15;
916
+ var raw = false;
917
+ var exclusive = false;
918
+ var timestamp = false;
919
+ var highlight = false;
920
+
921
+ if(!isNaN(parseInt(cmd.lines))) {
922
+ line = parseInt(cmd.lines);
923
+ }
924
+
925
+ if (cmd.parent.rawArgs.indexOf('--raw') !== -1)
926
+ raw = true;
927
+
928
+ if (cmd.timestamp)
929
+ timestamp = typeof cmd.timestamp === 'string' ? cmd.timestamp : 'YYYY-MM-DD-HH:mm:ss';
930
+
931
+ if (cmd.highlight)
932
+ highlight = typeof cmd.highlight === 'string' ? cmd.highlight : false;
933
+
934
+ if (cmd.out === true)
935
+ exclusive = 'out';
936
+
937
+ if (cmd.err === true)
938
+ exclusive = 'err';
939
+
940
+ if (cmd.nostream === true)
941
+ pm2.printLogs(id, line, raw, timestamp, exclusive);
942
+ else if (cmd.json === true)
943
+ Logs.jsonStream(pm2.Client, id);
944
+ else if (cmd.format === true)
945
+ Logs.formatStream(pm2.Client, id, false, 'YYYY-MM-DD-HH:mm:ssZZ', exclusive, highlight);
946
+ else
947
+ pm2.streamLogs(id, line, raw, timestamp, exclusive, highlight);
948
+ });
949
+
950
+
951
+ //
952
+ // Kill
953
+ //
954
+ commander.command('kill')
955
+ .description('kill daemon')
956
+ .action(failOnUnknown(function(arg) {
957
+ pm2.killDaemon(function() {
958
+ process.exit(cst.SUCCESS_EXIT);
959
+ });
960
+ }));
961
+
962
+ //
963
+ // Update repository for a given app
964
+ //
965
+
966
+ commander.command('pull <name> [commit_id]')
967
+ .description('updates repository for a given app')
968
+ .action(function(pm2_name, commit_id) {
969
+
970
+ if (commit_id !== undefined) {
971
+ pm2._pullCommitId({
972
+ pm2_name: pm2_name,
973
+ commit_id: commit_id
974
+ });
975
+ }
976
+ else
977
+ pm2.pullAndRestart(pm2_name);
978
+ });
979
+
980
+ //
981
+ // Update repository to the next commit for a given app
982
+ //
983
+ commander.command('forward <name>')
984
+ .description('updates repository to the next commit for a given app')
985
+ .action(function(pm2_name) {
986
+ pm2.forward(pm2_name);
987
+ });
988
+
989
+ //
990
+ // Downgrade repository to the previous commit for a given app
991
+ //
992
+ commander.command('backward <name>')
993
+ .description('downgrades repository to the previous commit for a given app')
994
+ .action(function(pm2_name) {
995
+ pm2.backward(pm2_name);
996
+ });
997
+
998
+ //
999
+ // Perform a deep update of PM2
1000
+ //
1001
+ commander.command('deepUpdate')
1002
+ .description('performs a deep update of PM2')
1003
+ .action(function() {
1004
+ pm2.deepUpdate();
1005
+ });
1006
+
1007
+ //
1008
+ // Launch a http server that expose a given path on given port
1009
+ //
1010
+ commander.command('serve [path] [port]')
1011
+ .alias('expose')
1012
+ .option('--port [port]', 'specify port to listen to')
1013
+ .option('--spa', 'always serving index.html on inexistant sub path')
1014
+ .option('--ftp', 'directory listing like python http.server')
1015
+ .option('--basic-auth-username [username]', 'set basic auth username')
1016
+ .option('--basic-auth-password [password]', 'set basic auth password')
1017
+ .option('--monitor [frontend-app]', 'frontend app monitoring (auto integrate snippet on html files)')
1018
+ .description('serve a directory over http via port')
1019
+ .action(function (path, port, cmd) {
1020
+ pm2.serve(path, port || cmd.port, cmd, commander);
1021
+ });
1022
+
1023
+ commander.command('autoinstall')
1024
+ .action(function() {
1025
+ pm2.autoinstall()
1026
+ })
1027
+
1028
+ commander.command('examples')
1029
+ .description('display pm2 usage examples')
1030
+ .action(() => {
1031
+ console.log(cst.PREFIX_MSG + chalk.gray('pm2 usage examples:\n'));
1032
+ displayExamples();
1033
+ process.exit(cst.SUCCESS_EXIT);
1034
+ })
1035
+
1036
+ //
1037
+ // OpenTelemetry tracing packages management
1038
+ //
1039
+ commander.command('install-otel')
1040
+ .description('install OpenTelemetry tracing packages (required for --trace)')
1041
+ .action(function() {
1042
+ var OtelManager = require('../OtelManager');
1043
+ try {
1044
+ if (OtelManager.isInstalled()) {
1045
+ Common.printOut(cst.PREFIX_MSG + 'OpenTelemetry packages are already installed');
1046
+ } else {
1047
+ OtelManager.install();
1048
+ }
1049
+ } catch(e) {
1050
+ Common.printError(cst.PREFIX_MSG_ERR + 'Failed to install OpenTelemetry packages: ' + e.message);
1051
+ process.exit(cst.ERROR_EXIT);
1052
+ }
1053
+ process.exit(cst.SUCCESS_EXIT);
1054
+ });
1055
+
1056
+ commander.command('uninstall-otel')
1057
+ .description('remove OpenTelemetry tracing packages')
1058
+ .action(function() {
1059
+ var OtelManager = require('../OtelManager');
1060
+ try {
1061
+ if (!OtelManager.isInstalled()) {
1062
+ Common.printOut(cst.PREFIX_MSG + 'OpenTelemetry packages are not installed');
1063
+ } else {
1064
+ OtelManager.uninstall();
1065
+ }
1066
+ } catch(e) {
1067
+ Common.printError(cst.PREFIX_MSG_ERR + 'Failed to remove OpenTelemetry packages: ' + e.message);
1068
+ process.exit(cst.ERROR_EXIT);
1069
+ }
1070
+ process.exit(cst.SUCCESS_EXIT);
1071
+ });
1072
+
1073
+ //
1074
+ // Catch all
1075
+ //
1076
+ commander.command('*')
1077
+ .action(function() {
1078
+ console.log(cst.PREFIX_MSG_ERR + chalk.bold('Command not found\n'));
1079
+ displayUsage();
1080
+ // Check if it does not forget to close fds from RPC
1081
+ process.exit(cst.ERROR_EXIT);
1082
+ });
1083
+
1084
+ //
1085
+ // Display help if 0 arguments passed to pm2
1086
+ //
1087
+ if (process.argv.length == 2) {
1088
+ commander.parse(process.argv);
1089
+ displayUsage();
1090
+ // Check if it does not forget to close fds from RPC
1091
+ process.exit(cst.ERROR_EXIT);
1092
+ }