Fix StartOS 0.4 TypeScript packaging to match SDK API
This commit is contained in:
Generated
Vendored
+8
@@ -0,0 +1,8 @@
|
||||
import { T } from '../../../../base/lib';
|
||||
/**
|
||||
* The result of a single health check invocation.
|
||||
*
|
||||
* Contains a `result` field ("success", "failure", or "starting") and an optional `message`.
|
||||
* This is the unnamed variant -- the health check name is added by the framework.
|
||||
*/
|
||||
export type HealthCheckResult = Omit<T.NamedHealthCheckResult, 'name'>;
|
||||
Generated
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
//# sourceMappingURL=HealthCheckResult.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"HealthCheckResult.js","sourceRoot":"","sources":["../../../../../package/lib/health/checkFns/HealthCheckResult.ts"],"names":[],"mappings":""}
|
||||
Generated
Vendored
+13
@@ -0,0 +1,13 @@
|
||||
import { Effects } from '../../../../base/lib/types';
|
||||
import { HealthCheckResult } from './HealthCheckResult';
|
||||
export declare function containsAddress(x: string, port: number, address?: bigint): boolean;
|
||||
/**
|
||||
* This is used to check if a port is listening on the system.
|
||||
* Used during the health check fn or the check main fn.
|
||||
*/
|
||||
export declare function checkPortListening(effects: Effects, port: number, options: {
|
||||
errorMessage: string;
|
||||
successMessage: string;
|
||||
timeoutMessage?: string;
|
||||
timeout?: number;
|
||||
}): Promise<HealthCheckResult>;
|
||||
Generated
Vendored
+79
@@ -0,0 +1,79 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || (function () {
|
||||
var ownKeys = function(o) {
|
||||
ownKeys = Object.getOwnPropertyNames || function (o) {
|
||||
var ar = [];
|
||||
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
||||
return ar;
|
||||
};
|
||||
return ownKeys(o);
|
||||
};
|
||||
return function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.containsAddress = containsAddress;
|
||||
exports.checkPortListening = checkPortListening;
|
||||
const util_1 = require("../../util");
|
||||
const node_util_1 = require("node:util");
|
||||
const CP = __importStar(require("node:child_process"));
|
||||
const cpExec = (0, node_util_1.promisify)(CP.exec);
|
||||
function containsAddress(x, port, address) {
|
||||
const readPorts = x
|
||||
.split('\n')
|
||||
.filter(Boolean)
|
||||
.splice(1)
|
||||
.map((x) => x.split(' ').filter(Boolean)[1]?.split(':'))
|
||||
.filter((x) => x?.length > 1)
|
||||
.map(([addr, p]) => [BigInt(`0x${addr}`), Number.parseInt(p, 16)]);
|
||||
return !!readPorts.find(([addr, p]) => (address === undefined || address === addr) && port === p);
|
||||
}
|
||||
/**
|
||||
* This is used to check if a port is listening on the system.
|
||||
* Used during the health check fn or the check main fn.
|
||||
*/
|
||||
async function checkPortListening(effects, port, options) {
|
||||
return Promise.race([
|
||||
Promise.resolve().then(async () => {
|
||||
const hasAddress = containsAddress(await cpExec(`cat /proc/net/tcp`, {}).then(util_1.stringFromStdErrOut), port) ||
|
||||
containsAddress(await cpExec(`cat /proc/net/tcp6`, {}).then(util_1.stringFromStdErrOut), port, BigInt(0)) ||
|
||||
containsAddress(await cpExec('cat /proc/net/udp', {}).then(util_1.stringFromStdErrOut), port) ||
|
||||
containsAddress(await cpExec('cat /proc/net/udp6', {}).then(util_1.stringFromStdErrOut), port, BigInt(0));
|
||||
if (hasAddress) {
|
||||
return { result: 'success', message: options.successMessage };
|
||||
}
|
||||
return {
|
||||
result: 'failure',
|
||||
message: options.errorMessage,
|
||||
};
|
||||
}),
|
||||
new Promise((resolve) => {
|
||||
setTimeout(() => resolve({
|
||||
result: 'failure',
|
||||
message: options.timeoutMessage || `Timeout trying to check port ${port}`,
|
||||
}), options.timeout ?? 1_000);
|
||||
}),
|
||||
]);
|
||||
}
|
||||
//# sourceMappingURL=checkPortListening.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"checkPortListening.js","sourceRoot":"","sources":["../../../../../package/lib/health/checkFns/checkPortListening.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAQA,0CAWC;AAMD,gDAmDC;AA3ED,qCAAgD;AAEhD,yCAAqC;AACrC,uDAAwC;AAExC,MAAM,MAAM,GAAG,IAAA,qBAAS,EAAC,EAAE,CAAC,IAAI,CAAC,CAAA;AAEjC,SAAgB,eAAe,CAAC,CAAS,EAAE,IAAY,EAAE,OAAgB;IACvE,MAAM,SAAS,GAAG,CAAC;SAChB,KAAK,CAAC,IAAI,CAAC;SACX,MAAM,CAAC,OAAO,CAAC;SACf,MAAM,CAAC,CAAC,CAAC;SACT,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;SACvD,MAAM,CAAC,CAAC,CAAC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EAAE,OAAO,CAAC,cAAc,EAAE,CAAA;YAC/D,CAAC;YACD,OAAO;gBACL,MAAM,EAAE,SAAS;gBACjB,OAAO,EAAE,OAAO,CAAC,YAAY;aAC9B,CAAA;QACH,CAAC,CAAC;QACF,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;YACtB,UAAU,CACR,GAAG,EAAE,CACH,OAAO,CAAC;gBACN,MAAM,EAAE,SAAS;gBACjB,OAAO,EACL,OAAO,CAAC,cAAc,IAAI,gCAAgC,IAAI,EAAE;aACnE,CAAC,EACJ,OAAO,CAAC,OAAO,IAAI,KAAK,CACzB,CAAA;QACH,CAAC,CAAC;KACH,CAAC,CAAA;AACJ,CAAC"}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
import { Effects } from '../../../../base/lib/types';
|
||||
import { HealthCheckResult } from './HealthCheckResult';
|
||||
import 'isomorphic-fetch';
|
||||
/**
|
||||
* This is a helper function to check if a web url is reachable.
|
||||
* @param url
|
||||
* @param createSuccess
|
||||
* @returns
|
||||
*/
|
||||
export declare const checkWebUrl: (effects: Effects, url: string, { timeout, successMessage, errorMessage, }?: {
|
||||
timeout?: number | undefined;
|
||||
successMessage?: string | undefined;
|
||||
errorMessage?: string | undefined;
|
||||
}) => Promise<HealthCheckResult>;
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.checkWebUrl = void 0;
|
||||
const util_1 = require("../../util");
|
||||
const index_1 = require("./index");
|
||||
require("isomorphic-fetch");
|
||||
/**
|
||||
* This is a helper function to check if a web url is reachable.
|
||||
* @param url
|
||||
* @param createSuccess
|
||||
* @returns
|
||||
*/
|
||||
const checkWebUrl = async (effects, url, { timeout = 1000, successMessage = `Reached ${url}`, errorMessage = `Error while fetching URL: ${url}`, } = {}) => {
|
||||
return Promise.race([fetch(url), (0, index_1.timeoutPromise)(timeout)])
|
||||
.then((x) => ({
|
||||
result: 'success',
|
||||
message: successMessage,
|
||||
}))
|
||||
.catch((e) => {
|
||||
console.warn(`Error while fetching URL: ${url}`);
|
||||
console.error(JSON.stringify(e));
|
||||
console.error((0, util_1.asError)(e));
|
||||
return { result: 'failure', message: errorMessage };
|
||||
});
|
||||
};
|
||||
exports.checkWebUrl = checkWebUrl;
|
||||
//# sourceMappingURL=checkWebUrl.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"checkWebUrl.js","sourceRoot":"","sources":["../../../../../package/lib/health/checkFns/checkWebUrl.ts"],"names":[],"mappings":";;;AACA,qCAAoC;AAEpC,mCAAwC;AACxC,4BAAyB;AAEzB;;;;;GAKG;AACI,MAAM,WAAW,GAAG,KAAK,EAC9B,OAAgB,EAChB,GAAW,EACX,EACE,OAAO,GAAG,IAAI,EACd,cAAc,GAAG,WAAW,GAAG,EAAE,EACjC,YAAY,GAAG,6BAA6B,GAAG,EAAE,GAClD,GAAG,EAAE,EACsB,EAAE;IAC9B,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,IAAA,sBAAc,EAAC,OAAO,CAAC,CAAC,CAAC;SACvD,IAAI,CACH,CAAC,CAAC,EAAE,EAAE,CACJ,CAAC;QACC,MAAM,EAAE,SAAS;QACjB,OAAO,EAAE,cAAc;KACxB,CAAU,CACd;SACA,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE;QACX,OAAO,CAAC,IAAI,CAAC,6BAA6B,GAAG,EAAE,CAAC,CAAA;QAChD,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAA;QAChC,OAAO,CAAC,KAAK,CAAC,IAAA,cAAO,EAAC,CAAC,CAAC,CAAC,CAAA;QACzB,OAAO,EAAE,MAAM,EAAE,SAAkB,EAAE,OAAO,EAAE,YAAY,EAAE,CAAA;IAC9D,CAAC,CAAC,CAAA;AACN,CAAC,CAAA;AAvBY,QAAA,WAAW,eAuBvB"}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
import { runHealthScript } from './runHealthScript';
|
||||
export { checkPortListening } from './checkPortListening';
|
||||
export { HealthCheckResult } from './HealthCheckResult';
|
||||
export { checkWebUrl } from './checkWebUrl';
|
||||
/**
|
||||
* Create a promise that rejects after the specified timeout.
|
||||
* Useful for racing against long-running health checks.
|
||||
*
|
||||
* @param ms - Timeout duration in milliseconds
|
||||
* @param options.message - Custom error message (defaults to "Timed out")
|
||||
* @returns A promise that never resolves, only rejects after the timeout
|
||||
*/
|
||||
export declare function timeoutPromise(ms: number, { message }?: {
|
||||
message?: string | undefined;
|
||||
}): Promise<never>;
|
||||
export { runHealthScript };
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.runHealthScript = exports.checkWebUrl = exports.checkPortListening = void 0;
|
||||
exports.timeoutPromise = timeoutPromise;
|
||||
const runHealthScript_1 = require("./runHealthScript");
|
||||
Object.defineProperty(exports, "runHealthScript", { enumerable: true, get: function () { return runHealthScript_1.runHealthScript; } });
|
||||
var checkPortListening_1 = require("./checkPortListening");
|
||||
Object.defineProperty(exports, "checkPortListening", { enumerable: true, get: function () { return checkPortListening_1.checkPortListening; } });
|
||||
var checkWebUrl_1 = require("./checkWebUrl");
|
||||
Object.defineProperty(exports, "checkWebUrl", { enumerable: true, get: function () { return checkWebUrl_1.checkWebUrl; } });
|
||||
/**
|
||||
* Create a promise that rejects after the specified timeout.
|
||||
* Useful for racing against long-running health checks.
|
||||
*
|
||||
* @param ms - Timeout duration in milliseconds
|
||||
* @param options.message - Custom error message (defaults to "Timed out")
|
||||
* @returns A promise that never resolves, only rejects after the timeout
|
||||
*/
|
||||
function timeoutPromise(ms, { message = 'Timed out' } = {}) {
|
||||
return new Promise((resolve, reject) => setTimeout(() => reject(new Error(message)), ms));
|
||||
}
|
||||
//# sourceMappingURL=index.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../package/lib/health/checkFns/index.ts"],"names":[],"mappings":";;;AAaA,wCAIC;AAjBD,uDAAmD;AAkB1C,gGAlBA,iCAAe,OAkBA;AAjBxB,2DAAyD;AAAhD,wHAAA,kBAAkB,OAAA;AAE3B,6CAA2C;AAAlC,0GAAA,WAAW,OAAA;AAEpB;;;;;;;GAOG;AACH,SAAgB,cAAc,CAAC,EAAU,EAAE,EAAE,OAAO,GAAG,WAAW,EAAE,GAAG,EAAE;IACvE,OAAO,IAAI,OAAO,CAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,CAC5C,UAAU,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,EAAE,EAAE,CAAC,CACjD,CAAA;AACH,CAAC"}
|
||||
Generated
Vendored
+15
@@ -0,0 +1,15 @@
|
||||
import { HealthCheckResult } from './HealthCheckResult';
|
||||
import { SubContainer } from '../../util/SubContainer';
|
||||
import { SDKManifest } from '../../types';
|
||||
/**
|
||||
* Running a health script, is used when we want to have a simple
|
||||
* script in bash or something like that. It should return something that is useful
|
||||
* in {result: string} else it is considered an error
|
||||
* @param param0
|
||||
* @returns
|
||||
*/
|
||||
export declare const runHealthScript: <Manifest extends SDKManifest>(runCommand: string[], subcontainer: SubContainer<Manifest>, { timeout, errorMessage, message, }?: {
|
||||
timeout?: number | undefined;
|
||||
errorMessage?: string | undefined;
|
||||
message?: ((res: string) => string) | undefined;
|
||||
}) => Promise<HealthCheckResult>;
|
||||
Generated
Vendored
+28
@@ -0,0 +1,28 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.runHealthScript = void 0;
|
||||
const index_1 = require("./index");
|
||||
/**
|
||||
* Running a health script, is used when we want to have a simple
|
||||
* script in bash or something like that. It should return something that is useful
|
||||
* in {result: string} else it is considered an error
|
||||
* @param param0
|
||||
* @returns
|
||||
*/
|
||||
const runHealthScript = async (runCommand, subcontainer, { timeout = 30000, errorMessage = `Error while running command: ${runCommand}`, message = (res) => `Have ran script ${runCommand} and the result: ${res}`, } = {}) => {
|
||||
const res = await Promise.race([
|
||||
subcontainer.execFail(runCommand),
|
||||
(0, index_1.timeoutPromise)(timeout),
|
||||
]).catch((e) => {
|
||||
console.warn(errorMessage);
|
||||
console.warn(JSON.stringify(e));
|
||||
console.warn(e.toString());
|
||||
throw { result: 'failure', message: errorMessage };
|
||||
});
|
||||
return {
|
||||
result: 'success',
|
||||
message: message(res.stdout.toString()),
|
||||
};
|
||||
};
|
||||
exports.runHealthScript = runHealthScript;
|
||||
//# sourceMappingURL=runHealthScript.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"runHealthScript.js","sourceRoot":"","sources":["../../../../../package/lib/health/checkFns/runHealthScript.ts"],"names":[],"mappings":";;;AACA,mCAAwC;AAIxC;;;;;;GAMG;AACI,MAAM,eAAe,GAAG,KAAK,EAClC,UAAoB,EACpB,YAAoC,EACpC,EACE,OAAO,GAAG,KAAK,EACf,YAAY,GAAG,gCAAgC,UAAU,EAAE,EAC3D,OAAO,GAAG,CAAC,GAAW,EAAE,EAAE,CACxB,mBAAmB,UAAU,oBAAoB,GAAG,EAAE,MACtD,EAAE,EACsB,EAAE;IAC9B,MAAM,GAAG,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC;QAC7B,YAAY,CAAC,QAAQ,CAAC,UAAU,CAAC;QACjC,IAAA,sBAAc,EAAC,OAAO,CAAC;KACxB,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE;QACb,OAAO,CAAC,IAAI,CAAC,YAAY,CAAC,CAAA;QAC1B,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAA;QAC/B,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAA;QAC1B,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,YAAY,EAAuB,CAAA;IACzE,CAAC,CAAC,CAAA;IACF,OAAO;QACL,MAAM,EAAE,SAAS;QACjB,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;KACnB,CAAA;AACxB,CAAC,CAAA;AAvBY,QAAA,eAAe,mBAuB3B"}
|
||||
Reference in New Issue
Block a user