UNPKG

15.5 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 * An arbitrary name that can be used to interact with (e.g. restart) the process
310 * later in other commands. Defaults to the script name without its extension
311 * (eg “testScript” for “testScript.js”)
312 */
313 name?: string;
314 /**
315 * The path of the script to run
316 */
317 script?: string;
318 /**
319 * A string or array of strings composed of arguments to pass to the script.
320 */
321 args?: string | string[];
322 /**
323 * A string or array of strings composed of arguments to call the interpreter process with.
324 * Eg “–harmony” or [”–harmony”,”–debug”]. Only applies if interpreter is something other
325 * than “none” (its “node” by default).
326 */
327 interpreter_args?: string | string[];
328 /**
329 * The working directory to start the process with.
330 */
331 cwd?: string;
332 /**
333 * (Default: “~/.pm2/logs/app_name-out.log”) The path to a file to append stdout output to.
334 * Can be the same file as error.
335 */
336 output?: string;
337 /**
338 * (Default: “~/.pm2/logs/app_name-error.err”) The path to a file to append stderr output to. Can be the same file as output.
339 */
340 error?: string;
341 /**
342 * The display format for log timestamps (eg “YYYY-MM-DD HH:mm Z”). The format is a moment display format.
343 */
344 log_date_format?: string;
345 /**
346 * Default: “~/.pm2/logs/~/.pm2/pids/app_name-id.pid”)
347 * The path to a file to write the pid of the started process. The file will be overwritten.
348 * Note that the file is not used in any way by pm2 and so the user is free to manipulate or
349 * remove that file at any time. The file will be deleted when the process is stopped or the daemon killed.
350 */
351 pid?: string;
352 /**
353 * The minimum uptime of the script before it’s considered successfully started.
354 */
355 min_uptime?: number;
356 /**
357 * The maximum number of times in a row a script will be restarted if it exits in less than min_uptime.
358 */
359 max_restarts?: number;
360 /**
361 * If sets and script’s memory usage goes about the configured number, pm2 restarts the script.
362 * Uses human-friendly suffixes: ‘K’ for kilobytes, ‘M’ for megabytes, ‘G’ for gigabytes’, etc. Eg “150M”.
363 */
364 max_memory_restart?: number | string;
365 /**
366 * This will make PM2 listen for that event. In your application you will need to add process.send('ready');
367 * when you want your application to be considered as ready.
368 */
369 wait_ready?: boolean;
370 /**
371 * (Default: 1600)
372 * The number of milliseconds to wait after a stop or restart command issues a SIGINT signal to kill the
373 * script forceably with a SIGKILL signal.
374 */
375 kill_timeout?: number;
376 /**
377 * (Default: 0) Number of millseconds to wait before restarting a script that has exited.
378 */
379 restart_delay?: number;
380 /**
381 * (Default: “node”) The interpreter for your script (eg “python”, “ruby”, “bash”, etc).
382 * The value “none” will execute the ‘script’ as a binary executable.
383 */
384 interpreter?: string;
385 /**
386 * (Default: ‘fork’) If sets to ‘cluster’, will enable clustering
387 * (running multiple instances of the script).
388 */
389 exec_mode?: string;
390 /**
391 * (Default: 1) How many instances of script to create. Only relevant in exec_mode ‘cluster’.
392 */
393 instances?: number;
394 /**
395 * (Default: false) If true, merges the log files for all instances of script into one stderr log
396 * and one stdout log. Only applies in ‘cluster’ mode. For example, if you have 4 instances of
397 * ‘test.js’ started via pm2, normally you would have 4 stdout log files and 4 stderr log files,
398 * but with this option set to true you would only have one stdout file and one stderr file.
399 */
400 merge_logs?: boolean;
401 /**
402 * If set to true, the application will be restarted on change of the script file.
403 */
404 watch?: boolean|string[];
405 /**
406 * (Default: false) By default, pm2 will only start a script if that script isn’t
407 * already running (a script is a path to an application, not the name of an application
408 * already running). If force is set to true, pm2 will start a new instance of that script.
409 */
410 force?: boolean;
411 ignore_watch?: string[];
412 cron?: any;
413 execute_command?: any;
414 write?: any;
415 source_map_support?: any;
416 disable_source_map_support?: any;
417 /**
418 * The environment variables to pass on to the process.
419 */
420 env?: { [key: string]: string; };
421}
422
423interface ReloadOptions {
424 /**
425 * (Default: false) If true is passed in, pm2 will reload it’s environment from process.env
426 * before reloading your process.
427 */
428 updateEnv?: boolean;
429}
430
431// Types
432
433type ProcessStatus = 'online' | 'stopping' | 'stopped' | 'launching' | 'errored' | 'one-launch-status';
434type Platform = 'ubuntu' | 'centos' | 'redhat' | 'gentoo' | 'systemd' | 'darwin' | 'amazon';
435
436type ErrCallback = (err: Error) => void;
437type ErrProcCallback = (err: Error, proc: Proc) => void;
438type ErrProcDescCallback = (err: Error, processDescription: ProcessDescription) => void;
439type ErrProcDescsCallback = (err: Error, processDescriptionList: ProcessDescription[]) => void;
440type ErrResultCallback = (err: Error, result: any) => void;
441type ErrBusCallback = (err: Error, bus: any) => void;