This repository was archived by the owner on Sep 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Expand file tree
/
Copy pathmonitor.js
More file actions
84 lines (75 loc) · 2.21 KB
/
Copy pathmonitor.js
File metadata and controls
84 lines (75 loc) · 2.21 KB
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
84
/**
* Component for monitor.
* Load and start monitor client.
*/
var logger = require('pomelo-logger').getLogger('pomelo', __filename);
var admin = require('pomelo-admin-js');
var moduleUtil = require('../util/moduleUtil');
var utils = require('../util/utils');
var Constants = require('../util/constants');
var Monitor = function(app, opts) {
opts = opts || {};
this.app = app;
this.serverInfo = app.getCurServer();
this.masterInfo = app.getMaster();
this.modules = [];
this.closeWatcher = opts.closeWatcher;
this.monitorConsole = admin.createMonitorConsole({
id: this.serverInfo.id,
type: this.app.getServerType(),
host: this.masterInfo.host,
port: this.masterInfo.port,
info: this.serverInfo,
env: this.app.get(Constants.RESERVED.ENV),
authServer: app.get('adminAuthServerMonitor') // auth server function
});
};
module.exports = Monitor;
Monitor.prototype.start = function(cb) {
moduleUtil.registerDefaultModules(false, this.app, this.closeWatcher);
this.startConsole(cb);
};
Monitor.prototype.startConsole = function(cb) {
moduleUtil.loadModules(this, this.monitorConsole);
var self = this;
this.monitorConsole.start(function(err) {
if (err) {
utils.invokeCallback(cb, err);
return;
}
moduleUtil.startModules(self.modules, function(err) {
utils.invokeCallback(cb, err);
return;
});
});
this.monitorConsole.on('error', function(err) {
if(!!err) {
logger.error('monitorConsole encounters with error: %j', err.stack);
return;
}
});
};
Monitor.prototype.stop = function(cb) {
this.monitorConsole.stop();
this.modules = [];
process.nextTick(function() {
utils.invokeCallback(cb);
});
};
// monitor reconnect to master
Monitor.prototype.reconnect = function(masterInfo) {
var self = this;
this.stop(function() {
self.monitorConsole = admin.createMonitorConsole({
id: self.serverInfo.id,
type: self.app.getServerType(),
host: masterInfo.host,
port: masterInfo.port,
info: self.serverInfo,
env: self.app.get(Constants.RESERVED.ENV)
});
self.startConsole(function() {
logger.info('restart modules for server : %j finish.', self.app.serverId);
});
});
};