@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,165 @@
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
+ /**
8
+ * Classification of pm2_env keys, shared by the CLI (lib/Common.js) and the
9
+ * daemon (lib/Utility.js) so the list lives in exactly one place.
10
+ *
11
+ * pm2_env is flat: an app's environment variables are merged into the same
12
+ * object that holds PM2's own configuration. Two different questions follow
13
+ * from that, and they need two different answers:
14
+ *
15
+ * - what may the *ambient shell* contribute to an app config? Nothing PM2
16
+ * owns: a stray `name=` or `port=` variable in the environment must not
17
+ * silently become app configuration.
18
+ * - what may the *user* contribute through `env:`? Anything except the
19
+ * daemon's own bookkeeping. `env: { port: 3000 }` is a deliberate,
20
+ * documented thing to write and the app has to receive it.
21
+ *
22
+ * and `filter_env` decides what of the shell (or daemon) env an app inherits.
23
+ */
24
+
25
+ var schema = require('../API/schema.json');
26
+
27
+ /**
28
+ * State the daemon maintains on each process. Never user-supplied.
29
+ */
30
+ var INTERNAL_KEYS = [
31
+ 'pm_id', 'status', 'pm_uptime', 'created_at', 'restart_time', 'unstable_restarts',
32
+ 'exit_code', 'versioning', 'version', 'vizion_running', 'km_link',
33
+ '_pm2_version', 'prev_restart_delay', 'pmx_module', 'command', 'pm2_env',
34
+ 'windowsHide', 'MODULE_DEBUG', '_tree_pids'
35
+ ];
36
+
37
+ /**
38
+ * Identity and topology: God.clusters_db is keyed and searched on these, so
39
+ * an env var overwriting one detaches the process from its own registry entry.
40
+ */
41
+ var IDENTITY_KEYS = [
42
+ 'name', 'namespace', 'exec_mode', 'instances'
43
+ ];
44
+
45
+ /**
46
+ * Everything PM2 owns: the ecosystem schema plus daemon state.
47
+ * `io` is excluded on purpose -- API.js copies it into env as a JSON string
48
+ * for the child to read back.
49
+ */
50
+ var CONFIG_KEYS = new Set(Object.keys(schema)
51
+ .filter(function(k) { return k[0] !== '^' && k !== 'io' })
52
+ .concat(INTERNAL_KEYS));
53
+
54
+ var OWNED_KEYS = new Set(INTERNAL_KEYS.concat(IDENTITY_KEYS));
55
+
56
+ /**
57
+ * `pm_*` and `axm_*` are reserved prefixes in both directions.
58
+ */
59
+ function isReserved(key) {
60
+ return /^(pm_|axm_)/.test(key);
61
+ }
62
+
63
+ /**
64
+ * What an app keeps with `filter_env: true`: without the OS variables it, and
65
+ * what it spawns (npm, shebang scripts, git...), finds no binary nor home.
66
+ * PM2_HOME keeps the pm2 calls made from the app on this daemon. Locales are
67
+ * listed one by one: ssh forwards LC_* (SendEnv), a known way to pass tokens
68
+ * (#6176)
69
+ */
70
+ var BASE_ENV_KEYS = new Set([
71
+ 'PATH', 'HOME', 'USER', 'LOGNAME', 'SHELL', 'TZ', 'TMPDIR', 'PM2_HOME', 'LANG', 'LANGUAGE',
72
+ 'LC_ALL', 'LC_CTYPE', 'LC_COLLATE', 'LC_MESSAGES', 'LC_MONETARY', 'LC_NUMERIC', 'LC_TIME',
73
+ 'LC_ADDRESS', 'LC_IDENTIFICATION', 'LC_MEASUREMENT', 'LC_NAME', 'LC_PAPER', 'LC_TELEPHONE'
74
+ ]);
75
+
76
+ // case-insensitive, as Windows env names are (Path, SystemRoot)
77
+ var WINDOWS_BASE_ENV_KEYS = new Set([
78
+ 'PATH', 'SYSTEMROOT', 'SYSTEMDRIVE', 'WINDIR', 'COMSPEC', 'PATHEXT', 'TEMP', 'TMP',
79
+ 'USERPROFILE', 'USERNAME', 'USERDOMAIN', 'HOMEDRIVE', 'HOMEPATH', 'APPDATA', 'LOCALAPPDATA',
80
+ 'ALLUSERSPROFILE', 'PUBLIC', 'PROGRAMDATA', 'PROGRAMFILES', 'PROGRAMFILES(X86)', 'PROGRAMW6432',
81
+ 'COMMONPROGRAMFILES', 'COMMONPROGRAMFILES(X86)', 'COMMONPROGRAMW6432', 'COMPUTERNAME',
82
+ 'NUMBER_OF_PROCESSORS', 'PROCESSOR_ARCHITECTURE', 'PROCESSOR_IDENTIFIER', 'PROCESSOR_LEVEL',
83
+ 'PROCESSOR_REVISION', 'OS', 'TZ', 'PM2_HOME'
84
+ ]);
85
+
86
+ function isBaseEnvKey(key, platform) {
87
+ if (platform === 'win32')
88
+ return WINDOWS_BASE_ENV_KEYS.has(key.toUpperCase());
89
+ return BASE_ENV_KEYS.has(key);
90
+ }
91
+
92
+ module.exports = {
93
+ /**
94
+ * Keys PM2 owns. Use to strip the *shell* environment before merging it into
95
+ * an app config -- nothing named like a PM2 option should be picked up from
96
+ * the ambient environment.
97
+ * #6006 #6016 #5747 #5622 #5030 #5032 #4943 #4778 #4821 #3210
98
+ */
99
+ isPm2ConfigKey : function(key) {
100
+ return CONFIG_KEYS.has(key) || isReserved(key);
101
+ },
102
+
103
+ /**
104
+ * Keys PM2 owns whatever their origin. Use when flattening pm2_env.env into
105
+ * pm2_env: a user may declare `env: { port: 3000 }` and the app must see it,
106
+ * but nothing may overwrite the daemon's own bookkeeping.
107
+ */
108
+ isPm2InternalKey : function(key) {
109
+ return OWNED_KEYS.has(key) || isReserved(key);
110
+ },
111
+
112
+ /**
113
+ * Copy `source` without the keys PM2 owns.
114
+ */
115
+ omitPm2ConfigKeys : function(source) {
116
+ if (!source || typeof source != 'object') return {};
117
+
118
+ var out = {};
119
+ Object.keys(source).forEach(function(key) {
120
+ if (CONFIG_KEYS.has(key) || isReserved(key)) return;
121
+ if (source[key] != '[object Object]')
122
+ out[key] = source[key];
123
+ });
124
+ return out;
125
+ },
126
+
127
+ /**
128
+ * Shell (or daemon) environment an app inherits, per its `filter_env`.
129
+ * Never mutates `env`. Shared by the start, restart/reload --update-env and
130
+ * the cluster fork, so every path filters the same way (#6176)
131
+ *
132
+ * true, 'true' -> only the variables above
133
+ * 'KEY' -> KEY is dropped
134
+ * ['A', 'B'] -> every key containing A or B is dropped
135
+ * false, 'false', [], unset -> everything is inherited
136
+ *
137
+ * `platform` defaults to the current one (tests)
138
+ */
139
+ filterShellEnv : function(env, filter_env, platform) {
140
+ var drop;
141
+
142
+ platform = platform || process.platform;
143
+
144
+ if (filter_env === 'false')
145
+ return env;
146
+
147
+ // 'true': same flag, as a string from a config file or an old dump
148
+ if (filter_env === true || filter_env === 'true')
149
+ drop = function(key) { return !isBaseEnvKey(key, platform); };
150
+ else if (typeof filter_env === 'string' && filter_env.length > 0)
151
+ drop = function(key) { return key === filter_env; };
152
+ else if (Array.isArray(filter_env) && filter_env.length > 0)
153
+ drop = function(key) {
154
+ return filter_env.some(function(pattern) { return key.includes(pattern); });
155
+ };
156
+ else
157
+ return env;
158
+
159
+ var kept = {};
160
+ Object.keys(env).forEach(function(key) {
161
+ if (!drop(key)) kept[key] = env[key];
162
+ });
163
+ return kept;
164
+ }
165
+ };
@@ -0,0 +1,76 @@
1
+ var readline = require('readline');
2
+
3
+ function prompt(message, opts, cb) {
4
+ if (typeof opts === 'function') { cb = opts; opts = {}; }
5
+ var rl = readline.createInterface({ input: process.stdin, output: process.stdout });
6
+ rl.question(message, function(answer) {
7
+ rl.close();
8
+ if (opts.validator) {
9
+ try {
10
+ answer = opts.validator(answer);
11
+ } catch(e) {
12
+ if (opts.retry) {
13
+ console.error(e.message || e);
14
+ return prompt(message, opts, cb);
15
+ }
16
+ return cb(e);
17
+ }
18
+ }
19
+ cb(null, answer);
20
+ });
21
+ }
22
+
23
+ function password(message, opts, cb) {
24
+ var input = '';
25
+ var replace = (opts && opts.replace) || '*';
26
+
27
+ process.stdout.write(message);
28
+ process.stdin.setRawMode(true);
29
+ process.stdin.resume();
30
+ process.stdin.setEncoding('utf8');
31
+
32
+ var onData = function(ch) {
33
+ if (ch === '\r' || ch === '\n') {
34
+ process.stdin.setRawMode(false);
35
+ process.stdin.pause();
36
+ process.stdin.removeListener('data', onData);
37
+ process.stdout.write('\n');
38
+ cb(null, input);
39
+ } else if (ch === '\u0003') {
40
+ process.exit();
41
+ } else if (ch === '\u007f' || ch === '\b') {
42
+ if (input.length > 0) {
43
+ input = input.slice(0, -1);
44
+ process.stdout.write('\b \b');
45
+ }
46
+ } else {
47
+ input += ch;
48
+ process.stdout.write(replace);
49
+ }
50
+ };
51
+ process.stdin.on('data', onData);
52
+ }
53
+
54
+ function confirm(message, cb) {
55
+ prompt(message + ' ', function(err, answer) {
56
+ if (err) return cb(err);
57
+ cb(null, /^y(es)?$/i.test(answer.trim()));
58
+ });
59
+ }
60
+
61
+ function choose(message, choices, cb) {
62
+ console.log(choices.map(function(c, i) { return ' ' + (i + 1) + ') ' + c; }).join('\n'));
63
+ prompt(message, function(err, answer) {
64
+ if (err) return cb(err);
65
+ answer = answer.trim();
66
+ var idx = parseInt(answer, 10);
67
+ if (idx >= 1 && idx <= choices.length) return cb(null, choices[idx - 1]);
68
+ if (choices.indexOf(answer) !== -1) return cb(null, answer);
69
+ return choose(message, choices, cb);
70
+ });
71
+ }
72
+
73
+ exports.prompt = prompt;
74
+ exports.password = password;
75
+ exports.confirm = confirm;
76
+ exports.choose = choose;
@@ -0,0 +1,149 @@
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
+ 'use strict';
7
+
8
+ /**
9
+ * Guard for `pm2 kill` run as a systemd stop command (ExecStop=pm2 kill
10
+ * from `pm2 startup`).
11
+ *
12
+ * systemd runs the stop commands even when the main process exited on its own.
13
+ * During `pm2 update` the old daemon (the unit main PID) exits, and `pm2 kill`
14
+ * then reaches the new daemon spawned by `pm2 update` outside the unit and
15
+ * kills it with all its apps (#5000).
16
+ *
17
+ * Rule: when the main process is gone, a stop command only acts on a daemon
18
+ * started by this run of the unit, and never spawns one.
19
+ */
20
+
21
+ var fs = require('fs');
22
+
23
+ var RPC_TIMEOUT = 3000;
24
+
25
+ /**
26
+ * Stop context of the current process, or null when the guard does not apply
27
+ *
28
+ * - only `pm2 kill`: other commands in a stop command (`ExecStop=pm2 delete web`
29
+ * of a oneshot unit, which never has a MAINPID) keep their behavior
30
+ * - SERVICE_RESULT is only set for ExecStop/ExecStopPost (systemd >= 232),
31
+ * never for the main process tree (CI runner jobs, apps...)
32
+ * - MAINPID is only set while the unit main process is alive: then it is an
33
+ * operator stop (systemctl stop/restart, shutdown), keep the normal behavior
34
+ */
35
+ function getStopContext(env, args) {
36
+ var command = (args || []).filter(function(a) { return a[0] !== '-'; })[0];
37
+
38
+ if (command !== 'kill')
39
+ return null;
40
+ if (env.SERVICE_RESULT === undefined || !env.INVOCATION_ID || env.MAINPID)
41
+ return null;
42
+ return { invocation_id : env.INVOCATION_ID };
43
+ }
44
+
45
+ /**
46
+ * Unit cgroup path from /proc/<pid>/cgroup content (v2 or v1 name=systemd),
47
+ * systemd >= 256 runs control commands in a `.control` sub-cgroup
48
+ */
49
+ function parseCgroup(content) {
50
+ if (!content) return null;
51
+ var lines = content.split('\n');
52
+ var found = null;
53
+
54
+ for (var i = 0; i < lines.length; i++) {
55
+ var parts = lines[i].split(':');
56
+ if (parts.length < 3) continue;
57
+ if ((parts[0] === '0' && parts[1] === '') || parts[1] === 'name=systemd') {
58
+ found = parts.slice(2).join(':');
59
+ if (parts[0] === '0') break;
60
+ }
61
+ }
62
+ return found ? found.replace(/\/\.control$/, '') : null;
63
+ }
64
+
65
+ /**
66
+ * @param {Object} ctx getStopContext() result
67
+ * @param {Object} report daemon getReport() result, null if no daemon answered
68
+ * @param {String} self_cgroup /proc/self/cgroup content
69
+ * @param {String} daemon_cgroup /proc/<daemon pid>/cgroup content
70
+ * @return {Object} { action: 'run' | 'skip', reason: String }
71
+ */
72
+ function decide(ctx, report, self_cgroup, daemon_cgroup) {
73
+ if (!report)
74
+ return { action : 'skip', reason : 'no running daemon, nothing to do' };
75
+
76
+ // daemon spawned by this unit run (ExecStart=pm2 resurrect): oneshot units...
77
+ if (report.env && report.env.INVOCATION_ID === ctx.invocation_id)
78
+ return { action : 'run', reason : 'daemon started by this service' };
79
+
80
+ // a real stop command runs in the unit cgroup: only trust a .service one
81
+ var self = parseCgroup(self_cgroup);
82
+ if (self && /\.service$/.test(self) && self === parseCgroup(daemon_cgroup))
83
+ return { action : 'run', reason : 'daemon in this service cgroup' };
84
+
85
+ return { action : 'skip', reason : 'daemon not started by this service (pm2 update?), leaving it running' };
86
+ }
87
+
88
+ function readCgroup(pid) {
89
+ try {
90
+ return fs.readFileSync('/proc/' + pid + '/cgroup', 'utf8');
91
+ } catch(e) {
92
+ return null;
93
+ }
94
+ }
95
+
96
+ /**
97
+ * Ask the running daemon for its report with a dedicated RPC client: never
98
+ * through Client.start/executeRemote, which spawn a daemon when none answers
99
+ *
100
+ * @param {String} rpc_socket_file
101
+ * @param {Function} cb invoked with <report|null>, never fails
102
+ */
103
+ function getDaemonReport(rpc_socket_file, cb) {
104
+ var axon = require('../../modules/pm2-axon');
105
+ var rpc = require('../../modules/pm2-axon-rpc');
106
+ var req = axon.socket('req');
107
+ var client = new rpc.Client(req);
108
+ var called = false;
109
+
110
+ function done(report) {
111
+ if (called) return;
112
+ called = true;
113
+ clearTimeout(timer);
114
+ try { req.close(); } catch(e) {}
115
+ cb(report || null);
116
+ }
117
+
118
+ var timer = setTimeout(done, RPC_TIMEOUT);
119
+
120
+ // socket errors (ENOENT, ECONNREFUSED, EACCES...) mean no usable daemon
121
+ req.on('error', function() { done(); });
122
+ req.once('reconnect attempt', function() { done(); });
123
+ req.once('connect', function() {
124
+ client.call('getReport', {}, function(err, report) {
125
+ done(err ? null : report);
126
+ });
127
+ });
128
+
129
+ req.connect(rpc_socket_file);
130
+ }
131
+
132
+ /**
133
+ * @param {Object} ctx getStopContext() result
134
+ * @param {String} rpc_socket_file
135
+ * @param {Function} cb invoked with <decision>
136
+ */
137
+ function check(ctx, rpc_socket_file, cb) {
138
+ getDaemonReport(rpc_socket_file, function(report) {
139
+ var daemon_cgroup = report && report.pid ? readCgroup(report.pid) : null;
140
+ cb(decide(ctx, report, readCgroup('self'), daemon_cgroup));
141
+ });
142
+ }
143
+
144
+ module.exports = {
145
+ getStopContext : getStopContext,
146
+ parseCgroup : parseCgroup,
147
+ decide : decide,
148
+ check : check
149
+ };
@@ -0,0 +1,55 @@
1
+
2
+ var path = require('path');
3
+ var fs = require('fs');
4
+ var child = require('child_process');
5
+
6
+ var DEFAULT_MAXBUFFER_SIZE = 20 * 1024 * 1024;
7
+
8
+ function _exec(command, options, callback) {
9
+ options = options || {};
10
+
11
+ if (typeof options === 'function') {
12
+ callback = options;
13
+ }
14
+
15
+ if (typeof options === 'object' && typeof callback === 'function') {
16
+ options.async = true;
17
+ }
18
+
19
+ if (!command) {
20
+ try {
21
+ console.error('[sexec] must specify command');
22
+ } catch (e) {
23
+ return;
24
+ }
25
+ }
26
+
27
+ options = Object.assign({
28
+ silent: false,
29
+ cwd: path.resolve(process.cwd()).toString(),
30
+ env: process.env,
31
+ maxBuffer: DEFAULT_MAXBUFFER_SIZE,
32
+ encoding: 'utf8',
33
+ }, options);
34
+
35
+ var c = child.exec(command, options, function (err, stdout, stderr) {
36
+ if (callback) {
37
+ if (!err) {
38
+ callback(0, stdout, stderr);
39
+ } else if (err.code === undefined) {
40
+ // See issue #536
41
+ /* istanbul ignore next */
42
+ callback(1, stdout, stderr);
43
+ } else {
44
+ callback(err.code, stdout, stderr);
45
+ }
46
+ }
47
+ });
48
+
49
+ if (!options.silent) {
50
+ c.stdout.pipe(process.stdout);
51
+ c.stderr.pipe(process.stderr);
52
+ }
53
+ }
54
+
55
+ module.exports = _exec;
@@ -0,0 +1,113 @@
1
+ // treeify.js
2
+ // Luke Plaster <notatestuser@gmail.com>
3
+ // https://github.com/notatestuser/treeify.js
4
+
5
+ // do the universal module definition dance
6
+ (function (root, factory) {
7
+
8
+ if (typeof exports === 'object') {
9
+ module.exports = factory();
10
+ } else if (typeof define === 'function' && define.amd) {
11
+ define(factory);
12
+ } else {
13
+ root.treeify = factory();
14
+ }
15
+
16
+ }(this, function() {
17
+
18
+ function makePrefix(key, last) {
19
+ var str = (last ? '└' : '├');
20
+ if (key) {
21
+ str += '─ ';
22
+ } else {
23
+ str += '──┐';
24
+ }
25
+ return str;
26
+ }
27
+
28
+ function filterKeys(obj, hideFunctions) {
29
+ var keys = [];
30
+ for (var branch in obj) {
31
+ // always exclude anything in the object's prototype
32
+ if (!obj.hasOwnProperty(branch)) {
33
+ continue;
34
+ }
35
+ // ... and hide any keys mapped to functions if we've been told to
36
+ if (hideFunctions && ((typeof obj[branch])==="function")) {
37
+ continue;
38
+ }
39
+ keys.push(branch);
40
+ }
41
+ return keys;
42
+ }
43
+
44
+ function growBranch(key, root, last, lastStates, showValues, hideFunctions, callback) {
45
+ var line = '', index = 0, lastKey, circular, lastStatesCopy = lastStates.slice(0);
46
+
47
+ if (lastStatesCopy.push([ root, last ]) && lastStates.length > 0) {
48
+ // based on the "was last element" states of whatever we're nested within,
49
+ // we need to append either blankness or a branch to our line
50
+ lastStates.forEach(function(lastState, idx) {
51
+ if (idx > 0) {
52
+ line += (lastState[1] ? ' ' : '│') + ' ';
53
+ }
54
+ if ( ! circular && lastState[0] === root) {
55
+ circular = true;
56
+ }
57
+ });
58
+
59
+ // the prefix varies based on whether the key contains something to show and
60
+ // whether we're dealing with the last element in this collection
61
+ line += makePrefix(key, last) + key;
62
+
63
+ // append values and the circular reference indicator
64
+ showValues && (typeof root !== 'object' || root instanceof Date) && (line += ': ' + root);
65
+ circular && (line += ' (circular ref.)');
66
+
67
+ callback(line);
68
+ }
69
+
70
+ // can we descend into the next item?
71
+ if ( ! circular && typeof root === 'object') {
72
+ var keys = filterKeys(root, hideFunctions);
73
+ keys.forEach(function(branch){
74
+ // the last key is always printed with a different prefix, so we'll need to know if we have it
75
+ lastKey = ++index === keys.length;
76
+
77
+ // hold your breath for recursive action
78
+ growBranch(branch, root[branch], lastKey, lastStatesCopy, showValues, hideFunctions, callback);
79
+ });
80
+ }
81
+ };
82
+
83
+ // --------------------
84
+
85
+ var Treeify = {};
86
+
87
+ // Treeify.asLines
88
+ // --------------------
89
+ // Outputs the tree line-by-line, calling the lineCallback when each one is available.
90
+
91
+ Treeify.asLines = function(obj, showValues, hideFunctions, lineCallback) {
92
+ /* hideFunctions and lineCallback are curried, which means we don't break apps using the older form */
93
+ var hideFunctionsArg = typeof hideFunctions !== 'function' ? hideFunctions : false;
94
+ growBranch('.', obj, false, [], showValues, hideFunctionsArg, lineCallback || hideFunctions);
95
+ };
96
+
97
+ // Treeify.asTree
98
+ // --------------------
99
+ // Outputs the entire tree, returning it as a string with line breaks.
100
+
101
+ Treeify.asTree = function(obj, showValues, hideFunctions) {
102
+ var tree = '';
103
+ growBranch('.', obj, false, [], showValues, hideFunctions, function(line) {
104
+ tree += line + '\n';
105
+ });
106
+ return tree;
107
+ };
108
+
109
+ // --------------------
110
+
111
+ return Treeify;
112
+
113
+ }));
@@ -0,0 +1,55 @@
1
+
2
+ var fs = require('fs');
3
+ var semver = require('semver');
4
+ var execSync = require('child_process').execSync;
5
+ var which = require('./which.js');
6
+
7
+ // Node.js type stripping availability:
8
+ // enabled by default since 22.18.0 (22.x line) and 23.6.0,
9
+ // behind --experimental-strip-types since 22.6.0.
10
+ var NATIVE_RANGE = '>=22.18.0 <23.0.0 || >=23.6.0';
11
+ var FLAG_RANGE = '>=22.6.0';
12
+
13
+ var resolved_node_version = null;
14
+
15
+ /**
16
+ * Type stripping support of a given node version.
17
+ * Returns 'native' (runs .ts without flags), 'flag'
18
+ * (needs --experimental-strip-types) or false.
19
+ */
20
+ function supportLevel(version) {
21
+ if (semver.satisfies(version, NATIVE_RANGE))
22
+ return 'native';
23
+ if (semver.satisfies(version, FLAG_RANGE))
24
+ return 'flag';
25
+ return false;
26
+ }
27
+
28
+ /**
29
+ * Version of the `node` binary fork mode will spawn (the one in PATH),
30
+ * which can differ from the node running PM2.
31
+ */
32
+ function resolvedNodeVersion() {
33
+ if (resolved_node_version)
34
+ return resolved_node_version;
35
+
36
+ var node_path = which('node');
37
+ if (node_path == null)
38
+ return resolved_node_version = process.versions.node;
39
+
40
+ try {
41
+ if (fs.realpathSync(node_path) === fs.realpathSync(process.execPath))
42
+ return resolved_node_version = process.versions.node;
43
+ resolved_node_version = execSync(JSON.stringify(node_path) + ' --version', {
44
+ encoding: 'utf8'
45
+ }).trim().replace(/^v/, '');
46
+ } catch(e) {
47
+ resolved_node_version = process.versions.node;
48
+ }
49
+ return resolved_node_version;
50
+ }
51
+
52
+ module.exports = {
53
+ supportLevel: supportLevel,
54
+ resolvedNodeVersion: resolvedNodeVersion
55
+ };