pinokiod 3.8.22 → 3.8.23

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.
@@ -32,9 +32,6 @@ class Caddy {
32
32
  this.kernel.exec({
33
33
  message: `caddy run --watch`,
34
34
  path: this.kernel.homedir,
35
- kill: [{
36
- message: "caddy stop"
37
- }]
38
35
  }, (e) => {
39
36
  console.log("[CADDY] " + e.cleaned)
40
37
  if (!resolved) {
@@ -327,9 +324,6 @@ class Caddy {
327
324
  this.kernel.exec({
328
325
  message: `caddy run --watch`,
329
326
  path: this.kernel.homedir,
330
- kill: [{
331
- message: "caddy stop"
332
- }]
333
327
  }, (e) => {
334
328
  resolve()
335
329
  console.log("[CADDY] " + e.cleaned)
@@ -348,10 +342,6 @@ class Caddy {
348
342
  path: this.kernel.homedir
349
343
  }, (e) => {
350
344
  ondata(e)
351
- // console.log(e)
352
- // if (/Caddy Local Authority/i.test(e.cleaned)) {
353
- // trusted = true
354
- // }
355
345
  })
356
346
  } else {
357
347
  console.log("req", req)
package/kernel/shell.js CHANGED
@@ -2,7 +2,7 @@ const { Terminal } = require('xterm-headless');
2
2
  const { SerializeAddon } = require("xterm-addon-serialize");
3
3
  const sanitize = require("sanitize-filename");
4
4
  const YAML = require('yaml')
5
-
5
+ const kill = require('tree-kill');
6
6
  const fastq = require('fastq')
7
7
  const { v4: uuidv4 } = require('uuid');
8
8
  const os = require('os');
@@ -60,8 +60,6 @@ class Shell {
60
60
 
61
61
  }
62
62
  async init_env(params) {
63
- console.log({ params })
64
- console.time("> 1")
65
63
  this.env = Object.assign({}, process.env)
66
64
  // If the user has set PYTHONPATH, unset it.
67
65
  if (this.env.PYTHONPATH) {
@@ -90,16 +88,12 @@ class Shell {
90
88
  // }
91
89
  for(let key in this.env) {
92
90
  if (key.startsWith("CUDA")) {
93
- console.log("Unset env key: " + key)
94
91
  delete this.env[key]
95
92
  }
96
93
  if (/.*(SSH|SSL).*/.test(key)) {
97
- console.log("Unset env key: " + key)
98
94
  delete this.env[key]
99
95
  }
100
96
  }
101
- console.timeEnd("> 1")
102
- console.time("> 2")
103
97
 
104
98
  this.env.CMAKE_OBJECT_PATH_MAX = 1024
105
99
  this.env.PYTORCH_ENABLE_MPS_FALLBACK = 1
@@ -113,9 +107,7 @@ class Shell {
113
107
  // First override this.env with system env
114
108
  let system_env = await Environment.get(this.kernel.homedir)
115
109
  this.env = Object.assign(this.env, system_env)
116
- console.timeEnd("> 2")
117
110
 
118
- console.time("> 3")
119
111
  // if the shell is running from a script file, the params.$parent will include the path to the parent script
120
112
  // this means we need to apply app environment as well
121
113
  if (params.$parent) {
@@ -147,7 +139,6 @@ class Shell {
147
139
 
148
140
  if (this.platform === "linux") {
149
141
  let gxx = this.kernel.which('g++')
150
- console.log({ gxx })
151
142
  if (gxx) {
152
143
  this.env.NVCC_PREPEND_FLAGS = `-ccbin ${gxx}`
153
144
  }
@@ -156,8 +147,6 @@ class Shell {
156
147
  this.env[PATH_KEY] = this.env[PATH_KEY] + path.delimiter + path.resolve(this.kernel.homedir, 'bin')
157
148
 
158
149
 
159
- console.timeEnd("> 3")
160
- console.time("> 4")
161
150
  if (params.env) {
162
151
  for(let key in params.env) {
163
152
  // iterate through the env attributes
@@ -191,10 +180,6 @@ class Shell {
191
180
  }
192
181
  }
193
182
  }
194
- console.timeEnd("> 4")
195
-
196
-
197
- console.time("> 5")
198
183
  for(let key in this.env) {
199
184
  if (!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(key) && key !== "ProgramFiles(x86)") {
200
185
  delete this.env[key]
@@ -213,7 +198,6 @@ class Shell {
213
198
  delete this.env[key]
214
199
  }
215
200
  }
216
- console.timeEnd("> 5")
217
201
  }
218
202
  async start(params, ondata) {
219
203
  this.ondata = ondata
@@ -245,9 +229,6 @@ class Shell {
245
229
  this.rows = params.client.rows
246
230
  }
247
231
 
248
- console.log({ cols: this.cols, rows: this.rows })
249
-
250
-
251
232
  this.vt = new Terminal({
252
233
  allowProposedApi: true,
253
234
  cols: this.cols,
@@ -280,13 +261,13 @@ class Shell {
280
261
  if (params.sudo) {
281
262
  let options = {
282
263
  name: "Pinokio",
283
- env: {}
264
+ // env: {}
284
265
  // icns: '/Applications/Electron.app/Contents/Resources/Electron.icns', // (optional)
285
266
  };
286
267
 
287
- for(let key in this.env) {
288
- options.env[key] = String(this.env[key])
289
- }
268
+ // for(let key in this.env) {
269
+ // options.env[key] = String(this.env[key])
270
+ // }
290
271
 
291
272
  // sudo-prompt uses TEMP
292
273
  await fs.promises.mkdir(this.env.TEMP, { recursive: true }).catch((e) => { })
@@ -297,7 +278,6 @@ class Shell {
297
278
  // Modify process.env (and need to immediately revert it back to original process.env so as to not affect other logic)
298
279
  let old_env = process.env
299
280
  process.env = this.env
300
- console.log("sudo process.env", process.env)
301
281
  sudo.exec(params.message, options, (err, stdout, stderr) => {
302
282
  if (err) {
303
283
  console.log("SUDOPROMPT ERR", err)
@@ -343,7 +323,6 @@ class Shell {
343
323
  return;
344
324
  }
345
325
  let chunk = message.slice(i, i+1024)
346
- console.log("Writing chunk", chunk)
347
326
  this.ptyProcess.write(chunk)
348
327
  i += 1024;
349
328
  }, 10);
@@ -972,14 +951,7 @@ class Shell {
972
951
  this.ondata({ raw: `\r\n\r\n██ Detached from Shell ${this.id}\r\n\r\n` })
973
952
  }
974
953
  }
975
- runSequentially(tasks) {
976
- let chain = Promise.resolve();
977
- for (const task of tasks) {
978
- chain = chain.then(() => task());
979
- }
980
- return chain;
981
- }
982
- kill(message, force) {
954
+ kill(message, force, cb) {
983
955
  console.log("KILL")
984
956
 
985
957
  this.done = true
@@ -1004,36 +976,24 @@ class Shell {
1004
976
  this.vt.dispose()
1005
977
  this.queue.killAndDrain()
1006
978
  if (this.ptyProcess) {
1007
- if (this.kill_messages) {
1008
- console.log({ kill_messages: this.kill_messages })
1009
- let promises = this.kill_messages.map((m) => {
1010
- return new Promise(async (resolve, reject) => {
1011
- await this.kernel.exec(m, this.ondata)
1012
- resolve()
1013
- })
1014
- })
1015
- this.runSequentially(promises).then(() => {
1016
- console.log("Running kill message", { kill_messages })
1017
- this.ptyProcess.write(kill_messages)
979
+ if (cb) {
980
+ console.log("tree kill", this.ptyProcess.pid)
981
+ kill(this.ptyProcess.pid, 'SIGKILL', () => {
1018
982
  this.ptyProcess.kill()
1019
983
  this.ptyProcess = undefined
1020
- // automatically remove the shell from this.kernel.shells
1021
- this.kernel.shell.rm(this.id)
1022
- this.ondata({ raw: `\r\n\r\n██ Terminated Shell ${this.id}\r\n████\r\n` })
1023
- })
984
+ cb()
985
+ });
1024
986
  } else {
987
+ console.log("tree kill", this.ptyProcess.pid)
988
+ kill(this.ptyProcess.pid, 'SIGKILL');
1025
989
  this.ptyProcess.kill()
1026
990
  this.ptyProcess = undefined
1027
- // automatically remove the shell from this.kernel.shells
1028
- this.kernel.shell.rm(this.id)
1029
- this.ondata({ raw: `\r\n\r\n██ Terminated Shell ${this.id}\r\n████\r\n` })
1030
991
  }
1031
- } else {
1032
- // automatically remove the shell from this.kernel.shells
1033
- this.kernel.shell.rm(this.id)
1034
- this.ondata({ raw: `\r\n\r\n██ Terminated Shell ${this.id}\r\n████\r\n` })
1035
992
  }
1036
993
 
994
+ // automatically remove the shell from this.kernel.shells
995
+ this.kernel.shell.rm(this.id)
996
+ this.ondata({ raw: `\r\n\r\n██ Terminated Shell ${this.id}\r\n████\r\n` })
1037
997
 
1038
998
  }
1039
999
  log() {
package/kernel/shells.js CHANGED
@@ -358,7 +358,7 @@ class Shells {
358
358
  stop (request, message) {
359
359
  return this.kill(request, message)
360
360
  }
361
- reset() {
361
+ reset(cb) {
362
362
  let info = this.shells.map((s) => {
363
363
  return { id: s.id, group: s.group, cmd: s.cmd }
364
364
  })
@@ -367,9 +367,19 @@ class Shells {
367
367
  for(let i=0; i<this.shells.length; i++) {
368
368
  shells.push(this.shells[i])
369
369
  }
370
+ let count = 0
370
371
  for(let shell of shells) {
371
372
  console.log("[Kill Shell]", { id: shell.id, group: shell.group, cmd: shell.cmd })
372
- shell.kill("", true)
373
+ if (cb) {
374
+ shell.kill("", true, () => {
375
+ count++
376
+ if (count >= shells.length) {
377
+ cb()
378
+ }
379
+ })
380
+ } else {
381
+ shell.kill("", true)
382
+ }
373
383
  }
374
384
  }
375
385
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pinokiod",
3
- "version": "3.8.22",
3
+ "version": "3.8.23",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -60,6 +60,7 @@
60
60
  "sudo-prompt-programfiles-x86": "^9.2.10",
61
61
  "symlink-dir": "^5.2.1",
62
62
  "systeminformation": "^5.18.4",
63
+ "tree-kill": "^1.2.2",
63
64
  "uuid": "^9.0.0",
64
65
  "wait-on": "^7.2.0",
65
66
  "which": "^5.0.0",
package/server/index.js CHANGED
@@ -3846,13 +3846,19 @@ class Server {
3846
3846
  });
3847
3847
  process.on('SIGINT', () => {
3848
3848
  console.log("SIGINT Event")
3849
- if (this.kernel && this.kernel.shell) this.kernel.shell.reset()
3850
- process.exit()
3849
+ if (this.kernel && this.kernel.shell) {
3850
+ this.kernel.shell.reset(() => {
3851
+ process.exit()
3852
+ })
3853
+ }
3851
3854
  })
3852
3855
  process.on('SIGTERM', () => {
3853
3856
  console.log("SIGTERM Event")
3854
- if (this.kernel && this.kernel.shell) this.kernel.shell.reset()
3855
- process.exit()
3857
+ if (this.kernel && this.kernel.shell) {
3858
+ this.kernel.shell.reset(() => {
3859
+ process.exit()
3860
+ })
3861
+ }
3856
3862
  })
3857
3863
  // process.on('exit', () => {
3858
3864
  // console.log("exit Event")