Server IP : 85.214.239.14 / Your IP : 3.142.114.166 Web Server : Apache/2.4.62 (Debian) System : Linux h2886529.stratoserver.net 4.9.0 #1 SMP Tue Jan 9 19:45:01 MSK 2024 x86_64 User : www-data ( 33) PHP Version : 7.4.18 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, MySQL : OFF | cURL : OFF | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : OFF Directory : /proc/2/root/proc/3/task/3/root/lib/node_modules/pm2/node_modules/@pm2/agent/src/ |
Upload File : |
'use strict' const debug = require('debug')('interactor:watchdog') const child = require('child_process') const path = require('path') const RECONNECT_TENTATIVES_BEFORE_RESURRECT = 6 process.env.PM2_AGENT_ONLINE = true module.exports = class WatchDog { static start (p) { this.pm2_binary_path = p.pm2_binary_path this.ipm2 = p.conf.ipm2 this.relaunching = false this.autoDumpTime = 5 * 60 * 1000 /** * Handle PM2 connection state changes */ this.ipm2.on('ready', _ => { debug('Connected to PM2') this.relaunching = false this.autoDump() }) debug('Launching') this.reconnect_tentatives = 0 this.ipm2.on('reconnecting', _ => { debug('PM2 is disconnected - Relaunching PM2') if (this.dump_interval) { clearInterval(this.dump_interval) } if (this.reconnect_tentatives++ >= RECONNECT_TENTATIVES_BEFORE_RESURRECT && this.relaunching === false) { this.relaunching = true this.resurrect() } }) } static stop() { clearInterval(this.dump_interval) } static resurrect () { debug(`Trying to launch PM2: ${path.resolve(__dirname, '../../../../bin/pm2')}`) child.exec(`node ${this.pm2_binary_path} resurrect`, (err, sto, ste) => { if (err) console.error(err) console.log(sto, ste) this.reconnect_tentatives = 0 setTimeout(_ => { this.relaunching = false }, 10 * 1000) }) } static autoDump () { this.dump_interval = setInterval(_ => { if (this.relaunching === true) return this.ipm2.pm2Interface.dump(function (err) { return err ? debug('Error when dumping', err) : debug('PM2 process list dumped') }) }, this.autoDumpTime) } }