bd5d0066b908af0db1c4e8b1fb18888d8965d3a0

Author
Myoungdo Park <cuspymd@gmail.com>
Committer
GitHub <noreply@github.com>
Date

Message

feat(pm2): Adding a pm2 plugin (#7684)

* Add pm2 plugin

* Add description of pm2 plugin

Diff

This diff is truncated to protect this page.

  1diff --git a/plugins/pm2/README.md b/plugins/pm2/README.md
  2new file mode 100644
  3index 0000000000000000000000000000000000000000..5dfd540b68900ee6face103b0f9da6009d5d8656
  4--- /dev/null
  5+++ b/plugins/pm2/README.md
  6@@ -0,0 +1,19 @@
  7+# pm2 plugin
  8+
  9+The plugin adds several aliases and completions for common [pm2](http://pm2.keymetrics.io/) commands.
 10+
 11+To use it, add `pm2` to the plugins array of your zshrc file:
 12+```
 13+plugins=(... pm2)
 14+```
 15+
 16+## Aliases
 17+
 18+| Alias  | Command              |
 19+|--------|----------------------|
 20+| p2s  | `pm2 start` |
 21+| p2o  | `pm2 stop` |
 22+| p2d | `pm2 delete` |
 23+| p2r   | `pm2 restart` |
 24+| p2i   | `pm2 list` |
 25+| p2l   |  `pm2 logs` |
 26diff --git a/plugins/pm2/_pm2 b/plugins/pm2/_pm2
 27new file mode 100644
 28index 0000000000000000000000000000000000000000..6f1e89df5e9a5cc8782aba1ba7d4ac5c3f48418c
 29--- /dev/null
 30+++ b/plugins/pm2/_pm2
 31@@ -0,0 +1,168 @@
 32+#!/bin/zsh -f
 33+#compdef pm2
 34+#autoload
 35+
 36+local -a _1st_arguments
 37+
 38+_1st_arguments=(
 39+    "start:start and daemonize an app"
 40+    "trigger:trigger process action"
 41+    "deploy:deploy your json"
 42+    "startOrRestart:start or restart JSON file"
 43+    "startOrReload:start or gracefully reload JSON file"
 44+    "pid:return pid of [app_name] or all"
 45+    "stop:stop a process"
 46+    "restart:restart a process"
 47+    "scale:scale up/down a process in cluster mode depending on total_number param"
 48+    "profile\:mem:Sample PM2 heap memory"
 49+    "profile\:cpu:Profile PM2 cpu"
 50+    "reload:reload processes (note that its for app using HTTP/HTTPS)"
 51+    "id:get process id by name"
 52+    "inspect:inspect a process"
 53+    "delete:stop and delete a process from pm2 process list"
 54+    "sendSignal:send a system signal to the target process"
 55+    "ping:ping pm2 daemon - if not up it will launch it"
 56+    "updatePM2:update in-memory PM2 with local PM2"
 57+    "install:install or update a module and run it forever"
 58+    "module\:update:update a module and run it forever"
 59+    "module\:generate:Generate a sample module in current folder"
 60+    "uninstall:stop and uninstall a module"
 61+    "package:Check & Package TAR type module"
 62+    "publish:Publish the module you are currently on"
 63+    "set:sets the specified config <key> <value>"
 64+    "multiset:multiset eg \"key1 val1 key2 val2\""
 65+    "get:get value for <key>"
 66+    "config:get / set module config values"
 67+    "unset:clears the specified config <key>"
 68+    "report:give a full pm2 report for https\://github.com/Unitech/pm2/issues"
 69+    "link:link with the pm2 monitoring dashboard"
 70+    "unlink:unlink with the pm2 monitoring dashboard"
 71+    "monitor:monitor target process"
 72+    "unmonitor:unmonitor target process"
 73+    "open:open the pm2 monitoring dashboard"
 74+    "plus:enable pm2 plus"
 75+    "login:Login to pm2 plus"
 76+    "logout:Logout from pm2 plus"
 77+    "web:launch a health API on 0.0.0.0\:9615"
 78+    "dump:dump all processes for resurrecting them later"
 79+    "cleardump:Create empty dump file"
 80+    "send:send stdin to <pm_id>"
 81+    "attach:attach stdin/stdout to application identified by <pm_id>"
 82+    "resurrect:resurrect previously dumped processes"
 83+    "unstartup:disable the pm2 startup hook"
 84+    "startup:enable the pm2 startup hook"
 85+    "logrotate:copy default logrotate configuration"
 86+    "ecosystem:generate a process conf file. (mode = null or simple)"
 87+    "reset:reset counters for process"
 88+    "describe:describe all parameters of a process id"
 89+    "list:list all processes"
 90+    "jlist:list all processes in JSON format"
 91+    "prettylist:print json in a prettified JSON"
 92+    "monit:launch termcaps monitoring"
 93+    "imonit:launch legacy termcaps monitoring"
 94+    "dashboard:launch dashboard with monitoring and logs"
 95+    "flush:flush logs"
 96+    "reloadLogs:reload all logs"
 97+    "logs:stream logs file. Default stream all logs"
 98+    "kill:kill daemon"
 99+    "pull:updates repository for a given app"
100+    "forward:updates repository to the next commit for a given app"
101+    "backward:downgrades repository to the previous commit for a given app"
102+    "deepUpdate:performs a deep update of PM2"
103+    "serve:serve a directory over http via port"
104+    "examples:display pm2 usage examples"
105+)
106+
107+local -a id_names
108+
109+_id_names() {
110+    local app_list
111+    app_list=`pm2 list -m`
112+
113+    local -a names ids 
114+    names=(`echo $app_list | grep '+---' | awk '{print $2}'`)
115+    ids=(`echo $app_list | grep 'pm2 id' | awk '{print $4}'`)
116+
117+    if (( ${#ids} > 0 )); then
118+        for i in {1..${#ids}}; do
119+            id_names+=( "${ids[i]}:${names[i]}" )
120+        done
121+    fi
122+}
123+
124+_arguments \
125+    '(-v --version)'{-v,--version}'[output version]' \
126+    '(-h --help)'{-h,--help}'[output usage information]' \
127+    '*:: :->subcmds' && return 0
128+
129+if (( CURRENT == 1 )); then
130+    _describe "command" _1st_arguments
131diff --git a/plugins/pm2/pm2.plugin.zsh b/plugins/pm2/pm2.plugin.zsh
132new file mode 100644
133index 0000000000000000000000000000000000000000..f05d8db8b1e07cf33f3c09336005953314f02c89
134--- /dev/null
135+++ b/plugins/pm2/pm2.plugin.zsh
136@@ -0,0 +1,6 @@
137+alias p2s='pm2 start'
138+alias p2o='pm2 stop'
139+alias p2d='pm2 delete'
140+alias p2r='pm2 restart'
141+alias p2i='pm2 list'
142+alias p2l='pm2 logs'