1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
|
#compdef pm2
# ------------------------------------------------------------------------------
# Description
# -----------
#
# Completion script for pm2 5.2.2 (https://pm2.keymetrics.io/).
#
# ------------------------------------------------------------------------------
# Authors
# -------
#
# * Myoungdo Park <mdo.park@gmail.com>
# * Shohei Yoshida <https://github.com/syohex>
#
# ------------------------------------------------------------------------------
_pm2() {
typeset -A opt_args
local context state line
local curcontext="$curcontext"
local ret=1
_arguments -C \
'(- *)'{-v,-V,--version}'[print pm2 version]' \
'(-s --silent)'{-s,--silent}'[hide all messages]' \
'--ext[watch only this file extension]:extension' \
'(-n --name)'{-n,--name}'[set a name for the process in the process list]:name' \
'(-m --mini-list)'{-m,--mini-list}'[display a compacted list without formatting]' \
'--interpreter[set a specific interpreter to use for executing app(default: node)]:prog' \
'(--interpreter-args --node-args)'{--interpreter-args,--node-args}'[set arguments to pass to the interpreter]:args' \
'(-o --output)'{-o,--output}'[specify log file for stdout]: :_files' \
'(-e --error)'{-e,--error}'[specify log file for stderr]: :_files' \
'(-l --log)'{-l,--log}'[specify log file which gathers both stdout and stderr]' \
'--filter-env[filter out outgoing global values that contain provided strings]:envs' \
'--log-type[specify log output style]: :(raw json)' \
'--log-date-format[specify log output style]:format' \
'--time[enable time logging]' \
'--disable-logs[disable all logs storage]' \
'*--env[specify which set of environment variables from ecosystem file must be injected]:env' \
'(-a --update-env)'{-a,--update-env}'[force and update of the environment with restart/reload]' \
'(-f --force)'{-f,--force}'[force actions]' \
'(-i --instances)'{-i,--instances}'[launch number instances]:num' \
'--parallel[number of parallel actions]:num' \
'--shutdown-with-message[shutdown an application with process.send("shutdown") instead of process.kill(pid, SIGINT)]' \
'(-p --pid)'{-p,--pid}'[specify pid file]: :_files' \
'(-k --kill-timeout)'{-k,--kill-timeout}'[delay before sending final SIGKILL signal to process]:delay' \
'--listen-timeout[listen timeout an application reload]:delay' \
'--max-memory-restart[restart the app if an amount of memory is exceeded (in bytes)]:bytes' \
'--restart-delay[specify a delay between restarts(in milliseconds)]:delay' \
'--exp-backoff-restart-delay[specify a delay between restarts(in milliseconds)]:delay' \
'(-x --execute-command)'{-e,--execute-command}'[execute a program using fork system]' \
'--max-restarts[only start the script COUNT times]:count' \
'(-u --user)'{-u,--user}'[define user when generating startup script]:username' \
'--uid[run target script with <uid> rights]:uid' \
'--gid[run target script with <gid> rights]:gui' \
'--namespace[start application within specified namespace]:namespace' \
'--cwd[run target script from path <cwd>]:cwd:_paths -/' \
'--hp[define home path when generating startup script]: :_paths -/' \
'--wait-ip[override systemd script to wait for full internet connectivity to launch pm2]' \
'--service-name[define service name when generating startup script]' \
'(-c --cron --cron-restart)'{-c,--cron,--cron-restart}'[restart a running process based on a cron pattern]:pattern' \
'(-w --write)'{-w,--write}'[write configuration in local folder]' \
'--no-daemon[run pm2 daemon in the foreground if it does not exist already]' \
'(--disable-source-map-support --source-map-support)--source-map-support[force source map support]' \
'--only[with json declaration, allow to only act on one application]:app' \
'(--disable-source-map-support --source-map-support)--disable-source-map-support[force disable source map support]' \
'--wait-ready[ask pm2 to wait for ready event from your app]' \
'--merge-logs[merge logs from different instances but keep error and out separated]' \
'*--watch[watch application folder for changes]: :_files -/' \
'*--ignore-watch[list of paths to ignore]: :_files' \
'--no-color[skip colors]' \
'--no-vizion[start an app without vizion feature]' \
'--np-autorestart[start an app without automatic restart]' \
'--no-treekill[Only kill the main process, not detached children]' \
'--no-pmx[start an app without pmx]' \
'--no-automation[start an app without automation]' \
'(--disable-trace --trace)--trace[enable transaction tracing with km]' \
'(--disable-trace --trace)--disable-trace[disable transaction tracing with km]' \
"--sort[sort process according to field's]:field_name" \
'--attach[attach logging after your start/restart/stop/reload]' \
'--v8[enable v8 data collecting]' \
'--event-loop-inspector[enable event-loop-inspector dump in pmx]' \
'--deep-monitoring[enable all monitoring tools]' \
'(- *)'{-h,--help}'[output usage information]' \
'1: :_pm2_subcommands' \
'*:: :->subcmds' && return 0
case "$state" in
(subcmds)
case $words[1] in
(start)
_arguments \
'--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]:name' \
'--node-version[with --container, set a specific major Node.js version]:version' \
'--dockerdaemon[for debugging purpose]' \
'(- *)'{-h,--help}'[output usage information]' \
'*: :_pm2_id_namespace_file' \
&& ret=0
;;
(trigger)
_arguments \
'(- *)'{-h,--help}'[output usage information]' \
'1: :_pm2_id_names' \
&& ret=0
;;
(deploy|startOrRestart|startOrReload|startOrGracefulReload)
_arguments \
'(- *)'{-h,--help}'[output usage information]' \
'1: :_files -g "*.json"' \
&& ret=0
;;
(stop|restart)
_arguments \
'(- *)'{-h,--help}'[output usage information]' \
'--watch[Stop watching folder for changes]' \
'*: :_pm2_id_namespace_all' \
&& ret=0
;;
(reload|delete|reset)
_arguments \
'(- *)'{-h,--help}'[output usage information]' \
'*: :_pm2_id_namespace_all' \
&& ret=0
;;
(module:install)
_arguments \
'(- *)'{-h,--help}'[output usage information]' \
'--tarball[is local tarball]' \
'--install[run yarn install before starting module]' \
'--docker[is docker container]' \
'--v1[install module in v1 manner(do not use it)]' \
'--safe[keep module backup, if new module fail = restore with previous]:time' \
&& ret=0
;;
(publish|module:publish)
_arguments \
'(- *)'{-h,--help}'[output usage information]' \
'--npm[publish on npm]' \
'*: :_files -/' \
&& ret=0
;;
(link)
_arguments \
'(- *)'{-h,--help}'[output usage information]' \
'--info-node[set url info node]:url' \
&& ret=0
;;
(plus)
_arguments \
'(- *)'{-h,--help}'[output usage information]' \
'--info-node[set url info node]:url' \
'(-d --discrete)'{-d,--discrete}'[silent mode]' \
'(-a --install-all)'{-a,--install-all}'[install all modules (force yes)]' \
&& ret=0
;;
(dump|save)
_arguments \
'(- *)'{-h,--help}'[output usage information]' \
'--force[force deletion of dump file even if empty]' \
&& ret=0
;;
(send|attach|describe|env)
_arguments \
'(- *)'{-h,--help}'[output usage information]' \
'1: :_pm2_id_names' \
&& ret=0
;;
(slist|sysinfos)
_arguments \
'(- *)'{-h,--help}'[output usage information]' \
'--tree[show as tree]' \
&& ret=0
;;
(logs)
_arguments \
'(- *)'{-h,--help}'[output usage information]' \
'--json[json log output]' \
'--format[formatted log output]' \
'--raw[raw output]' \
'--err[only shows error output]' \
'--out[only shows standard output]' \
'--line[output the last N lines, instead of the last 15 by default]:lines' \
'--timestamp[add timestamps(default format YYYY-MM-DD-HH:mm:ss)]:format' \
'--nostream[print logs without launching the log stream]' \
'*--highlight[highlights the given value]' \
'1: :_pm2_id_namespace' \
&& ret=0
;;
(serve)
_arguments \
'(- *)'{-h,--help}'[output usage information]' \
'--port[specify port to listen to]:port' \
'--spa[always serving index.html on inexistent sub path]' \
'--basic-auth-username[set basic auth username]:username' \
'--basic-auth-password[set basic auth password]:password' \
'--monitor[frontend app monitoring]:app' \
'*: :_files -/' \
&& ret=0
;;
(*)
_arguments \
'(- *)'{-h,--help}'[output usage information]' \
'*: :_files' \
&& ret=0
;;
esac
;;
esac
return ret
}
(( $+functions[_pm2_subcommands] )) ||
_pm2_subcommands() {
local -a subcommands=(
"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"
"create:return pid of [app_name] or all"
"startOrGracefulReload:start or gracefully reload JSON file"
"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"
"update:update in-memory PM2 with local PM2"
"install:install or update a module and run it forever"
"module\: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"
"module\:uninstall:stop and uninstall a module"
"package:Check & Package TAR type module"
"publish:Publish the module you are currently on"
"module\:publish:Publish the module you are currently on"
"set:sets the specified config <key> <value>"
"multiset:multiset eg \"key1 val1 key2 val2\""
"get:get value for <key>"
"conf:get / set module config values"
"config:get / set module config values"
"unset:clears the specified config <key>"
"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"
"dump:dump all processes for resurrecting them later"
"save:dump all processes for resurrecting them later"
"cleardump:Create empty dump file"
"send:send stdin to <pm_id>"
"attach:attach stdin/stdout to application identified by <pm_id>"
"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"
"init:generate a process conf file"
"reset:reset counters for process"
"describe:describe all parameters of a process"
"desc:describe all parameters of a process"
"info:describe all parameters of a process"
"show:describe all parameters of a process"
"env:list all environment variables of a process id"
"list:list all processes"
"l:list all processes"
"ps:list all processes"
"status:list all processes"
"jlist:list all processes in JSON format"
"sysmonit:start system monitoring daemon"
"slist:list system infos in JSON"
"sysinfos:list system infos in JSON"
"prettylist:print json in a prettified JSON"
"monit:launch termcaps monitoring"
"imonit:launch legacy termcaps monitoring"
"dashboard:launch dashboard with monitoring and logs"
"dash: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"
"autoinstall:auto install"
"examples:display pm2 usage examples"
)
_describe -t subcommands 'subcommand' subcommands "$@"
}
(( $+functions[_pm2_id_names] )) ||
_pm2_id_names() {
local app_list=$(pm2 list -m)
local -a names=(${(@f)"$(echo $app_list | awk '/^\+---/{sub("+--- ", ""); print}')"})
local -a ids=(${(@f)"$(echo $app_list | awk '/^pm2 id/{sub("pm2 id :", ""); print}')"})
if (( ${#ids} > 0 )); then
local -a id_names
for i in {1..${#ids}}; do
id_names+=( "${ids[i]}:${names[i]}" )
done
_describe 'id' id_names
fi
}
(( $+functions[_pm2_namespaces] )) ||
_pm2_namespaces() {
local -a namespaces=(${(@f)"$(pm2 list -m | awk '/^namespace :/{ print $3 }')"})
if (( ${#namespaces} > 0 )); then
_values 'namespace' $namespaces
fi
}
(( $+functions[_pm2_id_namespace] )) ||
_pm2_id_namespace() {
_alternative \
'ids:id:_pm2_id_names' \
'namespaces:namespace:_pm2_namespaces'
}
(( $+functions[_pm2_id_namespace_all] )) ||
_pm2_id_namespace_all() {
_alternative \
'ids:id:_pm2_id_names' \
'namespaces:namespace:_pm2_namespaces' \
'all:all:(all)'
}
(( $+functions[_pm2_id_namespace_file] )) ||
_pm2_id_namespace_file() {
_alternative \
'ids:id:_pm2_id_names' \
'namespaces:namespace:_pm2_namespaces' \
'files:file:_files'
}
_pm2 "$@"
# Local Variables:
# mode: Shell-Script
# sh-indentation: 2
# indent-tabs-mode: nil
# sh-basic-offset: 2
# End:
# vim: ft=zsh sw=2 ts=2 et
|