pinokiod 3.8.100 → 3.8.102
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/kernel/index.js +43 -15
- package/kernel/procs.js +3 -0
- package/kernel/router/connector.js +7 -7
- package/kernel/router/index.js +59 -1
- package/kernel/router/localhost_port_router.js +3 -2
- package/kernel/router/localhost_variable_router.js +1 -1
- package/kernel/router/peer_home_router.js +1 -0
- package/kernel/router/peer_peer_router.js +1 -0
- package/kernel/router/peer_port_router.js +1 -0
- package/kernel/shell.js +4 -2
- package/kernel/tree-kill.js +9 -7
- package/package.json +1 -1
- package/server/index.js +14 -4
package/kernel/index.js
CHANGED
|
@@ -266,28 +266,56 @@ class Kernel {
|
|
|
266
266
|
if (env && env.PINOKIO_NETWORK_ACTIVE && (env.PINOKIO_NETWORK_ACTIVE==="1" || env.PINOKIO_NETWORK_ACTIVE.toLowerCase()==="true")) {
|
|
267
267
|
active = true
|
|
268
268
|
}
|
|
269
|
-
|
|
270
|
-
console.log("kernel.refresh", { active, notify_peers })
|
|
269
|
+
console.log("kernel.refresh", { active, notify_peers })
|
|
271
270
|
if (active) {
|
|
272
271
|
|
|
272
|
+
// 1. get the process list
|
|
273
|
+
console.log("Step 1: Get process list")
|
|
274
|
+
await this.processes.refresh()
|
|
275
|
+
console.log("Process info", this.processes.info)
|
|
276
|
+
|
|
277
|
+
// 2. refresh peer info to reflect the proc info
|
|
278
|
+
await this.peer.refresh()
|
|
279
|
+
|
|
280
|
+
// 3. set current local host router info
|
|
281
|
+
console.log("Step 3: Set current local host router")
|
|
282
|
+
await this.router.local()
|
|
283
|
+
console.log("router mapping after step 3", this.router.info())
|
|
273
284
|
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
this.processes.refresh(),
|
|
277
|
-
// refresh peer info
|
|
278
|
-
this.peer.refresh()
|
|
279
|
-
])
|
|
280
|
-
console.log("proc info", this.processes.info)
|
|
281
|
-
console.log("peer info", this.peer.info)
|
|
282
|
-
// refresh router info
|
|
283
|
-
await this.router.refresh()
|
|
284
|
-
console.log("router info", this.router.published())
|
|
285
|
-
// await this.peer.refresh()
|
|
285
|
+
// 4. refresh peer info to reflect the updated router info
|
|
286
|
+
await this.peer.refresh()
|
|
286
287
|
|
|
288
|
+
// 4. tell peers to refresh
|
|
287
289
|
if (notify_peers) {
|
|
288
|
-
|
|
290
|
+
console.log("Step 4: notify peers to refresh")
|
|
289
291
|
await this.peer.notify_peers()
|
|
290
292
|
}
|
|
293
|
+
|
|
294
|
+
// 4. update remote router
|
|
295
|
+
console.log("Step 5: Set remote routers")
|
|
296
|
+
await this.router.remote()
|
|
297
|
+
console.log("router mapping after step 5", this.router.info())
|
|
298
|
+
|
|
299
|
+
await this.router.update()
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
// await Promise.all([
|
|
303
|
+
// // refresh proc info
|
|
304
|
+
// this.processes.refresh(),
|
|
305
|
+
// // refresh peer info
|
|
306
|
+
// this.peer.refresh()
|
|
307
|
+
// ])
|
|
308
|
+
// console.log("proc info", this.processes.info)
|
|
309
|
+
// console.log("peer info", this.peer.info)
|
|
310
|
+
// // refresh router info
|
|
311
|
+
// await this.router.refresh()
|
|
312
|
+
// console.log("router info", this.router.published())
|
|
313
|
+
//// await this.peer.refresh()
|
|
314
|
+
//
|
|
315
|
+
// if (notify_peers) {
|
|
316
|
+
// // broadcast to peers to refresh
|
|
317
|
+
// await this.peer.notify_peers()
|
|
318
|
+
// }
|
|
291
319
|
}
|
|
292
320
|
}
|
|
293
321
|
async clearLog(group) {
|
package/kernel/procs.js
CHANGED
|
@@ -81,6 +81,7 @@ class Procs {
|
|
|
81
81
|
}
|
|
82
82
|
async refresh() {
|
|
83
83
|
console.time("Get list")
|
|
84
|
+
let map = {}
|
|
84
85
|
let list = await new Promise((resolve, reject) => {
|
|
85
86
|
this.getPortPidList((err, portPidList) => {
|
|
86
87
|
if (err) {
|
|
@@ -97,6 +98,7 @@ class Procs {
|
|
|
97
98
|
let list = portPidList.map(({ port, pid, ip }) => {
|
|
98
99
|
const fullname = pidToName[pid] || 'Unknown';
|
|
99
100
|
const name = fullname.split(path.sep).pop()
|
|
101
|
+
map["" + pid] = fullname
|
|
100
102
|
return { port, pid , name, fullname, ip }
|
|
101
103
|
})
|
|
102
104
|
list = list.filter((item) => {
|
|
@@ -108,6 +110,7 @@ class Procs {
|
|
|
108
110
|
})
|
|
109
111
|
console.timeEnd("Get list")
|
|
110
112
|
this.info = list
|
|
113
|
+
this.map = map
|
|
111
114
|
}
|
|
112
115
|
}
|
|
113
116
|
module.exports = Procs
|
|
@@ -4,7 +4,7 @@ class Connector {
|
|
|
4
4
|
}
|
|
5
5
|
handle ({ match, connector, dial, }) {
|
|
6
6
|
console.log("connector.handle", { match, connector, dial })
|
|
7
|
-
let connector_name = connector.host + "
|
|
7
|
+
let connector_name = connector.host + "-" + connector.port
|
|
8
8
|
let listener = "0.0.0.0:PORT_PLACEHOLDER_" + connector_name
|
|
9
9
|
let listener_pointer = connector.host + ":PORT_PLACEHOLDER_" + connector_name
|
|
10
10
|
if(!this.router.config.apps.http.servers[connector_name]) {
|
|
@@ -16,12 +16,12 @@ class Connector {
|
|
|
16
16
|
"handler": "reverse_proxy",
|
|
17
17
|
"upstreams": [{ "dial": dial }],
|
|
18
18
|
"headers": {
|
|
19
|
-
"request": {
|
|
20
|
-
"set": {
|
|
21
|
-
"X-Forwarded-Proto": ["https"],
|
|
22
|
-
"X-Forwarded-Host": ["{http.request.host}"]
|
|
23
|
-
}
|
|
24
|
-
},
|
|
19
|
+
// "request": {
|
|
20
|
+
// "set": {
|
|
21
|
+
// "X-Forwarded-Proto": ["https"],
|
|
22
|
+
// "X-Forwarded-Host": ["{http.request.host}"]
|
|
23
|
+
// }
|
|
24
|
+
// },
|
|
25
25
|
"response": {
|
|
26
26
|
"set": {
|
|
27
27
|
"Access-Control-Allow-Origin": ["*"],
|
package/kernel/router/index.js
CHANGED
|
@@ -89,10 +89,12 @@ class Router {
|
|
|
89
89
|
async fill() {
|
|
90
90
|
const jsonString = JSON.stringify(this.config)
|
|
91
91
|
// find all PORT_PLACEHOLDER patterns
|
|
92
|
-
const matches = jsonString.match(/:PORT_PLACEHOLDER_[0-9
|
|
92
|
+
const matches = jsonString.match(/:PORT_PLACEHOLDER_[0-9.-]+/g)
|
|
93
|
+
|
|
93
94
|
|
|
94
95
|
// iterate through them and see if the port already exists
|
|
95
96
|
let count = matches ? new Set(matches).size : 0
|
|
97
|
+
console.log("fill matches", { matches, count })
|
|
96
98
|
/*
|
|
97
99
|
let count = 0
|
|
98
100
|
if (matches) {
|
|
@@ -109,11 +111,13 @@ class Router {
|
|
|
109
111
|
*/
|
|
110
112
|
|
|
111
113
|
|
|
114
|
+
|
|
112
115
|
let new_config
|
|
113
116
|
|
|
114
117
|
if (count > 0) {
|
|
115
118
|
let ports = await this.kernel.ports(count)
|
|
116
119
|
let response = Util.fill_object(this.config, /PORT_PLACEHOLDER_.+/, ports, this.port_cache)
|
|
120
|
+
console.log("fill_object response", response)
|
|
117
121
|
this.config = response.result
|
|
118
122
|
let replaced_map = response.replaced_map
|
|
119
123
|
for(let key in replaced_map) {
|
|
@@ -131,12 +135,66 @@ class Router {
|
|
|
131
135
|
|
|
132
136
|
//let original_port = key.replace("PORT_PLACEHOLDER_", "")
|
|
133
137
|
this.port_mapping[original_port] = replaced_map[key]
|
|
138
|
+
console.log("set port_mapping", { original_port, key, replaced_map })
|
|
134
139
|
}
|
|
135
140
|
this.port_cache = replaced_map
|
|
136
141
|
}
|
|
137
142
|
|
|
138
143
|
}
|
|
139
144
|
|
|
145
|
+
|
|
146
|
+
// set local config
|
|
147
|
+
async local() {
|
|
148
|
+
this._mapping = {}
|
|
149
|
+
this.localhost_home_router.handle()
|
|
150
|
+
this.localhost_variable_router.handle(this.kernel.memory.local)
|
|
151
|
+
for(let proc of this.kernel.processes.info) {
|
|
152
|
+
this.localhost_port_router.handle(proc)
|
|
153
|
+
}
|
|
154
|
+
//this.mapping = this._mapping
|
|
155
|
+
|
|
156
|
+
for(let host in this.kernel.peer.info) {
|
|
157
|
+
let peer = this.kernel.peer.info[host]
|
|
158
|
+
if (peer.host === this.kernel.peer.host) {
|
|
159
|
+
this.peer_home_router.handle(peer)
|
|
160
|
+
this.peer_variable_router.handle(peer)
|
|
161
|
+
this.peer_port_router.handle(peer)
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
await this.fill()
|
|
165
|
+
this.mapping = this._mapping
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// set remote config
|
|
169
|
+
async remote() {
|
|
170
|
+
for(let host in this.kernel.peer.info) {
|
|
171
|
+
let peer = this.kernel.peer.info[host]
|
|
172
|
+
if (peer.host !== this.kernel.peer.host) {
|
|
173
|
+
this.peer_peer_router.handle(peer)
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
//await this.fill()
|
|
177
|
+
this.mapping = this._mapping
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// update caddy config
|
|
181
|
+
async update() {
|
|
182
|
+
console.log("this.config", this.config)
|
|
183
|
+
console.log("this.old_config", this.old_config)
|
|
184
|
+
if (JSON.stringify(this.config) === JSON.stringify(this.old_config)) {
|
|
185
|
+
console.log("config hasn't updated")
|
|
186
|
+
} else {
|
|
187
|
+
console.log("config has updated")
|
|
188
|
+
let response = await axios.post('http://127.0.0.1:2019/load', this.config, {
|
|
189
|
+
headers: { 'Content-Type': 'application/json' }
|
|
190
|
+
}).catch((e) => {
|
|
191
|
+
console.log("EEEEEEEEEEEEE", e.message)
|
|
192
|
+
})
|
|
193
|
+
console.log("Caddy Response", { response })
|
|
194
|
+
this.old_config = this.config
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
140
198
|
async refresh() {
|
|
141
199
|
console.log("router.refresh")
|
|
142
200
|
console.time("router.refresh")
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
const Common = require('./common')
|
|
2
|
-
class
|
|
2
|
+
class LocalhostPortRouter {
|
|
3
3
|
constructor(router) {
|
|
4
4
|
this.router = router
|
|
5
5
|
this.common = new Common(router)
|
|
6
6
|
}
|
|
7
7
|
handle (proc) {
|
|
8
|
+
console.log("LocalhostPortRouter", proc)
|
|
8
9
|
this.common.handle({
|
|
9
10
|
match: `${proc.port}.localhost`,
|
|
10
11
|
dial: proc.ip,
|
|
@@ -12,4 +13,4 @@ class LocalhostHomeRouter {
|
|
|
12
13
|
})
|
|
13
14
|
}
|
|
14
15
|
}
|
|
15
|
-
module.exports =
|
|
16
|
+
module.exports = LocalhostPortRouter
|
|
@@ -8,7 +8,7 @@ class LocalhostVariableRouter extends Processor {
|
|
|
8
8
|
this.common = new Common(router)
|
|
9
9
|
}
|
|
10
10
|
handle (local) {
|
|
11
|
-
console.log("
|
|
11
|
+
console.log("LocalhostVariableRouter", local)
|
|
12
12
|
for(let script_path in local) {
|
|
13
13
|
let local_variables_for_script = local[script_path]
|
|
14
14
|
for(let key in local_variables_for_script) {
|
|
@@ -5,6 +5,7 @@ class PeerHomeRouter {
|
|
|
5
5
|
this.common = new Common(router)
|
|
6
6
|
}
|
|
7
7
|
handle(peer) {
|
|
8
|
+
console.log("PeerHomeRouter", peer)
|
|
8
9
|
this.common.handle({
|
|
9
10
|
match: `${this.router.default_prefix}.${peer.name}.${this.router.default_suffix}`,
|
|
10
11
|
dial: `${peer.host}:${this.router.default_port}`,
|
|
@@ -8,6 +8,7 @@ class PeerPortRouter extends Processor {
|
|
|
8
8
|
this.connector = new Connector(router)
|
|
9
9
|
}
|
|
10
10
|
handle(peer) {
|
|
11
|
+
console.log("PeerPortRouter", peer)
|
|
11
12
|
let https_domains_mapping = this.router.info()[peer.host]
|
|
12
13
|
for(let dial in https_domains_mapping) {
|
|
13
14
|
let parsed_dial = this.parse_ip(dial)
|
package/kernel/shell.js
CHANGED
|
@@ -979,7 +979,8 @@ class Shell {
|
|
|
979
979
|
this.queue.killAndDrain()
|
|
980
980
|
if (this.ptyProcess) {
|
|
981
981
|
if (cb) {
|
|
982
|
-
|
|
982
|
+
let map = this.kernel.processes.map || {}
|
|
983
|
+
kill(this.ptyProcess.pid, map, 'SIGKILL', () => {
|
|
983
984
|
console.log("child procs killed for", this.ptyProcess.pid)
|
|
984
985
|
this.ptyProcess.kill()
|
|
985
986
|
this.ptyProcess = undefined
|
|
@@ -989,7 +990,8 @@ class Shell {
|
|
|
989
990
|
cb()
|
|
990
991
|
});
|
|
991
992
|
} else {
|
|
992
|
-
|
|
993
|
+
let map = this.kernel.processes.map || {}
|
|
994
|
+
kill(this.ptyProcess.pid, map, 'SIGKILL');
|
|
993
995
|
console.log("child procs killed for", this.ptyProcess.pid)
|
|
994
996
|
this.ptyProcess.kill()
|
|
995
997
|
this.ptyProcess = undefined
|
package/kernel/tree-kill.js
CHANGED
|
@@ -5,7 +5,7 @@ var spawn = childProcess.spawn;
|
|
|
5
5
|
var exec = childProcess.exec;
|
|
6
6
|
var execSync = childProcess.execSync;
|
|
7
7
|
|
|
8
|
-
module.exports = function (pid, signal, callback) {
|
|
8
|
+
module.exports = function (pid, map, signal, callback) {
|
|
9
9
|
if (typeof signal === 'function' && callback === undefined) {
|
|
10
10
|
callback = signal;
|
|
11
11
|
signal = undefined;
|
|
@@ -31,7 +31,7 @@ module.exports = function (pid, signal, callback) {
|
|
|
31
31
|
break;
|
|
32
32
|
case 'darwin':
|
|
33
33
|
buildProcessTreeMacOS(pid, tree, pidsToProcess, function () {
|
|
34
|
-
killAll(tree, signal, callback);
|
|
34
|
+
killAll(tree, map, signal, callback);
|
|
35
35
|
});
|
|
36
36
|
break;
|
|
37
37
|
// case 'sunos':
|
|
@@ -43,19 +43,20 @@ module.exports = function (pid, signal, callback) {
|
|
|
43
43
|
buildProcessTree(pid, tree, pidsToProcess, function (parentPid) {
|
|
44
44
|
return spawn('ps', ['-o', 'pid', '--no-headers', '--ppid', parentPid]);
|
|
45
45
|
}, function () {
|
|
46
|
-
killAll(tree, signal, callback);
|
|
46
|
+
killAll(tree, map, signal, callback);
|
|
47
47
|
});
|
|
48
48
|
break;
|
|
49
49
|
}
|
|
50
50
|
};
|
|
51
51
|
|
|
52
|
-
function killAll (tree, signal, callback) {
|
|
52
|
+
function killAll (tree, map, signal, callback) {
|
|
53
|
+
console.log("KillAll", tree)
|
|
53
54
|
var killed = {};
|
|
54
55
|
try {
|
|
55
56
|
Object.keys(tree).forEach(function (pid) {
|
|
56
57
|
tree[pid].forEach(function (pidpid) {
|
|
57
58
|
if (!killed[pidpid]) {
|
|
58
|
-
killPid(pidpid, signal);
|
|
59
|
+
killPid(pidpid, map, signal);
|
|
59
60
|
killed[pidpid] = 1;
|
|
60
61
|
}
|
|
61
62
|
});
|
|
@@ -65,7 +66,7 @@ function killAll (tree, signal, callback) {
|
|
|
65
66
|
return
|
|
66
67
|
}
|
|
67
68
|
if (!killed[pid]) {
|
|
68
|
-
killPid(pid, signal);
|
|
69
|
+
killPid(pid, map, signal);
|
|
69
70
|
killed[pid] = 1;
|
|
70
71
|
}
|
|
71
72
|
});
|
|
@@ -81,8 +82,9 @@ function killAll (tree, signal, callback) {
|
|
|
81
82
|
}
|
|
82
83
|
}
|
|
83
84
|
|
|
84
|
-
function killPid(pid, signal) {
|
|
85
|
+
function killPid(pid, map, signal) {
|
|
85
86
|
try {
|
|
87
|
+
console.log("kill", pid, map[pid])
|
|
86
88
|
process.kill(parseInt(pid, 10), signal);
|
|
87
89
|
}
|
|
88
90
|
catch (err) {
|
package/package.json
CHANGED
package/server/index.js
CHANGED
|
@@ -1377,7 +1377,6 @@ class Server {
|
|
|
1377
1377
|
}
|
|
1378
1378
|
})
|
|
1379
1379
|
|
|
1380
|
-
console.log("ITEMS", items)
|
|
1381
1380
|
|
|
1382
1381
|
// if (req.query && req.query.mode === "task") {
|
|
1383
1382
|
// running = running.filter((x) => {
|
|
@@ -3522,7 +3521,6 @@ class Server {
|
|
|
3522
3521
|
let info = Object.assign({}, this.kernel.i)
|
|
3523
3522
|
info.launch_complete = this.kernel.launch_complete
|
|
3524
3523
|
console.log("kernel.launch_complete", this.kernel.launch_complete)
|
|
3525
|
-
console.log({ info })
|
|
3526
3524
|
delete info.vars
|
|
3527
3525
|
delete info.shell_env
|
|
3528
3526
|
delete info.memory
|
|
@@ -3947,6 +3945,7 @@ class Server {
|
|
|
3947
3945
|
})
|
|
3948
3946
|
});
|
|
3949
3947
|
process.on('SIGINT', () => {
|
|
3948
|
+
console.log("[SigInt event]")
|
|
3950
3949
|
//if (this.kernel && this.kernel.shell) {
|
|
3951
3950
|
// console.log("shell reset")
|
|
3952
3951
|
// this.kernel.shell.reset(() => {
|
|
@@ -3955,13 +3954,15 @@ class Server {
|
|
|
3955
3954
|
//} else {
|
|
3956
3955
|
// process.exit()
|
|
3957
3956
|
//}
|
|
3958
|
-
|
|
3957
|
+
let map = this.kernel.processes.map || {}
|
|
3958
|
+
kill(process.pid, map, 'SIGKILL', () => {
|
|
3959
3959
|
console.log("child procs killed for", process.pid)
|
|
3960
3960
|
process.exit()
|
|
3961
3961
|
});
|
|
3962
3962
|
})
|
|
3963
3963
|
|
|
3964
3964
|
process.on('SIGTERM', () => {
|
|
3965
|
+
console.log("[Sigterm event]")
|
|
3965
3966
|
// if (this.kernel && this.kernel.shell) {
|
|
3966
3967
|
// console.log("shell reset")
|
|
3967
3968
|
// this.kernel.shell.reset(() => {
|
|
@@ -3970,7 +3971,16 @@ class Server {
|
|
|
3970
3971
|
// } else {
|
|
3971
3972
|
// process.exit()
|
|
3972
3973
|
// }
|
|
3973
|
-
|
|
3974
|
+
let map = this.kernel.processes.map || {}
|
|
3975
|
+
kill(process.pid, map, 'SIGKILL', () => {
|
|
3976
|
+
console.log("child procs killed for", process.pid)
|
|
3977
|
+
process.exit()
|
|
3978
|
+
});
|
|
3979
|
+
})
|
|
3980
|
+
process.on('exit', () => {
|
|
3981
|
+
console.log("[Exit event]")
|
|
3982
|
+
let map = this.kernel.processes.map || {}
|
|
3983
|
+
kill(process.pid, map, 'SIGKILL', () => {
|
|
3974
3984
|
console.log("child procs killed for", process.pid)
|
|
3975
3985
|
process.exit()
|
|
3976
3986
|
});
|