-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathapp.js
73 lines (58 loc) · 1.49 KB
/
app.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
var pmx = require('pmx');
var pm2 = require('pm2');
var async = require('async');
var pkg = require('./package.json');
var Probe = pmx.probe();
var app_updated = Probe.counter({
name : 'Updates'
});
function autoPull(cb) {
pm2.list(function(err, procs) {
if (err) return console.error(err);
async.forEachLimit(procs, 1, function(proc, next) {
if (proc.pm2_env && proc.pm2_env.versioning) {
pm2.pullAndReload(proc.name, function(err, meta) {
if (meta) {
app_updated.inc();
console.log('>>>>>>>>>>>>> Successfully pulled Application! [App name: %s]', proc.name)
}
if (err)
console.log('App %s already at latest version', proc.name);
return next();
});
}
else next();
}, cb);
});
}
pmx.initModule({
widget : {
type : 'generic',
theme : ['#111111', '#1B2228', '#807C7C', '#807C7C'],
el : {
probes : true,
actions : true
},
block : {
actions : true,
issues : true,
meta : true,
cpu: true,
mem: true
}
// Status
// Green / Yellow / Red
}
}, function(err, conf) {
pm2.connect(function() {
console.log('pm2-auto-pull module connected to pm2');
var running = false;
setInterval(function() {
if (running == true) return false;
running = true;
autoPull(function() {
running = false;
});
}, conf.interval || 30000);
});
});