New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@pm2/agent

Package Overview
Dependencies
Maintainers
5
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@pm2/agent - npm Package Compare versions

Comparing version 0.5.13 to 0.5.14-next

4

constants.js

@@ -78,3 +78,5 @@ /**

SUCCESS_EXIT: 0,
ERROR_EXIT: 1
ERROR_EXIT: 1,
PM2_AGENT_ERROR_REPORT: useIfDefined(process.env.PM2_AGENT_ERROR_REPORT, true),
PM2_AGENT_REPORT_URI: 'https://608c72f27cc54035aff71b8a979b3b18@sentry.dev.pm2.io/3'
}

@@ -81,0 +83,0 @@

{
"name": "@pm2/agent",
"version": "0.5.13",
"version": "0.5.14-next",
"description": "PM2.io Agent Daemon",

@@ -22,2 +22,3 @@ "main": "index.js",

"fclone": "^1.0.11",
"find-process": "^1.1.3",
"handy-http": "^1.0.2",

@@ -28,4 +29,5 @@ "moment": "^2.21.0",

"pm2-axon-rpc": "^0.5.0",
"ws": "^5.1.0",
"semver": "^5.5.0"
"raven": "^2.6.3",
"semver": "^5.5.0",
"ws": "^5.1.0"
},

@@ -36,4 +38,4 @@ "devDependencies": {

"mocha": "^3.2",
"v8-coverage": "^1.0.4",
"nock": "^9.2.3"
"nock": "^9.2.3",
"v8-coverage": "^1.0.4"
},

@@ -40,0 +42,0 @@ "author": "Keymetrics Team",

@@ -12,2 +12,3 @@ 'use strict'

const childProcess = require('child_process')
const findProcess = require('find-process')

@@ -261,23 +262,39 @@ const printError = function (msg) {

/**
* Start or Restart the Interaction Daemon depending if its online or not
* @private
* Kill daemon via PID
* @param {Function} cb invoked with <processKilledCount>
*/
static killDuplicatedDaemonViaPID (cb) {
let processKilled = 0
findProcess('name', 'PM2 Agent').then((list) => {
list.map((daemonProcess) => {
if (process.pid === parseInt(daemonProcess.pid)) return log(`Ignored PID ${process.pid} (current process)`)
processKilled++
log(`Kill process with PID ${daemonProcess.pid}`)
return process.kill(daemonProcess.pid)
})
return cb(processKilled)
})
}
/**
* Kill existing daemon via RPC
* @param {Object} conf global constants
* @param {Object} infos data used to start the interactor [can be recovered from FS]
* @param {String} infos.secret_key the secret key used to cipher data
* @param {String} infos.public_key the public key used identify the user
* @param {String} infos.machine_name [optional] override name of the machine
* @param {Function} cb invoked with <err, msg, process>
* @param {Function} cb invoked with <err, killed>
*/
static launchOrAttach (conf, infos, cb) {
static killLaunchedDaemon (conf, cb) {
// Kill via RPC
this.ping(conf, (err, online) => {
if (!err && online) {
log('Interactor online, restarting it...')
this.launchRPC(conf, _ => {
log('Kill agent via RPC')
this.rpc.kill((ignoredErr) => {
this.daemonize(conf, infos, cb)
return this.killDuplicatedDaemonViaPID(_ => {
return cb(null, true)
})
})
})
} else {
log('Interactor offline, launching it...')
this.daemonize(conf, infos, cb)
return this.killDuplicatedDaemonViaPID((processKilled) => {
return cb(null, processKilled > 0)
})
}

@@ -288,2 +305,36 @@ })

/**
* Start or Restart the Interaction Daemon depending if its online or not
* @private
* @param {Object} conf global constants
* @param {Object} infos data used to start the interactor [can be recovered from FS]
* @param {String} infos.secret_key the secret key used to cipher data
* @param {String} infos.public_key the public key used identify the user
* @param {String} infos.machine_name [optional] override name of the machine
* @param {Function} cb invoked with <err, msg, process>
*/
static launchOrAttach (conf, infos, cb) {
this.killLaunchedDaemon(conf, (err, killed) => {
if (err) return cb(err)
log(`Interactor ${killed ? 'online, restarting' : 'offline, launching'} it...`)
return this.daemonize(conf, infos, cb)
})
}
/**
* Kill duplicated daemon and start a new one
* @param {Object} conf global constants
* @param {Object} infos data used to start the interactor [can be recovered from FS]
* @param {String} infos.secret_key the secret key used to cipher data
* @param {String} infos.public_key the public key used identify the user
* @param {String} infos.machine_name [optional] override name of the machine
* @param {Function} cb invoked with <err, msg, process>
*/
static forceLaunch (conf, infos, cb) {
this.killDuplicatedDaemonViaPID((processesKilled) => {
log(`Force launch interactor (${processesKilled} processes killed)`)
return this.daemonize(conf, infos, cb)
})
}
/**
* Restart the Interactor Daemon

@@ -453,3 +504,8 @@ * @param {Object} conf global constants

}
return this.launchOrAttach(cst, conf, cb)
if (cst && cst.HAS_CRASHED) {
return this.forceLaunch(cst, conf, cb)
} else {
return this.launchOrAttach(cst, conf, cb)
}
})

@@ -456,0 +512,0 @@ }

@@ -20,2 +20,3 @@ 'use strict'

const pkg = require('../package.json')
const raven = require('raven')

@@ -49,2 +50,8 @@ // use noop if not launched via IPC

this._internalDebugger()
if (cst.PM2_AGENT_ERROR_REPORT === true) {
log('Starting sentry integration')
raven.config(cst.PM2_AGENT_REPORT_URI, {
release: pkg.version
}).install()
}
}

@@ -396,21 +403,15 @@

console.log('Re-initiating Agent')
delete process.env.PM2_AGENT_ONLINE
InteractorClient.getOrSetConf(cst, null, (err, infos) => {
if (err || !infos) {
if (err) {
console.error('[PM2 Agent] Failed to rescue agent :')
console.error(err || new Error(`Cannot find configuration to connect to backend`))
return process.exit(1)
}
if (cst.PM2_AGENT_ERROR_REPORT === true) {
raven.captureException(err)
}
InteractorClient.launchAndInteract({HAS_CRASHED: true}, null, (err) => {
if (err) {
console.error('Failed to rescue agent:', err)
return process.exit(1)
}
console.log(`[PM2 Agent] Using (Public key: ${infos.public_key}) (Private key: ${infos.secret_key}) (Info node: ${infos.info_node})`)
InteractorClient.daemonize(cst, infos, (err) => {
if (err) {
log('[PM2 Agent] Failed to rescue agent :')
log(err)
} else {
log(`Succesfully launched new agent`)
}
daemon.exit(err)
})
console.log('Agent launched!')
return process.exit(0)
})

@@ -417,0 +418,0 @@ })

@@ -68,5 +68,7 @@ 'use strict'

if (!transport.isConnected()) {
log(`Transporters are not connected, connect them with: ${JSON.stringify(endpoints)}`)
transport.connect(this._buildConnectParamsFromEndpoints(name, endpoints), next)
// Endpoints have changed, reconnect
} else if (JSON.stringify(endpoints) !== JSON.stringify(this.endpoints)) {
log(`Received new endpoints to connect transporters: ${JSON.stringify(endpoints)}`)
transport.reconnect(this._buildConnectParamsFromEndpoints(name, endpoints), next)

@@ -73,0 +75,0 @@ // No changes

@@ -106,2 +106,3 @@ 'use strict'

// Connect to interaction/reverse server
log(`Connect axon with ${pushHost}:${pushPort} and nssocket with ${pullHost}:${pullPort}`)
async.parallel([

@@ -184,2 +185,3 @@ (next) => this._axon.connect(parseInt(pushPort), pushHost, next),

preparePacket (next) {
if (typeof this._daemon.getPM2Client().rpc.getMonitorData !== 'function') return next(new Error('Not able to connect to PM2'))
this._daemon.getPM2Client().rpc.getMonitorData({}, (err, processes) => {

@@ -186,0 +188,0 @@ if (err || !processes) return next(err || new Error('Not able to retrieve PM2 processes'))

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc