forked from Stii/nodervisor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathajax_supervisorctl.js
57 lines (53 loc) · 1.57 KB
/
ajax_supervisorctl.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
/*
* GET downloadctl page.
*/
exports.ajax_supervisorctl = function(params) {
var config = params.config;
var supervisordapi = params.supervisordapi;
return function(req, res) {
if (!req.session.loggedIn) {
res.send({error: 'Not logged in'});
} else {
if (req.session.user.Role != 'Admin') || (req.session.user.Role != 'Operator') {
res.send({error: 'Incorrect Priviledges!'});
return false;
} else {
var host = req.param('host');
var process = req.param('process');
var action = req.param('action');
if (config.hosts[host] !== undefined) {
var supclient = supervisordapi.connect(config.hosts[host].Url);
switch (action) {
case 'stop': {
supclient.stopProcessGroup(process, function(){
res.send({result: 'success'});
});
}
break;
case 'start': {
supclient.startProcess(process, function(){
res.send({result: 'success'});
});
}
break;
case 'restartAll': {
if (req.session.user.Role != 'Admin' || req.session.user.Role != 'Operator') {
res.send({error: 'Incorrect Priviledges!'});
return false;
} else {
supclient.stopAllProcesses(true, function(){
supclient.startAllProcesses(true, function(){
res.send({result: 'success'});
});
});
}
}
break;
}
} else {
res.send({result: 'error', message: 'Host not found'});
}
}
}
};
};