forked from acuminous/bosco
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathps.js
83 lines (68 loc) · 2.2 KB
/
ps.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
var async = require('async');
var Table = require('cli-table');
var _ = require('lodash');
var NodeRunner = require('../src/RunWrappers/Node');
var DockerRunner = require('../src/RunWrappers/Docker');
var nodeList = [];
var dockerList = [];
module.exports = {
name: 'ps',
description: 'Lists all running services',
};
function cmd(bosco) {
function initialiseRunners(next) {
var runners = [NodeRunner, DockerRunner];
async.map(runners, function loadRunner(runner, cb) {
runner.init(bosco, cb);
}, next);
}
function getRunningServices(next) {
NodeRunner.listRunning(true, function(err, nodeRunning) {
if (err) return next(err);
nodeList = nodeRunning;
DockerRunner.list(true, function(err, dockerRunning) {
if (err) return next(err);
dockerList = dockerRunning;
next();
});
});
}
function printNodeServices(name, list) {
var table = new Table({
chars: {'mid': '', 'left-mid': '', 'mid-mid': '', 'right-mid': ''},
head: [name + ' Service', 'PID', 'Status', 'Mode', 'Watch'],
colWidths: [60, 10, 10, 12, 10],
});
list.forEach(function(item) {
table.push([item.name, item.pid, item.pm2_env.status, item.pm2_env.exec_mode, item.pm2_env.watch || '']);
});
bosco.console.log(table.toString());
bosco.console.log('\r');
}
function printDockerServices(name, list) {
var table = new Table({
chars: {'mid': '', 'left-mid': '', 'mid-mid': '', 'right-mid': ''},
head: [name + ' Service', 'Status', 'FQN'],
colWidths: [25, 20, 60],
});
list.forEach(function(item) {
table.push([
_.map(item.Names, function(i) { return i.replace('/', ''); }).join(', '),
item.Status,
item.Image,
]);
});
bosco.console.log(table.toString());
bosco.console.log('\r');
}
bosco.log('Getting running microservices ...');
async.series([initialiseRunners, getRunningServices], function() {
bosco.console.log('');
bosco.log('Running NodeJS Services (via PM2):');
printNodeServices('Node', nodeList);
bosco.log('Running Docker Images:');
printDockerServices('Docker', dockerList);
process.exit(0);
});
}
module.exports.cmd = cmd;