pinokiod 3.15.2 → 3.15.4

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.
@@ -1,6 +1,8 @@
1
1
  const axios = require('axios')
2
+ const path = require('path')
2
3
  const fs = require('fs')
3
4
  const semver = require('semver')
5
+ const Util = require('../util')
4
6
 
5
7
  class Caddy {
6
8
  cmd() {
@@ -12,6 +14,7 @@ class Caddy {
12
14
  }
13
15
  async running() {
14
16
  console.log("caddy running check")
17
+ console.log("stack", new Error().stack)
15
18
  try {
16
19
  let response = await axios.get('http://127.0.0.1:2019/config/')
17
20
  return true
@@ -37,6 +40,7 @@ class Caddy {
37
40
  message: `caddy run --watch`,
38
41
  path: this.kernel.homedir,
39
42
  }, (e) => {
43
+ process.stdout.write(e.raw)
40
44
  if (!resolved) {
41
45
  if (/endpoint started/i.test(e.cleaned)) {
42
46
  resolved = true
@@ -50,6 +54,11 @@ class Caddy {
50
54
  }
51
55
  }
52
56
  async install(req, ondata, kernel, id) {
57
+ // let fullpath = path.resolve(kernel.homedir, "ENVIRONMENT")
58
+ // await Util.update_env(fullpath, {
59
+ // PINOKIO_NETWORK_ACTIVE: "1",
60
+ // PINOKIO_HTTPS_ACTIVE: "1"
61
+ // })
53
62
  await this.kernel.bin.exec({
54
63
  message: [
55
64
  "conda clean -y --all",
package/kernel/index.js CHANGED
@@ -3,6 +3,7 @@ const os = require("os")
3
3
  const jsdom = require("jsdom");
4
4
  const randomUseragent = require('random-useragent');
5
5
  const path = require('path')
6
+ const axios = require('axios')
6
7
  const fastq = require('fastq')
7
8
  const fetch = require('cross-fetch');
8
9
  const waitOn = require('wait-on');
@@ -262,38 +263,38 @@ class Kernel {
262
263
  log(data, group, info) {
263
264
  this.log_queue.push({ data, group, info })
264
265
  }
265
- async should_refresh() {
266
- if (this.refresh_cached) {
267
- return this.cached_refresh_value
268
- } else {
269
- let env = await Environment.get(this.homedir)
270
- let peer_active = true
271
- // if PINOKIO_NETWORK_SHARE is 0 or false, turn it off
272
- // By default it should be on.
273
- // It's off if the value is set, and it's 0 or false
274
-
275
- //if (env && env.PINOKIO_NETWORK_ACTIVE && (env.PINOKIO_NETWORK_ACTIVE==="1" || env.PINOKIO_NETWORK_ACTIVE.toLowerCase()==="true")) {
276
- if (env && env.PINOKIO_NETWORK_ACTIVE && (env.PINOKIO_NETWORK_ACTIVE==="0" || env.PINOKIO_NETWORK_ACTIVE.toLowerCase()==="false")) {
277
- peer_active = false
278
- }
279
- let https_active = true
280
- //if (env && env.PINOKIO_HTTPS_ACTIVE && (env.PINOKIO_HTTPS_ACTIVE==="1" || env.PINOKIO_HTTPS_ACTIVE.toLowerCase()==="true")) {
281
- if (env && env.PINOKIO_HTTPS_ACTIVE && (env.PINOKIO_HTTPS_ACTIVE==="0" || env.PINOKIO_HTTPS_ACTIVE.toLowerCase()==="false")) {
282
- //https_active = true
283
- https_active = false
266
+ async network_active() {
267
+ await this.peer.check(this)
268
+ return this.peer.active
269
+ }
270
+ async network_installed() {
271
+ let installed = await this.bin.check_installed({ name: "caddy" })
272
+ return installed
273
+ }
274
+ async network_running() {
275
+ let installed = await this.network_installed()
276
+ if (installed) {
277
+ try {
278
+ await axios.get(`http://127.0.0.1:2019/config/`, { timeout: 1000 });
279
+ return true;
280
+ } catch (err) {
281
+ return false;
284
282
  }
285
- // console.log("kernel.refresh", { active, notify_peers })
286
-
287
- let caddy_installed = await this.bin.check_installed({ name: "caddy" })
288
- this.refresh_cached = true
289
- this.cached_refresh_value = caddy_installed && https_active
290
- return this.cached_refresh_value
283
+ } else {
284
+ return false
291
285
  }
292
286
  }
293
287
  async refresh(notify_peers) {
288
+ console.log("kernel.refresh")
294
289
  const ts = Date.now()
295
- let should_refresh = await this.should_refresh()
296
- if (should_refresh) {
290
+ let network_active = await this.network_active()
291
+ console.log({ network_active })
292
+ if (!network_active) {
293
+ return
294
+ }
295
+ let network_running = await this.network_running()
296
+ console.log({ network_running })
297
+ if (network_running) {
297
298
 
298
299
 
299
300
  let ts = Date.now()
@@ -803,14 +804,19 @@ class Kernel {
803
804
  // }, 3000)
804
805
 
805
806
  // refresh every 5 second
806
- // if (this.refresh_interval) {
807
- // clearInterval(this.refresh_interval)
808
- // }
809
- this.refresh_cached = false
810
- this.cached_refresh_value = false
811
- this.refresh_interval = setInterval(() => {
812
- this.refresh()
813
- }, 5000)
807
+ if (this.refresh_interval) {
808
+ clearInterval(this.refresh_interval)
809
+ }
810
+ let network_active = await this.network_active()
811
+ if (network_active) {
812
+ this.refresh_interval = setInterval(() => {
813
+ if (this.server_running) {
814
+ this.refresh()
815
+ } else {
816
+ console.log("server not running yet. retry network refresh in 5 secs")
817
+ }
818
+ }, 5000)
819
+ }
814
820
 
815
821
  }
816
822
 
package/kernel/peer.js CHANGED
@@ -25,21 +25,45 @@ class PeerDiscovery {
25
25
  this.socket.send(this.message, 0, this.message.length, this.port, '192.168.1.255');
26
26
  }
27
27
  }
28
- async start(kernel) {
28
+ async check(kernel) {
29
29
  let env = await Environment.get(kernel.homedir)
30
-
31
- // by default expose to the local network
32
- this.active = true
33
- // if PINOKIO_NETWORK_SHARE is 0 or false, turn it off
34
- if (env && env.PINOKIO_NETWORK_ACTIVE && (env.PINOKIO_NETWORK_ACTIVE==="0" || env.PINOKIO_NETWORK_ACTIVE.toLowerCase()==="false")) {
35
- //if (env && env.PINOKIO_NETWORK_ACTIVE && (env.PINOKIO_NETWORK_ACTIVE==="1" || env.PINOKIO_NETWORK_ACTIVE.toLowerCase()==="true")) {
36
- this.active = false
30
+ //let peer_active = true
31
+ let peer_active = false
32
+ if (env && env.PINOKIO_NETWORK_ACTIVE && (env.PINOKIO_NETWORK_ACTIVE==="1" || env.PINOKIO_NETWORK_ACTIVE.toLowerCase()==="true")) {
33
+ //if (env && env.PINOKIO_NETWORK_ACTIVE && (env.PINOKIO_NETWORK_ACTIVE==="0" || env.PINOKIO_NETWORK_ACTIVE.toLowerCase()==="false")) {
34
+ peer_active = true
37
35
  }
38
-
36
+ //let https_active = true
37
+ let https_active = false
38
+ if (env && env.PINOKIO_HTTPS_ACTIVE && (env.PINOKIO_HTTPS_ACTIVE==="1" || env.PINOKIO_HTTPS_ACTIVE.toLowerCase()==="true")) {
39
+ //if (env && env.PINOKIO_HTTPS_ACTIVE && (env.PINOKIO_HTTPS_ACTIVE==="0" || env.PINOKIO_HTTPS_ACTIVE.toLowerCase()==="false")) {
40
+ https_active = true
41
+ //https_active = false
42
+ }
43
+ // console.log("kernel.refresh", { active, notify_peers })
39
44
  this.name = os.userInfo().username
40
45
  if (env && env.PINOKIO_NETWORK_NAME && env.PINOKIO_NETWORK_NAME.length > 0) {
41
46
  this.name = env.PINOKIO_NETWORK_NAME
42
47
  }
48
+ if (peer_active && https_active) {
49
+ this.active = true
50
+ } else {
51
+ this.active = false
52
+ }
53
+ }
54
+ async start(kernel) {
55
+ let env = await Environment.get(kernel.homedir)
56
+
57
+ // by default expose to the local network
58
+ //this.active = true
59
+ // if PINOKIO_NETWORK_SHARE is 0 or false, turn it off
60
+ // if (env && env.PINOKIO_NETWORK_ACTIVE && (env.PINOKIO_NETWORK_ACTIVE==="0" || env.PINOKIO_NETWORK_ACTIVE.toLowerCase()==="false")) {
61
+ await this.check(kernel)
62
+ console.log({ active: this.active, name: this.name })
63
+ // if (env && env.PINOKIO_NETWORK_ACTIVE && (env.PINOKIO_NETWORK_ACTIVE==="1" || env.PINOKIO_NETWORK_ACTIVE.toLowerCase()==="true")) {
64
+ //// this.active = false
65
+ // this.active = true
66
+ // }
43
67
 
44
68
  if (this.active) {
45
69
  // Listen for incoming pings
package/kernel/procs.js CHANGED
@@ -16,10 +16,11 @@ class Procs {
16
16
  return this.cache[localAddress]
17
17
  }
18
18
  try {
19
- await axios.head(`http://${localAddress}`, { timeout: 1000 });
19
+ await axios.head(`http://${localAddress}`, { timeout: 3000 });
20
20
  this.cache[localAddress] = true
21
21
  return true;
22
22
  } catch (err) {
23
+ // console.log("HEAD ERROR",{ localAddress, err })
23
24
  this.cache[localAddress] = false
24
25
  return false;
25
26
  }
@@ -41,8 +42,8 @@ class Procs {
41
42
  let pids = new Set()
42
43
  let s = stdout.trim()
43
44
  const lines = s.split('\n');
44
-
45
45
  for(let line of lines) {
46
+ console.log({ line })
46
47
  if (isWin) {
47
48
  // Skip headers
48
49
  try {
@@ -67,9 +68,12 @@ class Procs {
67
68
  ip = localAddress
68
69
  }
69
70
 
71
+ console.log("isHttp?", ip)
70
72
  let isHttp = await this.isHttp(ip)
73
+ console.log(isHttp)
71
74
  if (!isHttp) continue
72
75
 
76
+
73
77
  if (pids.has(pid+"/"+port)) continue;
74
78
  pids.add(pid+"/"+port)
75
79
  results.push({ port, pid, ip });
@@ -194,11 +198,9 @@ class Procs {
194
198
  }
195
199
  }
196
200
  if (cached) {
197
- // console.log("already cached")
198
201
  cb(this.port_map)
199
202
  return
200
203
  }
201
- // console.log("not cached")
202
204
  const cmd = isWin ? 'tasklist /fo csv /nh' : 'ps -Ao pid,comm';
203
205
  let id = "Procs.getPidToNameMap"
204
206
  let sh = this.kernel.shell.get(id)
@@ -244,10 +246,9 @@ class Procs {
244
246
  let list = await new Promise((resolve, reject) => {
245
247
  // console.time(">>>>>>>>GET PORTS " + ts)
246
248
  this.getPortPidList((portPidList) => {
249
+ console({ portPidList })
247
250
  // console.timeEnd(">>>>>>>>GET PORTS " + ts)
248
251
  // console.time(">>>>>>> GET PIDS " + ts)
249
- // console.log({ portPidList })
250
-
251
252
  // if there's any new port, run getPidToNameMap
252
253
 
253
254
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pinokiod",
3
- "version": "3.15.2",
3
+ "version": "3.15.4",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/server/index.js CHANGED
@@ -1723,9 +1723,7 @@ class Server {
1723
1723
  } else {
1724
1724
  currentIndexPath = "" + i
1725
1725
  }
1726
- console.log(">>", { indexPath, currentIndexPath, i })
1727
1726
  let shell_id = this.get_shell_id(name, currentIndexPath, rendered)
1728
- console.log(">>", { name, shell_id, })
1729
1727
 
1730
1728
 
1731
1729
  // let hash = crypto.createHash('md5').update(JSON.stringify(rendered)).digest('hex')
@@ -4840,7 +4838,7 @@ class Server {
4840
4838
  this.app.post("/network", ex(async (req, res) => {
4841
4839
  if (this.kernel.homedir) {
4842
4840
  let fullpath = path.resolve(this.kernel.homedir, "ENVIRONMENT")
4843
- console.log("req.body", req.body)
4841
+ console.log("POST /network", req.body)
4844
4842
  await Util.update_env(fullpath, req.body)
4845
4843
  res.json({ success: true })
4846
4844
  } else {
@@ -4938,6 +4936,7 @@ class Server {
4938
4936
  await new Promise((resolve, reject) => {
4939
4937
  this.listening = this.server.listen(this.port, () => {
4940
4938
  console.log(`Server listening on port ${this.port}`)
4939
+ this.kernel.server_running = true
4941
4940
  resolve()
4942
4941
  });
4943
4942
  this.httpTerminator = createHttpTerminator({
@@ -875,6 +875,7 @@ if (document.querySelector("#wifi")) {
875
875
  })
876
876
  }
877
877
  <% } %>
878
+ <% if (peer_active) { %>
878
879
  setInterval(() => {
879
880
  fetch("/peer_check").then((res) => {
880
881
  return res.json()
@@ -884,6 +885,7 @@ setInterval(() => {
884
885
  }
885
886
  })
886
887
  }, 2000)
888
+ <% } %>
887
889
  </script>
888
890
  </body>
889
891
  </html>
@@ -226,6 +226,7 @@ document.addEventListener("DOMContentLoaded", async () => {
226
226
  <% } %>
227
227
  <% if (!requirements_pending && !install_required && wait === "caddy") { %>
228
228
  console.log("RESTART")
229
+ alert("RESTART")
229
230
 
230
231
  let r = await fetch("/network", {
231
232
  method: "post",