-
Notifications
You must be signed in to change notification settings - Fork 0
/
supervisord.js
executable file
·121 lines (109 loc) · 3.16 KB
/
supervisord.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
const xmlrpc = require('xmlrpc');
const Url = require('url');
function api(host) {
var hostParts = {};
if(typeof host == 'string')
{
if (host.indexOf('unix') === 0) {
hostParts.socketPath = Url.parse(host).pathname;
}else{
if (host.indexOf('http') !== 0) {
host = 'http://' + host;
}
hostParts = Url.parse(host);
if(hostParts.auth)
{
var authParts = hostParts.auth.split(':');
hostParts.user = authParts[0];
hostParts.pass = authParts[1];
}
}
}
else if(host)
{
hostParts = host;
}
if(!hostParts.hostname) hostParts.hostname = 'localhost';
if(!hostParts.port) hostParts.port = 9001;
if(hostParts.socketPath){
this.client = xmlrpc.createClient({
socketPath: hostParts.socketPath,
path: '/RPC2',
});
}else{
this.client = xmlrpc.createClient({
host: hostParts.hostname,
port: hostParts.port,
path: '/RPC2',
basic_auth: {
user: hostParts.user,
pass: hostParts.pass
}
});
}
}
api.prototype._call = function(method, args)
{
return new Promise((resolve, reject) => {
try {
this.client.methodCall(method, args, (error, result) => {
if(error) {
reject(error);
} else {
resolve(result);
}
});
} catch (ex) {
reject(ex);
}
})
};
['supervisor.addProcessGroup',
'supervisor.clearAllProcessLogs',
'supervisor.clearLog',
'supervisor.clearProcessLog',
'supervisor.clearProcessLogs',
'supervisor.getAPIVersion',
'supervisor.getAllConfigInfo',
'supervisor.getAllProcessInfo',
'supervisor.getIdentification',
'supervisor.getPID',
'supervisor.getProcessInfo',
'supervisor.getState',
'supervisor.getSupervisorVersion',
'supervisor.getVersion',
'supervisor.readLog',
'supervisor.readMainLog',
'supervisor.readProcessLog',
'supervisor.readProcessStderrLog',
'supervisor.readProcessStdoutLog',
'supervisor.reloadConfig',
'supervisor.removeProcessGroup',
'supervisor.restart',
'supervisor.sendProcessStdin',
'supervisor.sendRemoteCommEvent',
'supervisor.signalProcess',
'supervisor.signalProcessGroup',
'supervisor.shutdown',
'supervisor.startAllProcesses',
'supervisor.startProcess',
'supervisor.startProcessGroup',
'supervisor.stopAllProcesses',
'supervisor.stopProcess',
'supervisor.stopProcessGroup',
'supervisor.tailProcessLog',
'supervisor.tailProcessStderrLog',
'supervisor.tailProcessStdoutLog',
'system.listMethods',
'system.methodHelp',
'system.methodSignature',
'system.multicall'].forEach(function(property){
api.prototype[property.split('.').pop()] = function(){
const args = Array.prototype.slice.call(arguments);
return this._call(property, args);
};
});
exports.connect = function(host)
{
return new api(host);
}