-
Notifications
You must be signed in to change notification settings - Fork 16
/
pm2.node_cli.txt
355 lines (278 loc) · 16.7 KB
/
pm2.node_cli.txt
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
PM2
ALTERNATIVES ==> # - pm2 (prefer)
# - forever
VERSION ==> #Node module (2.4.2)
#Helps managing multiprocess of same script (e.g. Node in cluster mode)
PM2.COMMAND([ARGS, ]
[OBJ, ]FUNC(ERROR, VAL)) #Programmatic use (Node.js). Must first use PM2.connect()
/=+===============================+=\
/ : : \
)==: CONFIG :==(
\ :_______________________________: /
\=+===============================+=/
CONF #Can alternatively declare options in a JSON file (will not use command line options then
#except --env):
# - apps OBJ_ARR:
# - name, script, args STR_ARR_STR, log_date_format, ignoreWatch PATH_ARR, node_args, cwd,
# env[_VAR] OBJ, instances NUM_STR, error|out_file, pid_file,
# exec_mode "cluster|fork_mode", port NUM, min_uptime, run_as_user|group, max_restarts,
# cron_restart, watch PATH_ARR, merge_logs BOOL_STR, exec_interpreter STR
#Extra options available only via CONF:
# - cwd DIR: used to resolve any relative path
# - env_VAR: env OBJ used if --env VAR is used
pm2 ecosystem [simple] #Creates sample ecosystem.json file ESYS:
#Unless simple, already fills in many variables
pm2 set VAR VAL ???
pm2 multiset VAR VAL ... ???
pm2 get [VAR] ???
pm2 conf [VAR] [VAL] ???
pm2 config VAR [VAL] ???
pm2 unset VAR ???
~/.pm2/custom_options.sh #Or ENVVAR: several variables to change pm2 (not jobs): PM2_GRACEFUL_TIMEOUT,
#PM2_RPC|PUB|API_PORT, PM2_BIND_ADDR, PM2_MODIFY_REQUIRE
/=+===============================+=\
/ : : \
)==: DAEMON :==(
\ :_______________________________: /
\=+===============================+=/
STARTING PM2 DAEMON ==> #Automatically done when launching jobs. Listen to port 6666 and 6667
#Only pm2 process can be seen through OS
pm2 ping #Pings pm2 daemon. If not up, starts it.
pm2 kill #Stops daemon
pm2 update #Updates pm2 after a npm update (does pm2 kill first)
pm2 deepUpdate ???
/=+===============================+=\
/ : : \
)==: JOBS :==(
\ :_______________________________: /
\=+===============================+=/
pm2 start [SCRIPT|CONF|ID|APP]#Start in the background (unless --no-daemon)
[-- ARGS] #SCRIPT def. is stdin
#PID:
# - jobs at PID_FILE (def: ~/.pm2/pids/APP-ID.pid) (can specify with -p PID_FILE)
# - pm2 at ~/.pm2/pm2.pid
#When job exits, restart it according to CONF members:
# - max_restarts NUM (def: 15)
# - min_uptime (def: 200, in ms)
--instances NUM #Number of identical jobs to launch
#NUM:
# - can be NUM, def 1
# - can be max|0 for number of CPU cores
# - can be -NUM, for max - NUM
#Can be in mode:
# - cluster (if no -x): uses Node CLUSTER.fork():
# - all listens to same port, so does load balancing
# - allows pm2 [graceful]reload (as opposed to restart)
# - fork (if -x): uses Node CHILD_PROCESS.fork()
# - must listen to different ports
# - but does load balancing too
--name APP #Process name (def: NODE_SCRIPT without extension)
--interpreter STR #Def: "node" (.js), "bash" (.sh), "python" (.py), "ruby" (.rb), "coffee" (.coffee), "php" (.php),
#"perl" (.pl)
--interpreter-args ARGS #To pass arguments to the interpreter not to the SCRIPT
--watch [DIR...] #Do pm2 restart if folder changes:
--ignore-watch FILE|DIR... # - Def: SCRIPT
#To stop watching, use --watch with pm2 stop
#Restart keeps --watch
#Prefer using only in dev mode, and then prefer nodemon
--run-as-user|group USER|GROUP#
--max-memory-restart NUM #Restart jobs when it uses more than NUM MB of RAM
--restart-delay NUM ???
--max-restarts [NUM] ???
-c STR #According to cron pattern STR, will pm2 restart
-w #Write configuration CONF at ./APP-pm2.json
--wait-ready ???
--no-vizion ???
--no-autorestart ???
--no-treekill ???
--no-pmx ???
--[disable-]trace ???
--[disable-]source-map-support ???
pm2 stop [ID|APP|all|CONF] #Stops jobs but do not remove from jobs list
#Def: stdin (for CONF)
pm2 delete #Stops jobs and removes from jobs list
[ID|APP|all|CONF|SCRIPT] #Def: stdin (for CONF)
pm2 restart [ID|APP|all|CONF] #Restart running|stopped jobs at same time
#Def: stdin (for CONF)
--cron PATTERN ???
--update-env ???
pm2 startOrRestart CONF #
pm2 reload FILE|APP|all #Restart jobs at sequential time to avoid downtime. Only if cluster_mode
--only APP #
pm2 startOrReload CONF ???
pm2 gracefulReload APP|all #Same as pm2 reload but:
# - first sends message (using CHILD_PROCESS|CLUSTER.send())
# - after ENVVAR PM2_GRACEFUL_TIMEOUT secs (def: 4), terminates
# - sequential time too: wait for each job to be online. If job doesn't listen to a port,
# can manually process.send("online")
#Application should also:
# - process.on('SIGINT'), doing cleanup
pm2 startOrGracefulReload CONF#
pm2 sendSignal SIGNAL ID|APP #e.g. SIGTERM
--kill-timeout NUM ???
pm2 scale APP NUM ???
/=+===============================+=\
/ : : \
)==: INFO :==(
\ :_______________________________: /
\=+===============================+=/
pm2 list #List jobs with nice formatting:
# - name
# - id
# - mode "fork|cluster"
# - PID
# - status "online|stopped"
# - restarted NUM
# - uptime
# - memory
# - watching
-m #No formatting
--watch #
pm2 show ???
pm2 jlist|prettylist #List jobs as JSON OBJ_ARR (pretified or not):
# - name
# - pid
# - pm_id
# - monit:
# - memory NUM
# - cpu NUM
# - pm2_env:
# - monit: memory, cpu
# - name
# - node_args
# - instances NUM
# - exec_mode "cluster_mode|fork"
# - env OBJ (ENVVARs)
# - pm_cwd
# - exec_interpreter
# - pm_exec_path
# - pm_out|err_log_path
# - pm_pid_path
# - pm_id
# - restart_time NUM
# - unstable_restarts NUM
# - created_at DATE_NUM
# - pm_uptime DATE_NUM
# - status "online|stopped"
pm2 desc ID #Same as pm2 list (including options) with also:
# - path NODE_SCRIPT
# - args NODE_ARGS
# - exec cwd DIR
# - out|error log path STDOUT|ERRFILE
# - pid path PID_FILE
# - node v8 arguments
# - watch & reload
# - interpreter node
# - [unstable] restarts NUM
# - created at DATE
pm2 monit #List pm2 list but "live" (like top)
pm2 reset APP|ID|all #Resets stats
pm2 web #Launch server on port 9615, which respond with JSON taken from Node.js OS.*() + pm2 jlist:
# - system_info: hostname STR, uptime NUM
# - monit:
# - loadavg NUM_ARR (3 NUMs)
# - total|free_mem
# - cpu OBJ_ARR
# - interfaces OBJ_ARR
# - processes OBJ (like pm2 jlist, without top-level monit)
pm2 dashboard ???
pm2 snapshot ???
pm2 profile COMMAND ???
pm2 id APP ???
pm2 gc ???
pm2 serve [PATH] [PORT] ???
/=+===============================+=\
/ : : \
)==: LOGS :==(
\ :_______________________________: /
\=+===============================+=/
pm2 ...
--no-color #
-s #Silent
-v #Verbose
--log FILE ???
--output|error FILE ???
--log-type raw|json ???
--attach ???
pm2 logs [ID|APP] #Show logs (streaming output).
#Logs locations:
# - Redirects stdout|err to STDOUT|ERRFILE (def: ~/.pm2/logs/a-out|err-0.log)
# - can specify with pm2 start -o|e STDOUT|ERRFILE
# - use a-out-err.log (so merge different jobs) if pm2 start --merge-logs
# - pm2 log at ~/.pm2/pm2.log
#Can specify date format with pm2 start --log-date-format MOMENTJS_FORMAT
--json???
--format ???
--raw ???
--err ???
--out ???
--lines NUM ???
--timestamp DATE ???
--nostream ???
pm2 flush #Delete logs
pm2 reloadLogs #Or send SIGUSR2 to pm2 proces
pm2 logrotate ???
/=+===============================+=\
/ : : \
)==: SNAPSHOTS :==(
\ :_______________________________: /
\=+===============================+=/
pm2 save #Snapshots all processes to ~/.pm2/dump.pm2
pm2 resurrect #Restore snapshot
pm2 startup PLATFORM #Sets init scripts to restore snapshots at boot time:
# - ubuntu: updaterc.d and lib/scripts/pm2-init.sh
# - centos: chkconfig and lib/scripts/pm2-init-centos.sh
# - gentoo: rc-update and lib/scripts/pm2
# - systemd: systemctl and lib/scripts/pm2.service
-u USER #User to use
--hp DIR ???
pm2 unstartup [PLATFORM] ???
/=+===============================+=\
/ : : \
)==: DEPLOY :==(
\ :_______________________________: /
\=+===============================+=/
STAGE #E.g. "dev" or "production"
CONF.deploy.STAGE #OBJ:
# - user STR
# - host IP
# - repo GIT_SSH_URL
# - ref LBRANCH
# - path DIR: where to copy
# - pre-deploy: COMMAND_STR
# - post-deploy COMMAND_STR (def: "pm2 startOrRestart ecosystem.json")
pm2 deploy ... #Everything below is executed on remote server at IP (connect using SSH)
pm2 deploy ESYS VAR setup #Creates local DIR
pm2 deploy ESYS VAR [COMMIT] #Copy remote repo to local DIR from COMMIT (def: HEAD)
pm2 deploy ESYS VAR update #Removes local repo and copy remote repo to local DIR
pm2 deploy ESYS VAR revert
[NUM] #Uses NUMth last commit
pm2 deploy ESYS VAR curr|prev #Show current|previous commit
pm2 deploy ESYS VAR list #List previously deployed commits
pm2 deploy ESYS VAR exec STR #Execute shell command on remote server
pm2 trigger ???
pm2 pull APP [COMMIT] ???
pm2 forward APP ???
pm2 backward APP ???
/=+===============================+=\
/ : : \
)==: MODULES :==(
\ :_______________________________: /
\=+===============================+=/
pm2 module:generate [APP] ???
pm2 [module:]install MODULE|GIT_URL ???
pm2 module:update MODULE|GIT_URL ???
pm2 [module:]uninstall MODULE ???
pm2 [module:]publish ???
/=+===============================+=\
/ : : \
)==: DOCKER :==(
\ :_______________________________: /
\=+===============================+=/
pm2 docker:gen FILE|CONF???
--force ???
pm2 docker:dev|dist FILE|CONF???
--fresh ???
--daemon ???