From bd5d0066b908af0db1c4e8b1fb18888d8965d3a0 Mon Sep 17 00:00:00 2001 From: Myoungdo Park Date: Mon, 14 Jun 2021 02:58:44 +0900 Subject: [PATCH] feat(pm2): Adding a pm2 plugin (#7684) * Add pm2 plugin * Add description of pm2 plugin --- plugins/pm2/README.md | 19 +++++ plugins/pm2/_pm2 | 168 +++++++++++++++++++++++++++++++++++++ plugins/pm2/pm2.plugin.zsh | 6 ++ 3 files changed, 193 insertions(+) create mode 100644 plugins/pm2/README.md create mode 100644 plugins/pm2/_pm2 create mode 100644 plugins/pm2/pm2.plugin.zsh diff --git a/plugins/pm2/README.md b/plugins/pm2/README.md new file mode 100644 index 00000000..5dfd540b --- /dev/null +++ b/plugins/pm2/README.md @@ -0,0 +1,19 @@ +# pm2 plugin + +The plugin adds several aliases and completions for common [pm2](http://pm2.keymetrics.io/) commands. + +To use it, add `pm2` to the plugins array of your zshrc file: +``` +plugins=(... pm2) +``` + +## Aliases + +| Alias | Command | +|--------|----------------------| +| p2s | `pm2 start` | +| p2o | `pm2 stop` | +| p2d | `pm2 delete` | +| p2r | `pm2 restart` | +| p2i | `pm2 list` | +| p2l | `pm2 logs` | diff --git a/plugins/pm2/_pm2 b/plugins/pm2/_pm2 new file mode 100644 index 00000000..6f1e89df --- /dev/null +++ b/plugins/pm2/_pm2 @@ -0,0 +1,168 @@ +#!/bin/zsh -f +#compdef pm2 +#autoload + +local -a _1st_arguments + +_1st_arguments=( + "start:start and daemonize an app" + "trigger:trigger process action" + "deploy:deploy your json" + "startOrRestart:start or restart JSON file" + "startOrReload:start or gracefully reload JSON file" + "pid:return pid of [app_name] or all" + "stop:stop a process" + "restart:restart a process" + "scale:scale up/down a process in cluster mode depending on total_number param" + "profile\:mem:Sample PM2 heap memory" + "profile\:cpu:Profile PM2 cpu" + "reload:reload processes (note that its for app using HTTP/HTTPS)" + "id:get process id by name" + "inspect:inspect a process" + "delete:stop and delete a process from pm2 process list" + "sendSignal:send a system signal to the target process" + "ping:ping pm2 daemon - if not up it will launch it" + "updatePM2:update in-memory PM2 with local PM2" + "install:install or update a module and run it forever" + "module\:update:update a module and run it forever" + "module\:generate:Generate a sample module in current folder" + "uninstall:stop and uninstall a module" + "package:Check & Package TAR type module" + "publish:Publish the module you are currently on" + "set:sets the specified config " + "multiset:multiset eg \"key1 val1 key2 val2\"" + "get:get value for " + "config:get / set module config values" + "unset:clears the specified config " + "report:give a full pm2 report for https\://github.com/Unitech/pm2/issues" + "link:link with the pm2 monitoring dashboard" + "unlink:unlink with the pm2 monitoring dashboard" + "monitor:monitor target process" + "unmonitor:unmonitor target process" + "open:open the pm2 monitoring dashboard" + "plus:enable pm2 plus" + "login:Login to pm2 plus" + "logout:Logout from pm2 plus" + "web:launch a health API on 0.0.0.0\:9615" + "dump:dump all processes for resurrecting them later" + "cleardump:Create empty dump file" + "send:send stdin to " + "attach:attach stdin/stdout to application identified by " + "resurrect:resurrect previously dumped processes" + "unstartup:disable the pm2 startup hook" + "startup:enable the pm2 startup hook" + "logrotate:copy default logrotate configuration" + "ecosystem:generate a process conf file. (mode = null or simple)" + "reset:reset counters for process" + "describe:describe all parameters of a process id" + "list:list all processes" + "jlist:list all processes in JSON format" + "prettylist:print json in a prettified JSON" + "monit:launch termcaps monitoring" + "imonit:launch legacy termcaps monitoring" + "dashboard:launch dashboard with monitoring and logs" + "flush:flush logs" + "reloadLogs:reload all logs" + "logs:stream logs file. Default stream all logs" + "kill:kill daemon" + "pull:updates repository for a given app" + "forward:updates repository to the next commit for a given app" + "backward:downgrades repository to the previous commit for a given app" + "deepUpdate:performs a deep update of PM2" + "serve:serve a directory over http via port" + "examples:display pm2 usage examples" +) + +local -a id_names + +_id_names() { + local app_list + app_list=`pm2 list -m` + + local -a names ids + names=(`echo $app_list | grep '+---' | awk '{print $2}'`) + ids=(`echo $app_list | grep 'pm2 id' | awk '{print $4}'`) + + if (( ${#ids} > 0 )); then + for i in {1..${#ids}}; do + id_names+=( "${ids[i]}:${names[i]}" ) + done + fi +} + +_arguments \ + '(-v --version)'{-v,--version}'[output version]' \ + '(-h --help)'{-h,--help}'[output usage information]' \ + '*:: :->subcmds' && return 0 + +if (( CURRENT == 1 )); then + _describe "command" _1st_arguments + return +fi + +local -a id_comp id_all_comp id_all_files_comp start_options logs_options +id_comp=('1: :->id_comp') +id_all_comp=('1: :->id_all_comp') +id_all_files_comp=('1: :->id_all_files_comp') +start_options=( + '--watch[Watch folder for changes]' + '--fresh[Rebuild Dockerfile]' + '--daemon[Run container in Daemon mode (debug purposes)]' + '--container[Start application in container mode]' + '--dist[with --container; change local Dockerfile to containerize all files in current directory]' + '--image-name[with --dist; set the exported image name]' + '--node-version[with --container, set a specific major Node.js version]' + '--dockerdaemon[for debugging purpose]' + '(-h --help)'{-h,--help}'[output usage information]' + $id_all_files_comp +) +logs_options=( + '--json[json log output]' + '--format[formated log output]' + '--raw[raw output]' + '--err[only shows error output]' + '--out[only shows standard output]' + '--lines[output the last N lines, instead of the last 15 by default]' + '--timestamp[add timestamps (default format YYYY-MM-DD-HH:mm:ss)]' + '--nostream[print logs without lauching the log stream]' + '(-h --help)'{-h,--help}'[output usage information]' + $id_all_comp +) + +case "$words[1]" in + start) + _arguments $start_options && return 0 + ;; + logs) + _arguments $logs_options && return 0 + ;; + stop|restart|delete|reload|reset) + _arguments $id_all_comp && return 0 + ;; + env|inspect|monitor|unmonitor|discribe) + _arguments $id_comp && return 0 + ;; + deploy|startOrRestart|startOrReload) + _files ;; +esac + +case "$state" in + id_comp) + _id_names + _alternative \ + 'args:app args:(($id_names))' + ;; + id_all_comp) + _id_names + id_names+=(all) + _alternative \ + 'args:app args:(($id_names))' + ;; + id_all_files_comp) + _id_names + id_names+=(all) + _alternative \ + 'args:app args:(($id_names))' \ + 'files:filename:_files' + ;; +esac diff --git a/plugins/pm2/pm2.plugin.zsh b/plugins/pm2/pm2.plugin.zsh new file mode 100644 index 00000000..f05d8db8 --- /dev/null +++ b/plugins/pm2/pm2.plugin.zsh @@ -0,0 +1,6 @@ +alias p2s='pm2 start' +alias p2o='pm2 stop' +alias p2d='pm2 delete' +alias p2r='pm2 restart' +alias p2i='pm2 list' +alias p2l='pm2 logs' -- GitLab