UNPKG

16.1 kBTypeScriptView Raw
1// Type definitions for pm2 2.7.1
2// Definitions by: João Portela https://www.github.com/jportela
3
4// Exported Methods
5
6/**
7 * Either connects to a running pm2 daemon (“God”) or launches and daemonizes one.
8 * Once launched, the pm2 process will keep running after the script exits.
9 * @param errback - Called when finished connecting to or launching the pm2 daemon process.
10 */
11export function connect(errback: ErrCallback): void;
12/**
13 * Either connects to a running pm2 daemon (“God”) or launches and daemonizes one.
14 * Once launched, the pm2 process will keep running after the script exits.
15 * @param noDaemonMode - (Default: false) If true is passed for the first argument
16 * pm2 will not be run as a daemon and will die when the related script exits.
17 * By default, pm2 stays alive after your script exits.
18 * If pm2 is already running, your script will link to the existing daemon but will die once your process exits.
19 * @param errback - Called when finished connecting to or launching the pm2 daemon process.
20 */
21export function connect(noDaemonMode:boolean, errback: ErrCallback): void;
22
23/**
24 * Starts a script that will be managed by pm2.
25 * @param options - Options
26 * @param errback - An errback called when the script has been started.
27 * The proc parameter will be a pm2 process object.
28 */
29export function start(options: StartOptions, errback: ErrProcCallback): void;
30/**
31 * Starts a script that will be managed by pm2.
32 * @param jsonConfigFile - The path to a JSON file that can contain the same options as the options parameter.
33 * @param errback - An errback called when the script has been started.
34 * The proc parameter will be a pm2 process object.
35 */
36export function start(jsonConfigFile: string, errback: ErrProcCallback): void;
37/**
38 * Starts a script that will be managed by pm2.
39 * @param script - The path of the script to run.
40 * @param errback - An errback called when the script has been started.
41 * The proc parameter will be a pm2 process object.
42 */
43export function start(script: string , errback: ErrProcCallback): void;
44/**
45 * Starts a script that will be managed by pm2.
46 * @param script - The path of the script to run.
47 * @param options - Options
48 * @param errback - An errback called when the script has been started.
49 * The proc parameter will be a pm2 process object.
50 */
51export function start(script: string, options: StartOptions, errback: ErrProcCallback): void;
52/**
53 * Starts a script that will be managed by pm2.
54 * @param script - The path of the script to run.
55 * @param jsonConfigFile - The path to a JSON file that can contain the same options as the options parameter.
56 * @param errback - An errback called when the script has been started.
57 * The proc parameter will be a pm2 process object.
58 */
59export function start(script: string, jsonConfigFile: string, errback: ErrProcCallback): void;
60
61/**
62 * Disconnects from the pm2 daemon.
63 */
64export function disconnect(): void;
65
66/**
67 * Stops a process but leaves the process meta-data in pm2’s list
68 * @param process - Can either be the name as given in the pm2.start options,
69 * a process id, or the string “all” to indicate that all scripts should be restarted.
70 * @param errback - called when the process is stopped
71 */
72export function stop(process: string|number, errback: ErrProcCallback): void;
73
74/**
75 * Stops and restarts the process.
76 * @param process - Can either be the name as given in the pm2.start options,
77 * a process id, or the string “all” to indicate that all scripts should be restarted.
78 * @param errback - called when the process is restarted
79 */
80export function restart(process: string|number, errback: ErrProcCallback): void;
81
82/**
83 * Stops the process and removes it from pm2’s list.
84 * The process will no longer be accessible by its name
85 * @param process - Can either be the name as given in the pm2.start options,
86 * a process id, or the string “all” to indicate that all scripts should be restarted.
87 * @param errback - called when the process is deleted
88 */
89declare function del(process: string|number, errback: ErrProcCallback): void;
90// have to use this construct because `delete` is a reserved word
91export {del as delete};
92
93/**
94 * Zero-downtime rolling restart. At least one process will be kept running at
95 * all times as each instance is restarted individually.
96 * Only works for scripts started in cluster mode.
97 * @param process - Can either be the name as given in the pm2.start options,
98 * a process id, or the string “all” to indicate that all scripts should be restarted.
99 * @param errback - called when the process is reloaded
100 */
101export function reload(process: string|number, errback: ErrProcCallback): void;
102
103/**
104 * Zero-downtime rolling restart. At least one process will be kept running at
105 * all times as each instance is restarted individually.
106 * Only works for scripts started in cluster mode.
107 * @param process - Can either be the name as given in the pm2.start options,
108 * a process id, or the string “all” to indicate that all scripts should be restarted.
109 * @param options - An object containing configuration
110 * @param options.updateEnv - (Default: false) If true is passed in, pm2 will reload it’s
111 * environment from process.env before reloading your process.
112 * @param errback - called when the process is reloaded
113 */
114export function reload(process: string|number, options: ReloadOptions, errback: ErrProcCallback): void;
115
116/**
117 * Kills the pm2 daemon (same as pm2 kill). Note that when the daemon is killed, all its
118 * processes are also killed. Also note that you still have to explicitly disconnect
119 * from the daemon even after you kill it.
120 * @param errback
121 */
122export function killDaemon(errback: ErrProcDescCallback): void;
123
124/**
125 * Returns various information about a process: eg what stdout/stderr and pid files are used.
126 * @param process - Can either be the name as given in the pm2.start options,
127 * a process id, or the string “all” to indicate that all scripts should be restarted.
128 * @param errback
129 */
130export function describe(process: string|number, errback: ErrProcDescsCallback): void;
131
132/**
133 * Gets the list of running processes being managed by pm2.
134 * @param errback
135 */
136export function list(errback: ErrProcDescsCallback): void;
137
138/**
139 * Writes the process list to a json file at the path in the DUMP_FILE_PATH environment variable
140 * (“~/.pm2/dump.pm2” by default).
141 * @param errback
142 */
143export function dump(errback: ErrResultCallback): void;
144
145/**
146 * Flushes the logs.
147 * @param process - Can either be the name as given in the pm2.start options,
148 * a process id, or the string “all” to indicate that all scripts should be restarted.
149 * @param errback
150 */
151export function flush(process: number|string, errback: ErrResultCallback): void;
152
153/**
154 * @param errback
155 */
156export function dump(errback: ErrResultCallback): void;
157
158/**
159 * Rotates the log files. The new log file will have a higher number
160 * in it (the default format being ${process.name}-${out|err}-${number}.log).
161 * @param errback
162 */
163export function reloadLogs(errback: ErrResultCallback): void;
164
165/**
166 * Opens a message bus.
167 * @param errback The bus will be an Axon Sub Emitter object used to listen to and send events.
168 */
169export function launchBus(errback: ErrBusCallback): void;
170
171/**
172 * @param signal
173 * @param process - Can either be the name as given in the pm2.start options,
174 * a process id, or the string “all” to indicate that all scripts should be restarted.
175 * @param errback
176 */
177export function sendSignalToProcessName(signal:string|number, process: number|string, errback: ErrResultCallback): void;
178
179/**
180 * - 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.
181 * @param platform
182 * @param errback
183 */
184export function startup(platform: Platform, errback: ErrResultCallback): void;
185
186/**
187 * - Send an set of data as object to a specific process
188 * @param proc_id
189 * @param packet
190 * @param cb
191 */
192export function sendDataToProcessId(proc_id: number, packet: object, cb: ErrResultCallback): void;
193
194// Interfaces
195
196export interface Proc {
197 name?: string;
198 vizion?: boolean;
199 autorestart?: boolean;
200 exec_mode?: string;
201 exec_interpreter?: string;
202 pm_exec_path?: string;
203 pm_cwd?: string;
204 instances?: number;
205 node_args?: string[];
206 pm_out_log_path?: string;
207 pm_err_log_path?: string;
208 pm_pid_path?: string;
209 status?: string;
210 pm_uptime?: number;
211 axm_actions?: any[];
212 axm_monitor?: any;
213 axm_dynamic?: any;
214 vizion_running?: boolean;
215 created_at?: number;
216 pm_id?: number;
217 restart_time?: number;
218 unstable_restarts?: number;
219 started_inside?: boolean;
220 command?: Command;
221 versioning?: any;
222 exit_code?: number;
223}
224
225export interface Command {
226 locked?: boolean;
227 metadata?: any;
228 started_at?: any;
229 finished_at?: any;
230 error?: any;
231}
232
233/**
234 * An object with information about the process.
235 */
236export interface ProcessDescription {
237 /**
238 * The name given in the original start command.
239 */
240 name?: string;
241 /**
242 * The pid of the process.
243 */
244 pid?: number;
245 /**
246 * The pid for the pm2 God daemon process.
247 */
248 pm_id?: number;
249 monit?: Monit;
250 /**
251 * The list of path variables in the process’s environment
252 */
253 pm2_env?: Pm2Env;
254}
255
256interface Monit {
257 /**
258 * The number of bytes the process is using.
259 */
260 memory?: number;
261 /**
262 * The percent of CPU being used by the process at the moment.
263 */
264 cpu?: number;
265}
266
267/**
268 * The list of path variables in the process’s environment
269 */
270interface Pm2Env {
271 /**
272 * The working directory of the process.
273 */
274 pm_cwd?: string;
275 /**
276 * The stdout log file path.
277 */
278 pm_out_log_path?: string;
279 /**
280 * The stderr log file path.
281 */
282 pm_err_log_path?: string;
283 /**
284 * The interpreter used.
285 */
286 exec_interpreter?: string;
287 /**
288 * The uptime of the process.
289 */
290 pm_uptime?: number;
291 /**
292 * The number of unstable restarts the process has been through.
293 */
294 unstable_restarts?: number;
295 restart_time?: number;
296 status?: ProcessStatus;
297 /**
298 * The number of running instances.
299 */
300 instances?: number | 'max';
301 /**
302 * The path of the script being run in this process.
303 */
304 pm_exec_path?: string;
305}
306
307export interface StartOptions {
308 /**
309 * Enable or disable auto start after process added (default: true).
310 */
311 autostart?: boolean;
312 /**
313 * Enable or disable auto restart after process failure (default: true).
314 */
315 autorestart?: boolean;
316 /**
317 * List of exit codes that should allow the process to stop (skip autorestart).
318 */
319 stop_exit_codes?: number[];
320 /**
321 * An arbitrary name that can be used to interact with (e.g. restart) the process
322 * later in other commands. Defaults to the script name without its extension
323 * (eg “testScript” for “testScript.js”)
324 */
325 name?: string;
326 /**
327 * The path of the script to run
328 */
329 script?: string;
330 /**
331 * A string or array of strings composed of arguments to pass to the script.
332 */
333 args?: string | string[];
334 /**
335 * A string or array of strings composed of arguments to call the interpreter process with.
336 * Eg “–harmony” or [”–harmony”,”–debug”]. Only applies if interpreter is something other
337 * than “none” (its “node” by default).
338 */
339 interpreter_args?: string | string[];
340 /**
341 * The working directory to start the process with.
342 */
343 cwd?: string;
344 /**
345 * (Default: “~/.pm2/logs/app_name-out.log”) The path to a file to append stdout output to.
346 * Can be the same file as error.
347 */
348 output?: string;
349 /**
350 * (Default: “~/.pm2/logs/app_name-error.err”) The path to a file to append stderr output to. Can be the same file as output.
351 */
352 error?: string;
353 /**
354 * The display format for log timestamps (eg “YYYY-MM-DD HH:mm Z”). The format is a moment display format.
355 */
356 log_date_format?: string;
357 /**
358 * Default: “~/.pm2/logs/~/.pm2/pids/app_name-id.pid”)
359 * The path to a file to write the pid of the started process. The file will be overwritten.
360 * Note that the file is not used in any way by pm2 and so the user is free to manipulate or
361 * remove that file at any time. The file will be deleted when the process is stopped or the daemon killed.
362 */
363 pid?: string;
364 /**
365 * The minimum uptime of the script before it’s considered successfully started.
366 */
367 min_uptime?: number;
368 /**
369 * The maximum number of times in a row a script will be restarted if it exits in less than min_uptime.
370 */
371 max_restarts?: number;
372 /**
373 * If sets and script’s memory usage goes about the configured number, pm2 restarts the script.
374 * Uses human-friendly suffixes: ‘K’ for kilobytes, ‘M’ for megabytes, ‘G’ for gigabytes’, etc. Eg “150M”.
375 */
376 max_memory_restart?: number | string;
377 /**
378 * Arguments to pass to the interpreter
379 */
380 node_args?: string | string[];
381 /**
382 * Prefix logs with time
383 */
384 time?: boolean;
385 /**
386 * This will make PM2 listen for that event. In your application you will need to add process.send('ready');
387 * when you want your application to be considered as ready.
388 */
389 wait_ready?: boolean;
390 /**
391 * (Default: 1600)
392 * The number of milliseconds to wait after a stop or restart command issues a SIGINT signal to kill the
393 * script forceably with a SIGKILL signal.
394 */
395 kill_timeout?: number;
396 /**
397 * (Default: 0) Number of millseconds to wait before restarting a script that has exited.
398 */
399 restart_delay?: number;
400 /**
401 * (Default: “node”) The interpreter for your script (eg “python”, “ruby”, “bash”, etc).
402 * The value “none” will execute the ‘script’ as a binary executable.
403 */
404 interpreter?: string;
405 /**
406 * (Default: ‘fork’) If sets to ‘cluster’, will enable clustering
407 * (running multiple instances of the script).
408 */
409 exec_mode?: string;
410 /**
411 * (Default: 1) How many instances of script to create. Only relevant in exec_mode ‘cluster’.
412 */
413 instances?: number;
414 /**
415 * (Default: false) If true, merges the log files for all instances of script into one stderr log
416 * and one stdout log. Only applies in ‘cluster’ mode. For example, if you have 4 instances of
417 * ‘test.js’ started via pm2, normally you would have 4 stdout log files and 4 stderr log files,
418 * but with this option set to true you would only have one stdout file and one stderr file.
419 */
420 merge_logs?: boolean;
421 /**
422 * If set to true, the application will be restarted on change of the script file.
423 */
424 watch?: boolean|string[];
425 /**
426 * (Default: false) By default, pm2 will only start a script if that script isn’t
427 * already running (a script is a path to an application, not the name of an application
428 * already running). If force is set to true, pm2 will start a new instance of that script.
429 */
430 force?: boolean;
431 ignore_watch?: string[];
432 cron?: any;
433 execute_command?: any;
434 write?: any;
435 source_map_support?: any;
436 disable_source_map_support?: any;
437 /**
438 * The environment variables to pass on to the process.
439 */
440 env?: { [key: string]: string; };
441 /**
442 * NameSpace for the process
443 * @default 'default'
444 * @example 'production'
445 * @example 'development'
446 * @example 'staging'
447 */
448 namespace?: string;
449}
450
451interface ReloadOptions {
452 /**
453 * (Default: false) If true is passed in, pm2 will reload it’s environment from process.env
454 * before reloading your process.
455 */
456 updateEnv?: boolean;
457}
458
459// Types
460
461type ProcessStatus = 'online' | 'stopping' | 'stopped' | 'launching' | 'errored' | 'one-launch-status';
462type Platform = 'ubuntu' | 'centos' | 'redhat' | 'gentoo' | 'systemd' | 'darwin' | 'amazon';
463
464type ErrCallback = (err: Error) => void;
465type ErrProcCallback = (err: Error, proc: Proc) => void;
466type ErrProcDescCallback = (err: Error, processDescription: ProcessDescription) => void;
467type ErrProcDescsCallback = (err: Error, processDescriptionList: ProcessDescription[]) => void;
468type ErrResultCallback = (err: Error, result: any) => void;
469type ErrBusCallback = (err: Error, bus: any) => void;