-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Expand file tree
/
Copy pathindex.d.ts
More file actions
726 lines (676 loc) · 22.4 KB
/
index.d.ts
File metadata and controls
726 lines (676 loc) · 22.4 KB
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
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
// Type definitions for pm2 6.0.8
// Definitions by: João Portela https://www.github.com/jportela
// Exported Methods
/**
* Either connects to a running pm2 daemon (“God”) or launches and daemonizes one.
* Once launched, the pm2 process will keep running after the script exits.
* @param errback - Called when finished connecting to or launching the pm2 daemon process.
*/
export function connect(errback: ErrCallback): void;
/**
* Either connects to a running pm2 daemon (“God”) or launches and daemonizes one.
* Once launched, the pm2 process will keep running after the script exits.
* @param noDaemonMode - (Default: false) If true is passed for the first argument
* pm2 will not be run as a daemon and will die when the related script exits.
* By default, pm2 stays alive after your script exits.
* If pm2 is already running, your script will link to the existing daemon but will die once your process exits.
* @param errback - Called when finished connecting to or launching the pm2 daemon process.
*/
export function connect(noDaemonMode:boolean, errback: ErrCallback): void;
/**
* Starts a script that will be managed by pm2.
* @param options - Options
* @param errback - An errback called when the script has been started.
* The proc parameter will be a pm2 process object.
*/
export function start(options: StartOptions, errback: ErrProcCallback): void;
/**
* Starts a script that will be managed by pm2.
* @param jsonConfigFile - The path to a JSON file that can contain the same options as the options parameter.
* @param errback - An errback called when the script has been started.
* The proc parameter will be a pm2 process object.
*/
export function start(jsonConfigFile: string, errback: ErrProcCallback): void;
/**
* Starts a script that will be managed by pm2.
* @param script - The path of the script to run.
* @param errback - An errback called when the script has been started.
* The proc parameter will be a pm2 process object.
*/
export function start(script: string , errback: ErrProcCallback): void;
/**
* Starts a script that will be managed by pm2.
* @param script - The path of the script to run.
* @param options - Options
* @param errback - An errback called when the script has been started.
* The proc parameter will be a pm2 process object.
*/
export function start(script: string, options: StartOptions, errback: ErrProcCallback): void;
/**
* Starts a script that will be managed by pm2.
* @param script - The path of the script to run.
* @param jsonConfigFile - The path to a JSON file that can contain the same options as the options parameter.
* @param errback - An errback called when the script has been started.
* The proc parameter will be a pm2 process object.
*/
export function start(script: string, jsonConfigFile: string, errback: ErrProcCallback): void;
/**
* Disconnects from the pm2 daemon.
*/
export function disconnect(): void;
/**
* Stops a process but leaves the process meta-data in pm2’s list
* @param process - Can either be the name as given in the pm2.start options,
* a process id, or the string “all” to indicate that all scripts should be restarted.
* @param errback - called when the process is stopped
*/
export function stop(process: string|number, errback: ErrProcCallback): void;
/**
* Stops and restarts the process.
* @param process - Can either be the name as given in the pm2.start options,
* a process id, or the string “all” to indicate that all scripts should be restarted.
* @param errback - called when the process is restarted
*/
export function restart(process: string|number, errback: ErrProcCallback): void;
/**
* Stops the process and removes it from pm2’s list.
* The process will no longer be accessible by its name
* @param process - Can either be the name as given in the pm2.start options,
* a process id, or the string “all” to indicate that all scripts should be restarted.
* @param errback - called when the process is deleted
*/
declare function del(process: string|number, errback: ErrProcCallback): void;
// have to use this construct because `delete` is a reserved word
export {del as delete};
/**
* Zero-downtime rolling restart. At least one process will be kept running at
* all times as each instance is restarted individually.
* Only works for scripts started in cluster mode.
* @param process - Can either be the name as given in the pm2.start options,
* a process id, or the string “all” to indicate that all scripts should be restarted.
* @param errback - called when the process is reloaded
*/
export function reload(process: string|number, errback: ErrProcCallback): void;
/**
* Zero-downtime rolling restart. At least one process will be kept running at
* all times as each instance is restarted individually.
* Only works for scripts started in cluster mode.
* @param process - Can either be the name as given in the pm2.start options,
* a process id, or the string “all” to indicate that all scripts should be restarted.
* @param options - An object containing configuration
* @param options.updateEnv - (Default: false) If true is passed in, pm2 will reload it’s
* environment from process.env before reloading your process.
* @param errback - called when the process is reloaded
*/
export function reload(process: string|number, options: ReloadOptions, errback: ErrProcCallback): void;
/**
* Kills the pm2 daemon (same as pm2 kill). Note that when the daemon is killed, all its
* processes are also killed. Also note that you still have to explicitly disconnect
* from the daemon even after you kill it.
* @param errback
*/
export function killDaemon(errback: ErrProcDescCallback): void;
/**
* Returns various information about a process: eg what stdout/stderr and pid files are used.
* @param process - Can either be the name as given in the pm2.start options,
* a process id, or the string “all” to indicate that all scripts should be restarted.
* @param errback
*/
export function describe(process: string|number, errback: ErrProcDescsCallback): void;
/**
* Gets the list of running processes being managed by pm2.
* @param errback
*/
export function list(errback: ErrProcDescsCallback): void;
/**
* Writes the process list to a json file at the path in the DUMP_FILE_PATH environment variable
* (“~/.pm2/dump.pm2” by default).
* @param errback
*/
export function dump(errback: ErrResultCallback): void;
/**
* Flushes the logs.
* @param process - Can either be the name as given in the pm2.start options,
* a process id, or the string “all” to indicate that all scripts should be restarted.
* @param errback
*/
export function flush(process: number|string, errback: ErrResultCallback): void;
/**
* @param errback
*/
export function dump(errback: ErrResultCallback): void;
/**
* Rotates the log files. The new log file will have a higher number
* in it (the default format being ${process.name}-${out|err}-${number}.log).
* @param errback
*/
export function reloadLogs(errback: ErrResultCallback): void;
/**
* Opens a message bus.
* @param errback The bus will be an Axon Sub Emitter object used to listen to and send events.
*/
export function launchBus(errback: ErrBusCallback): void;
/**
* @param signal
* @param process - Can either be the name as given in the pm2.start options,
* a process id, or the string “all” to indicate that all scripts should be restarted.
* @param errback
*/
export function sendSignalToProcessName(signal:string|number, process: number|string, errback: ErrResultCallback): void;
/**
* - Registers the script as a process that will start on machine boot. The current process list will be dumped and saved for resurrection on reboot.
* @param platform
* @param errback
*/
export function startup(platform: Platform, errback: ErrResultCallback): void;
/**
* - Send an set of data as object to a specific process
* @param proc_id
* @param packet
* @param cb
*/
export function sendDataToProcessId(proc_id: number, packet: object, cb: ErrResultCallback): void;
/**
* - Send an set of data as object to a specific process
* @param packet {id: number, type: 'process:msg', topic: true, data: object}
*/
export function sendDataToProcessId(packet: {id: number, type: 'process:msg', topic: true, data: object}): void;
/**
* Launch system monitoring (CPU, Memory usage)
* @param errback - Called when monitoring is launched
*/
export function launchSysMonitoring(errback?: ErrCallback): void;
/**
* Profile CPU or Memory usage
* @param type - 'cpu' for CPU profiling, 'mem' for memory profiling
* @param time - Duration in seconds (default: 10)
* @param errback - Called when profiling is complete
*/
export function profile(type: 'cpu' | 'mem', time?: number, errback?: ErrCallback): void;
/**
* Get process environment variables
* @param app_id - Process name or id
* @param errback - Called with environment variables
*/
export function env(app_id: string | number, errback?: ErrCallback): void;
/**
* Get process PID
* @param app_name - Process name (optional, returns all PIDs if not provided)
* @param errback - Called with PID information
*/
export function getPID(app_name?: string, errback?: ErrProcCallback): void;
/**
* Trigger a custom action on a process
* @param pm_id - Process id
* @param action_name - Name of the action to trigger
* @param params - Parameters to pass to the action
* @param errback - Called when action completes
*/
export function trigger(pm_id: string | number, action_name: string, params?: any, errback?: ErrCallback): void;
/**
* Inspect a process (debugging)
* @param app_name - Process name
* @param errback - Called with inspect information
*/
export function inspect(app_name: string, errback?: ErrCallback): void;
/**
* Serve static files
* @param path - Path to serve files from
* @param port - Port number (default: 8080)
* @param options - Serve options
* @param errback - Called when server starts
*/
export function serve(path?: string, port?: number, options?: ServeOptions, errback?: ErrCallback): void;
/**
* Install a PM2 module
* @param module_name - Name of the module to install
* @param options - Installation options
* @param errback - Called when installation completes
*/
export function install(module_name: string, options?: InstallOptions, errback?: ErrCallback): void;
/**
* Uninstall a PM2 module
* @param module_name - Name of the module to uninstall
* @param errback - Called when uninstallation completes
*/
export function uninstall(module_name: string, errback?: ErrCallback): void;
/**
* Send line to process stdin
* @param pm_id - Process id
* @param line - Line to send
* @param separator - Line separator (default: '\n')
* @param errback - Called when line is sent
*/
export function sendLineToStdin(pm_id: string | number, line: string, separator?: string, errback?: ErrCallback): void;
/**
* Attach to process logs
* @param pm_id - Process id
* @param separator - Log separator
* @param errback - Called when attached
*/
export function attach(pm_id: string | number, separator?: string, errback?: ErrCallback): void;
/**
* Get PM2 configuration value
* @param key - Configuration key (optional, returns all config if not provided)
* @param errback - Called with configuration value
*/
export function get(key?: string, errback?: ErrCallback): void;
/**
* Set PM2 configuration value
* @param key - Configuration key
* @param value - Configuration value
* @param errback - Called when value is set
*/
export function set(key: string, value: any, errback?: ErrCallback): void;
/**
* Set multiple PM2 configuration values
* @param values - Configuration values as string
* @param errback - Called when values are set
*/
export function multiset(values: string, errback?: ErrCallback): void;
/**
* Unset PM2 configuration value
* @param key - Configuration key to unset
* @param errback - Called when value is unset
*/
export function unset(key: string, errback?: ErrCallback): void;
// Interfaces
export interface Proc {
name?: string;
vizion?: boolean;
autorestart?: boolean;
exec_mode?: string;
exec_interpreter?: string;
pm_exec_path?: string;
pm_cwd?: string;
instances?: number;
node_args?: string[];
pm_out_log_path?: string;
pm_err_log_path?: string;
pm_pid_path?: string;
status?: string;
pm_uptime?: number;
axm_actions?: any[];
axm_monitor?: any;
axm_dynamic?: any;
vizion_running?: boolean;
created_at?: number;
pm_id?: number;
restart_time?: number;
unstable_restarts?: number;
started_inside?: boolean;
command?: Command;
versioning?: any;
exit_code?: number;
}
export interface Command {
locked?: boolean;
metadata?: any;
started_at?: any;
finished_at?: any;
error?: any;
}
/**
* An object with information about the process.
*/
export interface ProcessDescription {
/**
* The name given in the original start command.
*/
name?: string;
/**
* The pid of the process.
*/
pid?: number;
/**
* The pid for the pm2 God daemon process.
*/
pm_id?: number;
monit?: Monit;
/**
* The list of path variables in the process’s environment
*/
pm2_env?: Pm2Env;
}
interface Monit {
/**
* The number of bytes the process is using.
*/
memory?: number;
/**
* The percent of CPU being used by the process at the moment.
*/
cpu?: number;
}
/**
* The list of path variables in the process’s environment
*/
interface Pm2Env {
/**
* The working directory of the process.
*/
pm_cwd?: string;
/**
* The stdout log file path.
*/
pm_out_log_path?: string;
/**
* The stderr log file path.
*/
pm_err_log_path?: string;
/**
* The interpreter used.
*/
exec_interpreter?: string;
/**
* The uptime of the process.
*/
pm_uptime?: number;
/**
* The number of unstable restarts the process has been through.
*/
unstable_restarts?: number;
restart_time?: number;
status?: ProcessStatus;
/**
* The number of running instances.
*/
instances?: number | 'max';
/**
* The path of the script being run in this process.
*/
pm_exec_path?: string;
}
export interface StartOptions {
/**
* Enable or disable auto start after process added (default: true).
*/
autostart?: boolean;
/**
* Enable or disable auto restart after process failure (default: true).
*/
autorestart?: boolean;
/**
* List of exit codes that should allow the process to stop (skip autorestart).
*/
stop_exit_codes?: number[];
/**
* An arbitrary name that can be used to interact with (e.g. restart) the process
* later in other commands. Defaults to the script name without its extension
* (eg “testScript” for “testScript.js”)
*/
name?: string;
/**
* The path of the script to run
*/
script?: string;
/**
* A string or array of strings composed of arguments to pass to the script.
*/
args?: string | string[];
/**
* A string or array of strings composed of arguments to call the interpreter process with.
* Eg “–harmony” or [”–harmony”,”–debug”]. Only applies if interpreter is something other
* than “none” (its “node” by default).
*/
interpreter_args?: string | string[];
/**
* The working directory to start the process with.
*/
cwd?: string;
/**
* (Default: “~/.pm2/logs/app_name-out.log”) The path to a file to append stdout output to.
* Can be the same file as error.
*/
output?: string;
/**
* (Default: “~/.pm2/logs/app_name-error.err”) The path to a file to append stderr output to. Can be the same file as output.
*/
error?: string;
/**
* The display format for log timestamps (eg “YYYY-MM-DD HH:mm Z”). The format is a moment display format.
*/
log_date_format?: string;
/**
* Default: “~/.pm2/logs/~/.pm2/pids/app_name-id.pid”)
* The path to a file to write the pid of the started process. The file will be overwritten.
* Note that the file is not used in any way by pm2 and so the user is free to manipulate or
* remove that file at any time. The file will be deleted when the process is stopped or the daemon killed.
*/
pid?: string;
/**
* The minimum uptime of the script before it’s considered successfully started.
*/
min_uptime?: number;
/**
* The maximum number of times in a row a script will be restarted if it exits in less than min_uptime.
*/
max_restarts?: number;
/**
* If sets and script’s memory usage goes about the configured number, pm2 restarts the script.
* Uses human-friendly suffixes: ‘K’ for kilobytes, ‘M’ for megabytes, ‘G’ for gigabytes’, etc. Eg “150M”.
*/
max_memory_restart?: number | string;
/**
* Arguments to pass to the interpreter
*/
node_args?: string | string[];
/**
* Prefix logs with time
*/
time?: boolean;
/**
* This will make PM2 listen for that event. In your application you will need to add process.send('ready');
* when you want your application to be considered as ready.
*/
wait_ready?: boolean;
/**
* (Default: 1600)
* The number of milliseconds to wait after a stop or restart command issues a SIGINT signal to kill the
* script forceably with a SIGKILL signal.
*/
kill_timeout?: number;
/**
* (Default: 0) Number of millseconds to wait before restarting a script that has exited.
*/
restart_delay?: number;
/**
* (Default: “node”) The interpreter for your script (eg “python”, “ruby”, “bash”, etc).
* The value “none” will execute the ‘script’ as a binary executable.
*/
interpreter?: string;
/**
* (Default: ‘fork’) If sets to ‘cluster’, will enable clustering
* (running multiple instances of the script).
*/
exec_mode?: string;
/**
* (Default: 1) How many instances of script to create. Only relevant in exec_mode ‘cluster’.
*/
instances?: number;
/**
* (Default: false) If true, merges the log files for all instances of script into one stderr log
* and one stdout log. Only applies in ‘cluster’ mode. For example, if you have 4 instances of
* ‘test.js’ started via pm2, normally you would have 4 stdout log files and 4 stderr log files,
* but with this option set to true you would only have one stdout file and one stderr file.
*/
merge_logs?: boolean;
/**
* If set to true, the application will be restarted on change of the script file.
*/
watch?: boolean|string[];
/**
* (Default: false) By default, pm2 will only start a script if that script isn’t
* already running (a script is a path to an application, not the name of an application
* already running). If force is set to true, pm2 will start a new instance of that script.
*/
force?: boolean;
ignore_watch?: string[];
cron?: any;
execute_command?: any;
write?: any;
source_map_support?: any;
disable_source_map_support?: any;
/**
* Shortcut to inject a PORT environment variable.
*/
port?: number;
/**
* The environment variables to pass on to the process.
*/
env?: { [key: string]: string; };
/**
* NameSpace for the process
* @default 'default'
* @example 'production'
* @example 'development'
* @example 'staging'
*/
namespace?: string;
/**
* (Default: false) Exponential backoff restart delay in milliseconds.
* When enabled, PM2 will progressively increase restart delays after failures.
*/
exp_backoff_restart_delay?: number;
/**
* Timeout for application to be ready after reload (in milliseconds).
*/
listen_timeout?: number;
/**
* (Default: false) If true, shutdown the process using process.send('shutdown') instead of process.kill().
*/
shutdown_with_message?: boolean;
/**
* Environment variable name that gets incremented for each cluster instance.
*/
increment_var?: string;
/**
* Name of the environment variable holding the instance ID.
* @default 'NODE_APP_INSTANCE'
*/
instance_var?: string;
/**
* Filter out specific environment variables from the process.
* Can be true to filter all, or array/string of specific variables.
*/
filter_env?: boolean | string | string[];
/**
* (Default: false) Disable logs output.
*/
disable_logs?: boolean;
/**
* Log output type.
*/
log_type?: string;
/**
* (Default: false) Enable container mode.
*/
container?: boolean;
/**
* (Default: false) Distribution mode for Docker.
*/
dist?: boolean;
/**
* Docker image name.
*/
image_name?: string;
/**
* Node.js version for Docker container.
*/
node_version?: string;
/**
* (Default: false) Fresh install for Docker.
*/
fresh?: boolean;
/**
* (Default: false) Docker daemon mode.
*/
dockerdaemon?: boolean;
}
interface ReloadOptions {
/**
* (Default: false) If true is passed in, pm2 will reload it's environment from process.env
* before reloading your process.
*/
updateEnv?: boolean;
}
/**
* Options for serving static files
*/
export interface ServeOptions {
/**
* (Default: false) Single Page Application mode
*/
spa?: boolean;
/**
* Basic authentication username
*/
basic_auth_username?: string;
/**
* Basic authentication password
*/
basic_auth_password?: string;
/**
* Monitor URL path
*/
monitor?: string;
}
/**
* Options for Docker operations
*/
export interface DockerOptions {
/**
* Docker image name
*/
imageName?: string;
/**
* Node.js version to use
*/
nodeVersion?: string;
/**
* (Default: false) Fresh installation
*/
fresh?: boolean;
/**
* (Default: false) Force operation
*/
force?: boolean;
/**
* (Default: false) Docker daemon mode
*/
dockerdaemon?: boolean;
}
/**
* Options for module installation
*/
export interface InstallOptions {
/**
* (Default: false) Install from tarball
*/
tarball?: boolean;
/**
* (Default: true) Perform installation
*/
install?: boolean;
/**
* (Default: false) Docker mode
*/
docker?: boolean;
/**
* (Default: false) Use v1 API
*/
v1?: boolean;
/**
* (Default: false) Safe mode installation
*/
safe?: boolean | number;
}
// Types
type ProcessStatus = 'online' | 'stopping' | 'stopped' | 'launching' | 'errored' | 'one-launch-status' | 'waiting_restart';
type Platform = 'ubuntu' | 'centos' | 'redhat' | 'gentoo' | 'systemd' | 'darwin' | 'amazon';
type ErrCallback = (err: Error) => void;
type ErrProcCallback = (err: Error, proc: Proc) => void;
type ErrProcDescCallback = (err: Error, processDescription: ProcessDescription) => void;
type ErrProcDescsCallback = (err: Error, processDescriptionList: ProcessDescription[]) => void;
type ErrResultCallback = (err: Error, result: any) => void;
type ErrBusCallback = (err: Error, bus: any) => void;