querysub 0.256.0 → 0.257.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "querysub",
3
- "version": "0.256.0",
3
+ "version": "0.257.0",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
6
  "note1": "note on node-forge fork, see https://github.com/digitalbazaar/forge/issues/744 for details",
@@ -472,6 +472,11 @@ if (isServer()) {
472
472
  }
473
473
  }
474
474
 
475
+ export async function forceRemoveNode(nodeId: string) {
476
+ await archives().del(nodeId);
477
+ void tellEveryoneNodesChanges();
478
+ }
479
+
475
480
 
476
481
  /** Called on shutdown, to completely remove this node from discovery. */
477
482
  export async function nodeDiscoveryShutdown() {
@@ -48,6 +48,8 @@ import yargs, { check } from "yargs";
48
48
  import { parseArgsFactory } from "../misc/rawParams";
49
49
 
50
50
  import * as typesafecss from "typesafecss";
51
+
52
+
51
53
  typesafecss.setMeasureBlock(measureBlock);
52
54
  typesafecss.setDelayFnc(async fnc => {
53
55
  await (clientWatcher.waitForBeforeTriggerFinished() || Promise.resolve());
@@ -1254,6 +1256,13 @@ setImmediate(async () => {
1254
1256
  await import("../5-diagnostics/nodeMetadata");
1255
1257
  });
1256
1258
 
1259
+ setImmediate(async () => {
1260
+ if (isNode()) {
1261
+ const { doRegisterNodeForMachineCleanup } = await import("../deployManager/machineSchema");
1262
+ doRegisterNodeForMachineCleanup();
1263
+ }
1264
+ });
1265
+
1257
1266
  registerGetCompressNetwork(() => Querysub.COMPRESS_NETWORK);
1258
1267
  registerGetCompressDisk(() => Querysub.COMPRESS_DISK);
1259
1268
 
@@ -1269,4 +1278,5 @@ import { css } from "../4-dom/css";
1269
1278
  import { getCountPerPaint } from "../functional/onNextPaint";
1270
1279
  import { addEpsilons } from "../bits";
1271
1280
  import { blue } from "socket-function/src/formatting/logColors";
1281
+ import { MachineController } from "../deployManager/machineController";
1272
1282
 
@@ -2,9 +2,9 @@ import "../inject";
2
2
 
3
3
  import { measureWrap } from "socket-function/src/profiling/measure";
4
4
  import { getOwnMachineId } from "../-a-auth/certs";
5
- import { getOurNodeId, getOurNodeIdAssert } from "../-f-node-discovery/NodeDiscovery";
5
+ import { forceRemoveNode, getOurNodeId, getOurNodeIdAssert } from "../-f-node-discovery/NodeDiscovery";
6
6
  import { Querysub } from "../4-querysub/QuerysubController";
7
- import { MACHINE_RESYNC_INTERVAL, MachineServiceControllerBase, MachineInfo, ServiceConfig, serviceConfigs, SERVICE_FOLDER, machineInfos } from "./machineSchema";
7
+ import { MACHINE_RESYNC_INTERVAL, MachineServiceControllerBase, MachineInfo, ServiceConfig, serviceConfigs, SERVICE_FOLDER, machineInfos, SERVICE_NODE_FILE_NAME } from "./machineSchema";
8
8
  import { runPromise } from "../functional/runCommand";
9
9
  import { getExternalIP } from "socket-function/src/networking";
10
10
  import { errorToUndefined, errorToUndefinedSilent } from "../errors";
@@ -305,10 +305,17 @@ const getScreenState = measureWrap(async function getScreenState(populateIsProce
305
305
 
306
306
  return screenList;
307
307
  });
308
+ async function removeOldNodeId(screenName: string) {
309
+ let screenNameFile = os.homedir() + "/" + SERVICE_FOLDER + screenName + "/" + SERVICE_NODE_FILE_NAME;
310
+ if (fs.existsSync(screenNameFile)) {
311
+ let nodeId = await fs.promises.readFile(screenNameFile, "utf8");
312
+ await fs.promises.unlink(screenNameFile);
313
+ await forceRemoveNode(nodeId);
314
+ }
315
+ }
308
316
  const runScreenCommand = measureWrap(async function runScreenCommand(config: {
309
317
  screenName: string;
310
318
  command: string;
311
- folder: string;
312
319
  }) {
313
320
  let screenName = config.screenName;
314
321
  // C:/cygwin64/bin/tmux has-session -t myproj 2>/dev/null || C:/cygwin64/bin/tmux new-session -d -s myproj
@@ -321,6 +328,7 @@ const runScreenCommand = measureWrap(async function runScreenCommand(config: {
321
328
  await runPromise(`${prefix}tmux send-keys -t ${screenName} 'C-c' Enter`);
322
329
  await delay(1000);
323
330
 
331
+
324
332
  let screens = await getScreenState();
325
333
  let screen = screens.find(x => x.screenName === screenName);
326
334
  let pid = screen?.pid;
@@ -343,23 +351,24 @@ const runScreenCommand = measureWrap(async function runScreenCommand(config: {
343
351
  await runScreenCommand({
344
352
  screenName,
345
353
  command: config.command,
346
- folder: config.folder,
347
354
  });
348
355
  return;
349
356
  }
350
357
  }
351
358
  }
352
- await runPromise(`${prefix}tmux send-keys -t ${screenName} 'cd ${config.folder}' Enter`);
359
+ await removeOldNodeId(screenName);
360
+ let folder = os.homedir() + "/" + SERVICE_FOLDER + screenName + "/";
361
+ await runPromise(`${prefix}tmux send-keys -t ${screenName} 'cd ${folder}git' Enter`);
353
362
  let command = `#!/bin/bash
354
363
  ${config.command}
355
364
  `;
356
- await fs.promises.writeFile(config.folder + "../command.sh", command);
365
+ await fs.promises.writeFile(folder + "command.sh", command);
357
366
  await runPromise(`${prefix}tmux send-keys -t ${screenName} 'bash ../command.sh' Enter`);
358
367
 
359
368
  // Setup pipe-pane as well
360
369
 
361
- let pipeFile = path.resolve(config.folder + "../pipe.txt");
362
- let pipeScript = path.resolve(config.folder + "../pipe.sh");
370
+ let pipeFile = path.resolve(folder + "pipe.txt");
371
+ let pipeScript = path.resolve(folder + "pipe.sh");
363
372
  await fs.promises.writeFile(pipeScript, `#!/bin/bash
364
373
  line_count=0
365
374
  while IFS= read -r line; do
@@ -390,6 +399,7 @@ const killScreen = measureWrap(async function killScreen(config: {
390
399
  }) {
391
400
  let prefix = getTmuxPrefix();
392
401
  await runPromise(`${prefix}tmux kill-session -t ${config.screenName}`);
402
+ await removeOldNodeId(config.screenName);
393
403
  });
394
404
  const ensureGitSynced = measureWrap(async function ensureGitSynced(config: {
395
405
  // Ensures existingFolder is the repo, as in, cwd to it, and git clone ., if needed. Reset the hash, in whatever way we need to, to force it to gitRef (git add --all and stash, etc, etc).
@@ -515,7 +525,6 @@ const resyncServicesBase = runInSerial(measureWrap(async function resyncServices
515
525
  await runScreenCommand({
516
526
  screenName,
517
527
  command: config.parameters.command,
518
- folder: gitFolder,
519
528
  });
520
529
  await delay(2000);
521
530
  let newScreens = await getScreenState(false);
@@ -18,9 +18,12 @@ import { OnServiceChange } from "./machineController";
18
18
  import path from "path";
19
19
  import fs from "fs";
20
20
  import { runPromise } from "../functional/runCommand";
21
+ import { isNode } from "typesafecss";
21
22
 
22
- export const SERVICE_FOLDER = "machine-services/";
23
+ const SERVICE_FOLDER_NAME = "machine-services";
24
+ export const SERVICE_FOLDER = `${SERVICE_FOLDER_NAME}/`;
23
25
  export const MACHINE_RESYNC_INTERVAL = timeInMinute * 15;
26
+ export const SERVICE_NODE_FILE_NAME = "serviceNodeId.txt";
24
27
 
25
28
  export type MachineInfo = {
26
29
  machineId: string;
@@ -83,6 +86,20 @@ export type ServiceConfig = {
83
86
  export const machineInfos = archiveJSONT<MachineInfo>(() => nestArchives("machines/machine-heartbeats/", getArchivesBackblaze(getDomain())));
84
87
  export const serviceConfigs = archiveJSONT<ServiceConfig>(() => nestArchives("machines/service-configs/", getArchivesBackblaze(getDomain())));
85
88
 
89
+ export function doRegisterNodeForMachineCleanup() {
90
+ if (isNode()) {
91
+ void SocketFunction.mountPromise.finally(() => {
92
+ void registerNodeForMachineCleanup(SocketFunction.mountedNodeId);
93
+ });
94
+ }
95
+ }
96
+ async function registerNodeForMachineCleanup(nodeId: string) {
97
+ let currentPath = path.resolve(".").replaceAll("\\", "/");
98
+ let array = currentPath.split("/");
99
+ if (array.at(-1) === "git" && array.at(-2) === SERVICE_FOLDER_NAME) {
100
+ await fs.promises.writeFile(array.slice(0, -2).join("/") + "/" + SERVICE_NODE_FILE_NAME, nodeId);
101
+ }
102
+ }
86
103
 
87
104
  export class MachineServiceControllerBase {
88
105
 
@@ -1,10 +1,4 @@
1
- OH, okay, so... we DO need machine update support, because... we will need to update them
2
-
3
-
4
- 7) Quick node removal on process crash OR removal
5
- - In the service, check our parent folder to see if we are in a screen (/machine-services/git/), and then write our nodeId to /machine-services/nodeId
6
- - If we see a nodeId when we are removing a screen, or killing the service, then delete that nodeId from the nodeId directory (and call tellEveryoneNodesChanges)
7
- 7.1) Verify this by killing a lot of services (the function runner?), by just poking it over and over, verifying the nodes are quickly deleted
1
+ 7.1) Verify quick node removal work by having a repeatedly crashing service, verifying the node exists, and then goes away on crash.
8
2
 
9
3
 
10
4