mirror of
https://github.com/Unitech/pm2.git
synced 2025-12-08 20:35:53 +00:00
feat: add service detection system + disable docker container listing by default
This commit is contained in:
parent
8f00e37597
commit
79a6a2d2ea
5
bin/pm2
5
bin/pm2
@ -967,6 +967,11 @@ commander.command('serve [path] [port]')
|
||||
pm2.serve(path, port || cmd.port, cmd, commander);
|
||||
});
|
||||
|
||||
commander.command('autoinstall')
|
||||
.action(function() {
|
||||
pm2.autoinstall()
|
||||
})
|
||||
|
||||
commander.command('examples')
|
||||
.description('display pm2 usage examples')
|
||||
.action(() => {
|
||||
|
||||
@ -11,6 +11,7 @@ var Common = require('../Common');
|
||||
var Spinner = require('./Spinner.js');
|
||||
var UX = module.exports = {};
|
||||
var Passwd = require('../tools/passwd.js')
|
||||
var Configuration = require('../Configuration.js')
|
||||
|
||||
/**
|
||||
* Description
|
||||
@ -235,6 +236,8 @@ UX.describeTable = function(proc) {
|
||||
* @return
|
||||
*/
|
||||
UX.dispAsTable = function(list, sys_infos) {
|
||||
var pm2_conf = Configuration.getSync('pm2')
|
||||
|
||||
var condensed_mode = (process.stdout.columns || 300) < 120
|
||||
var app_head = {
|
||||
id: 4,
|
||||
@ -469,7 +472,8 @@ UX.dispAsTable = function(list, sys_infos) {
|
||||
|
||||
proc_id++
|
||||
// Container display
|
||||
if (sys_infos && sys_infos.containers && sys_infos.containers.length > 0) {
|
||||
if (sys_infos && sys_infos.containers && sys_infos.containers.length > 0 &&
|
||||
(pm2_conf && pm2_conf.show_docker == "true")) {
|
||||
var stacked_docker = (process.stdout.columns || 100) < 140
|
||||
|
||||
var docker_head = {
|
||||
|
||||
@ -428,6 +428,21 @@ module.exports = function(CLI) {
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* API method to launch a process that will serve directory over http
|
||||
*/
|
||||
CLI.prototype.autoinstall = function (cb) {
|
||||
var filepath = path.resolve(path.dirname(module.filename), '../Sysinfo/ServiceDetection/ServiceDetection.js');
|
||||
|
||||
this.start(filepath, (err, res) => {
|
||||
if (err) {
|
||||
Common.printError(cst.PREFIX_MSG_ERR + 'Error while trying to serve : ' + err.message || err);
|
||||
return cb ? cb(err) : this.speedList(cst.ERROR_EXIT);
|
||||
}
|
||||
return cb ? cb(null) : this.speedList();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* API method to launch a process that will serve directory over http
|
||||
*
|
||||
|
||||
@ -253,7 +253,7 @@ function continueInstall(CLI, module_name, opts, cb) {
|
||||
|
||||
CLI.conf(canonic_module_name, function() {
|
||||
Common.printOut(cst.PREFIX_MSG_MOD + 'Module successfully installed and launched');
|
||||
Common.printOut(cst.PREFIX_MSG_MOD + 'Edit configuration via: `pm2 conf`');
|
||||
Common.printOut(cst.PREFIX_MSG_MOD + 'Checkout module options: `$ pm2 conf`');
|
||||
return cb(null, dt);
|
||||
});
|
||||
});
|
||||
|
||||
119
lib/Sysinfo/ServiceDetection/ServiceDetection.js
Normal file
119
lib/Sysinfo/ServiceDetection/ServiceDetection.js
Normal file
@ -0,0 +1,119 @@
|
||||
|
||||
const PM2 = require('./../../API.js')
|
||||
const psList = require('../psList.js')
|
||||
const _ = require('lodash')
|
||||
|
||||
const SERVICES_ASSOCIATION = {
|
||||
'mongodb,mongo': {
|
||||
module: 'pm2-mongodb'
|
||||
},
|
||||
'redis,redis-server': {
|
||||
module: 'pm2-redis'
|
||||
},
|
||||
'elasticsearch': {
|
||||
module: 'pm2-elasticsearch'
|
||||
},
|
||||
'docker': {
|
||||
module: 'pm2-monit-docker'
|
||||
},
|
||||
'consul': {
|
||||
module:'pm2-monit-consul'
|
||||
},
|
||||
'pm2': {
|
||||
module: 'pm2-probe'
|
||||
},
|
||||
'fpm': {
|
||||
module: 'pm2-php-fpm'
|
||||
}
|
||||
}
|
||||
|
||||
// 'python,python3': {
|
||||
// module: 'pm2-python'
|
||||
// },
|
||||
// 'nginx': {
|
||||
// module: 'pm2-monit-nginx'
|
||||
// },
|
||||
// 'haproxy': {
|
||||
// module: 'pm2-monit-haproxy'
|
||||
// },
|
||||
// 'traeffik': {
|
||||
// module: 'pm2-monit-traeffik'
|
||||
// }
|
||||
|
||||
class ServicesDetection {
|
||||
constructor() {
|
||||
this.pm2 = new PM2()
|
||||
}
|
||||
|
||||
startDetection(cb = () => {}) {
|
||||
// Check running probes
|
||||
this.monitoredServices((err, pm2_services) => {
|
||||
// Check running services
|
||||
this.discover((err, required_modules) => {
|
||||
var required_monitoring_probes = Object.keys(required_modules)
|
||||
// Make the diff between
|
||||
console.log(`Need to start following modules:`)
|
||||
console.log(_.difference(required_monitoring_probes, pm2_services))
|
||||
this.pm2.install('pm2-server-monit', (err, apps) => {
|
||||
cb()
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
monitoredServices(cb) {
|
||||
var f_proc_list = []
|
||||
|
||||
this.pm2.list((err, proc_list) => {
|
||||
f_proc_list = proc_list.map(p => {
|
||||
return p.name
|
||||
})
|
||||
this.pm2.close()
|
||||
cb(err, f_proc_list)
|
||||
})
|
||||
}
|
||||
|
||||
discover(cb) {
|
||||
psList()
|
||||
.then(processes => {
|
||||
var supported_systems = Object.keys(SERVICES_ASSOCIATION)
|
||||
var required_modules = {}
|
||||
|
||||
processes.forEach((proc) => {
|
||||
supported_systems.forEach(sup_sys => {
|
||||
var proc_names = sup_sys.split(',')
|
||||
proc_names.forEach(proc_name => {
|
||||
if (proc.name.includes(proc_name) === true ||
|
||||
proc.cmd.includes(proc_name) === true) {
|
||||
var key = SERVICES_ASSOCIATION[sup_sys].module
|
||||
required_modules[key] = SERVICES_ASSOCIATION[sup_sys]
|
||||
required_modules[key].monit = proc
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
return cb(null, required_modules)
|
||||
})
|
||||
.catch(e => {
|
||||
console.error(`Error while listing processes`, e)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
if (require.main === module) {
|
||||
var serviceDetection = new ServicesDetection()
|
||||
|
||||
var process = (done) => {
|
||||
serviceDetection.startDetection((err, procs) => {
|
||||
done()
|
||||
})
|
||||
}
|
||||
|
||||
var iterate = () => {
|
||||
process(() => {
|
||||
setTimeout(iterate, 3000)
|
||||
})
|
||||
}
|
||||
|
||||
iterate()
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user