@milaboratories/pl-deployments 2.16.4 → 2.16.6
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/dist/_virtual/_rolldown/runtime.cjs +7 -13
- package/dist/common/os_and_arch.cjs +1 -2
- package/dist/common/os_and_arch.cjs.map +1 -1
- package/dist/common/os_and_arch.js +1 -1
- package/dist/common/pl_binary.cjs +5 -6
- package/dist/common/pl_binary.cjs.map +1 -1
- package/dist/common/pl_binary.d.ts.map +1 -0
- package/dist/common/pl_binary.js +1 -2
- package/dist/common/pl_binary.js.map +1 -1
- package/dist/common/pl_binary_download.cjs +3 -4
- package/dist/common/pl_binary_download.cjs.map +1 -1
- package/dist/common/pl_binary_download.d.ts.map +1 -0
- package/dist/common/pl_binary_download.js +1 -2
- package/dist/common/pl_binary_download.js.map +1 -1
- package/dist/common/pl_version.cjs +2 -3
- package/dist/common/pl_version.cjs.map +1 -1
- package/dist/common/pl_version.d.ts.map +1 -0
- package/dist/common/pl_version.js +1 -2
- package/dist/common/pl_version.js.map +1 -1
- package/dist/index.cjs +7 -8
- package/dist/index.js +1 -2
- package/dist/local/pid.cjs +2 -3
- package/dist/local/pid.cjs.map +1 -1
- package/dist/local/pid.js +1 -2
- package/dist/local/pid.js.map +1 -1
- package/dist/local/pl.cjs +6 -7
- package/dist/local/pl.cjs.map +1 -1
- package/dist/local/pl.d.ts.map +1 -0
- package/dist/local/pl.js +1 -2
- package/dist/local/pl.js.map +1 -1
- package/dist/local/process.cjs +2 -3
- package/dist/local/process.cjs.map +1 -1
- package/dist/local/process.d.ts.map +1 -0
- package/dist/local/process.js +1 -2
- package/dist/local/process.js.map +1 -1
- package/dist/local/trace.cjs +1 -2
- package/dist/local/trace.cjs.map +1 -1
- package/dist/local/trace.d.ts.map +1 -0
- package/dist/local/trace.js +1 -1
- package/dist/package.cjs +6 -7
- package/dist/package.js +1 -1
- package/dist/ssh/connection_info.cjs +2 -3
- package/dist/ssh/connection_info.cjs.map +1 -1
- package/dist/ssh/connection_info.d.ts.map +1 -0
- package/dist/ssh/connection_info.js +1 -2
- package/dist/ssh/connection_info.js.map +1 -1
- package/dist/ssh/pl.cjs +8 -9
- package/dist/ssh/pl.cjs.map +1 -1
- package/dist/ssh/pl.d.ts.map +1 -0
- package/dist/ssh/pl.js +1 -2
- package/dist/ssh/pl.js.map +1 -1
- package/dist/ssh/pl_paths.cjs +4 -5
- package/dist/ssh/pl_paths.cjs.map +1 -1
- package/dist/ssh/pl_paths.js +1 -2
- package/dist/ssh/pl_paths.js.map +1 -1
- package/dist/ssh/ssh.cjs +3 -4
- package/dist/ssh/ssh.cjs.map +1 -1
- package/dist/ssh/ssh.d.ts.map +1 -0
- package/dist/ssh/ssh.js +1 -2
- package/dist/ssh/ssh.js.map +1 -1
- package/dist/ssh/ssh_errors.cjs +2 -3
- package/dist/ssh/ssh_errors.cjs.map +1 -1
- package/dist/ssh/ssh_errors.js +1 -2
- package/dist/ssh/ssh_errors.js.map +1 -1
- package/dist/ssh/supervisord.cjs +3 -4
- package/dist/ssh/supervisord.cjs.map +1 -1
- package/dist/ssh/supervisord.d.ts.map +1 -0
- package/dist/ssh/supervisord.js +1 -2
- package/dist/ssh/supervisord.js.map +1 -1
- package/package.json +10 -10
package/dist/local/pl.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pl.js","names":["os"],"sources":["../../src/local/pl.ts"],"sourcesContent":["import type { ProcessOptions } from \"./process\";\nimport { isProcessAlive, processStop, processWaitStopped, processRun } from \"./process\";\nimport type { PlBinarySource } from \"../common/pl_binary\";\nimport { newDefaultPlBinarySource, resolveLocalPlBinaryPath } from \"../common/pl_binary\";\nimport type { MiLogger } from \"@milaboratories/ts-helpers\";\nimport { notEmpty } from \"@milaboratories/ts-helpers\";\nimport type { ChildProcess, SpawnOptions } from \"node:child_process\";\nimport { filePid, readPid, writePid } from \"./pid\";\nimport type { Trace } from \"./trace\";\nimport { withTrace } from \"./trace\";\nimport upath from \"upath\";\nimport fsp from \"node:fs/promises\";\nimport type { Required } from \"utility-types\";\nimport * as os from \"node:os\";\nimport type { ProxySettings } from \"@milaboratories/pl-http\";\nimport { defaultHttpDispatcher } from \"@milaboratories/pl-http\";\nimport { parseHttpAuth } from \"@milaboratories/pl-model-common\";\n\nexport const LocalConfigYaml = \"config-local.yaml\";\n\n/**\n * Represents a local running pl-core,\n * and has methods to start, check if it's running, stop and wait for stopping it.\n * Also, a hook on pl-core closed can be provided.\n */\nexport class LocalPl {\n private instance?: ChildProcess;\n public pid?: number;\n private nRuns: number = 0;\n private lastRunHistory: Trace = {};\n private wasStopped = false;\n\n constructor(\n private readonly logger: MiLogger,\n private readonly workingDir: string,\n private readonly startOptions: ProcessOptions,\n private readonly initialStartHistory: Trace,\n private readonly onClose?: (pl: LocalPl) => Promise<void>,\n private readonly onError?: (pl: LocalPl) => Promise<void>,\n private readonly onCloseAndError?: (pl: LocalPl) => Promise<void>,\n private readonly onCloseAndErrorNoStop?: (pl: LocalPl) => Promise<void>,\n ) {}\n\n async start() {\n await withTrace(this.logger, async (trace, t) => {\n this.wasStopped = false;\n const instance = processRun(this.logger, this.startOptions);\n instance.on(\"error\", (e: any) => {\n this.logger.error(\n `error '${e}', while running platforma, started opts: ${JSON.stringify(this.debugInfo())}`,\n );\n\n // keep in mind there are no awaits here, it will be asynchronous\n if (this.onError !== undefined) void this.onError(this);\n if (this.onCloseAndError !== undefined) void this.onCloseAndError(this);\n if (this.onCloseAndErrorNoStop !== undefined && !this.wasStopped)\n void this.onCloseAndErrorNoStop(this);\n });\n instance.on(\"close\", () => {\n this.logger.warn(`platforma was closed, started opts: ${JSON.stringify(this.debugInfo())}`);\n\n // keep in mind there are no awaits here, it will be asynchronous\n if (this.onClose !== undefined) void this.onClose(this);\n if (this.onCloseAndError !== undefined) void this.onCloseAndError(this);\n if (this.onCloseAndErrorNoStop !== undefined && !this.wasStopped)\n void this.onCloseAndErrorNoStop(this);\n });\n\n trace(\"started\", true);\n\n const pidFile = trace(\"pidFile\", filePid(this.workingDir));\n trace(\"pid\", notEmpty(instance.pid));\n trace(\"pidWritten\", await writePid(pidFile, notEmpty(instance.pid)));\n\n this.nRuns++;\n this.instance = instance;\n this.pid = instance.pid;\n this.lastRunHistory = t;\n });\n }\n\n stop() {\n // TODO use this.instance to stop the process\n this.wasStopped = true;\n processStop(notEmpty(this.pid));\n }\n\n async waitStopped() {\n await processWaitStopped(notEmpty(this.pid), 15000);\n }\n\n stopped() {\n return this.wasStopped;\n }\n\n async isAlive(): Promise<boolean> {\n return await isProcessAlive(notEmpty(this.pid));\n }\n\n debugInfo() {\n return {\n lastRunHistory: this.lastRunHistory,\n nRuns: this.nRuns,\n pid: this.pid,\n workingDir: this.workingDir,\n initialStartHistory: this.initialStartHistory,\n wasStopped: this.wasStopped,\n };\n }\n}\n\n/** Options to start a local pl-core. */\nexport type LocalPlOptions = {\n /** From what directory start a process. */\n readonly workingDir: string;\n /** A string representation of yaml config. */\n readonly config: string;\n /** How to get a binary, download it or get an existing one (default: download latest version) */\n readonly plBinary?: PlBinarySource;\n /** Additional options for a process, environments, stdout, stderr etc. */\n readonly spawnOptions?: SpawnOptions;\n /**\n * If the previous pl-core was started from the same directory,\n * we can check if it's still running and then stop it before starting a new one.\n * (default: true)\n */\n readonly closeOld?: boolean;\n /**\n * Proxy settings to use to fetch the binary and pass it down\n * as a HTTPS_PROXY/HTTP_PROXY environment variable;\n * Backend only supports Basic auth.\n */\n readonly proxy?: ProxySettings;\n\n readonly onClose?: (pl: LocalPl) => Promise<void>;\n readonly onError?: (pl: LocalPl) => Promise<void>;\n readonly onCloseAndError?: (pl: LocalPl) => Promise<void>;\n readonly onCloseAndErrorNoStop?: (pl: LocalPl) => Promise<void>;\n};\n\nexport type LocalPlOptionsFull = Required<LocalPlOptions, \"plBinary\" | \"spawnOptions\" | \"closeOld\">;\n\n/**\n * Starts pl-core, if the option was provided downloads a binary, reads license environments etc.\n */\nexport async function localPlatformaInit(logger: MiLogger, _ops: LocalPlOptions): Promise<LocalPl> {\n // filling-in default values\n\n // Backend could consume a lot of CPU power,\n // we want to keep at least a couple for UI and other apps to work.\n const numCpu = Math.max(os.cpus().length - 2, 1);\n const ops = mergeDefaultOps(_ops, numCpu);\n\n return await withTrace(logger, async (trace, t) => {\n trace(\"startOptions\", { ...ops, config: \"too wordy\" });\n\n const workDir = upath.resolve(ops.workingDir);\n\n if (ops.closeOld) {\n trace(\"closeOld\", await localPlatformaReadPidAndStop(logger, workDir));\n }\n\n const configPath = upath.join(workDir, LocalConfigYaml);\n\n logger.info(`writing configuration '${configPath}'...`);\n await fsp.writeFile(configPath, ops.config);\n\n const plBinPath = upath.join(workDir, \"binaries\");\n const baseBinaryPath = await resolveLocalPlBinaryPath({\n logger,\n downloadDir: plBinPath,\n src: ops.plBinary,\n dispatcher: defaultHttpDispatcher(ops.proxy),\n });\n const binaryPath = trace(\"binaryPath\", upath.join(\"binaries\", baseBinaryPath));\n\n const env = { ...process.env };\n\n if (ops.proxy?.url) {\n const url = new URL(ops.proxy.url);\n if (ops.proxy.auth) {\n const parsed = parseHttpAuth(ops.proxy.auth);\n if (parsed.scheme !== \"Basic\") {\n throw new Error(`\\\nUnsupported auth scheme: ${parsed.scheme}. \\\nOnly Basic auth is supported by the backend.`);\n }\n url.username = parsed.username;\n url.password = parsed.password;\n }\n env.http_proxy = url.toString();\n env.https_proxy = url.toString();\n }\n\n const processOpts = plProcessOps(binaryPath, configPath, ops, workDir, env);\n trace(\"processOpts\", {\n cmd: processOpts.cmd,\n args: processOpts.args,\n cwd: processOpts.opts.cwd,\n });\n\n const pl = new LocalPl(\n logger,\n ops.workingDir,\n processOpts,\n t,\n ops.onClose,\n ops.onError,\n ops.onCloseAndError,\n ops.onCloseAndErrorNoStop,\n );\n await pl.start();\n\n return pl;\n });\n}\n\n/** Reads a pid of the old pl-core if it was started in the same working directory,\n * and closes it. */\nasync function localPlatformaReadPidAndStop(\n logger: MiLogger,\n workingDir: string,\n): Promise<Record<string, any>> {\n return await withTrace(logger, async (trace, t) => {\n const file = trace(\"pidFilePath\", filePid(workingDir));\n\n const oldPid = trace(\"pid\", await readPid(file));\n const alive = trace(\"wasAlive\", await isProcessAlive(oldPid));\n\n if (oldPid !== undefined && alive) {\n trace(\"stopped\", processStop(oldPid));\n try {\n trace(\"waitStopped\", await processWaitStopped(oldPid, 15_000)); // larger, that 10s we provide to backend in config.\n } catch {\n trace(\"forceStopped\", processStop(oldPid, true));\n trace(\"waitForceStopped\", await processWaitStopped(oldPid, 5_000));\n }\n }\n\n return t;\n });\n}\n\n/** Gets default options for the whole init process\n * and overrides them with the provided options. */\nexport function mergeDefaultOps(ops: LocalPlOptions, numCpu: number): LocalPlOptionsFull {\n const result: {\n plBinary: PlBinarySource;\n spawnOptions: SpawnOptions;\n closeOld: boolean;\n } = {\n plBinary: newDefaultPlBinarySource(),\n spawnOptions: {\n env: {\n GOMAXPROCS: String(numCpu),\n },\n },\n closeOld: true,\n };\n\n if (ops.spawnOptions?.env) {\n result.spawnOptions.env = { ...result.spawnOptions.env, ...ops.spawnOptions.env };\n }\n\n if (ops.spawnOptions) {\n const withoutEnv = { ...ops.spawnOptions };\n delete withoutEnv[\"env\"];\n result.spawnOptions = { ...result.spawnOptions, ...withoutEnv };\n }\n\n const withoutSpawnOps = { ...ops };\n delete withoutSpawnOps[\"spawnOptions\"];\n\n return { ...result, ...withoutSpawnOps };\n}\n\n/** Gets default options for a platforma local binary\n * and overrides them with the provided options. */\nexport function plProcessOps(\n binaryPath: any,\n configPath: string,\n ops: LocalPlOptionsFull,\n workDir: string,\n defaultEnv: Record<string, string | undefined>,\n): ProcessOptions {\n const result: ProcessOptions = {\n cmd: binaryPath,\n args: [\"--config\", configPath],\n opts: {\n env: { ...defaultEnv },\n cwd: workDir,\n stdio: [\"pipe\", \"ignore\", \"inherit\"],\n windowsHide: true, // hide a terminal on Windows\n },\n };\n\n if (ops.spawnOptions?.env) {\n result.opts.env = { ...result.opts.env, ...ops.spawnOptions.env };\n }\n\n const withoutEnv = { ...ops.spawnOptions };\n delete withoutEnv[\"env\"];\n result.opts = { ...result.opts, ...withoutEnv };\n\n return result;\n}\n"],"mappings":";;;;;;;;;;;;AAkBA,MAAa,kBAAkB;;;;;;AAO/B,IAAa,UAAb,MAAqB;CACnB,AAAQ;CACR,AAAO;CACP,AAAQ,QAAgB;CACxB,AAAQ,iBAAwB,EAAE;CAClC,AAAQ,aAAa;CAErB,YACE,AAAiB,QACjB,AAAiB,YACjB,AAAiB,cACjB,AAAiB,qBACjB,AAAiB,SACjB,AAAiB,SACjB,AAAiB,iBACjB,AAAiB,uBACjB;EARiB;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;CAGnB,MAAM,QAAQ;AACZ,QAAM,UAAU,KAAK,QAAQ,OAAO,OAAO,MAAM;AAC/C,QAAK,aAAa;GAClB,MAAM,WAAW,WAAW,KAAK,QAAQ,KAAK,aAAa;AAC3D,YAAS,GAAG,UAAU,MAAW;AAC/B,SAAK,OAAO,MACV,UAAU,EAAE,4CAA4C,KAAK,UAAU,KAAK,WAAW,CAAC,GACzF;AAGD,QAAI,KAAK,YAAY,OAAW,CAAK,KAAK,QAAQ,KAAK;AACvD,QAAI,KAAK,oBAAoB,OAAW,CAAK,KAAK,gBAAgB,KAAK;AACvE,QAAI,KAAK,0BAA0B,UAAa,CAAC,KAAK,WACpD,CAAK,KAAK,sBAAsB,KAAK;KACvC;AACF,YAAS,GAAG,eAAe;AACzB,SAAK,OAAO,KAAK,uCAAuC,KAAK,UAAU,KAAK,WAAW,CAAC,GAAG;AAG3F,QAAI,KAAK,YAAY,OAAW,CAAK,KAAK,QAAQ,KAAK;AACvD,QAAI,KAAK,oBAAoB,OAAW,CAAK,KAAK,gBAAgB,KAAK;AACvE,QAAI,KAAK,0BAA0B,UAAa,CAAC,KAAK,WACpD,CAAK,KAAK,sBAAsB,KAAK;KACvC;AAEF,SAAM,WAAW,KAAK;GAEtB,MAAM,UAAU,MAAM,WAAW,QAA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qB,QAAoC;CACvF,MAAM,SAIF;EACF,UAAU,0BAA0B;EACpC,cAAc,EACZ,KAAK,EACH,YAAY,OAAO,OAAO,EAC3B,EACF;EACD,UAAU;EACX;AAED,KAAI,IAAI,cAAc,IACpB,QAAO,aAAa,MAAM;EAAE,GAAG,OAAO,aAAa;EAAK,GAAG,IAAI,aAAa;EAAK;AAGnF,KAAI,IAAI,cAAc;EACpB,MAAM,aAAa,EAAE,GAAG,IAAI,cAAc;AAC1C,SAAO,WAAW;AAClB,SAAO,eAAe;GAAE,GAAG,OAAO;GAAc,GAAG;GAAY;;CAGjE,MAAM,kBAAkB,EAAE,GAAG,KAAK;AAClC,QAAO,gBAAgB;AAEvB,QAAO;EAAE,GAAG;EAAQ,GAAG;EAAiB;;;;AAK1C,SAAgB,aACd,YACA,YACA,KACA,SACA,YACgB;CAChB,MAAM,SAAyB;EAC7B,KAAK;EACL,MAAM,CAAC,YAAY,WAAW;EAC9B,MAAM;GACJ,KAAK,EAAE,GAAG,YAAY;GACtB,KAAK;GACL,OAAO;IAAC;IAAQ;IAAU;IAAU;GACpC,aAAa;GACd;EACF;AAED,KAAI,IAAI,cAAc,IACpB,QAAO,KAAK,MAAM;EAAE,GAAG,OAAO,KAAK;EAAK,GAAG,IAAI,aAAa;EAAK;CAGnE,MAAM,aAAa,EAAE,GAAG,IAAI,cAAc;AAC1C,QAAO,WAAW;AAClB,QAAO,OAAO;EAAE,GAAG,OAAO;EAAM,GAAG;EAAY;AAE/C,QAAO"}
|
|
1
|
+
{"version":3,"file":"pl.js","names":["os"],"sources":["../../src/local/pl.ts"],"sourcesContent":["import type { ProcessOptions } from \"./process\";\nimport { isProcessAlive, processStop, processWaitStopped, processRun } from \"./process\";\nimport type { PlBinarySource } from \"../common/pl_binary\";\nimport { newDefaultPlBinarySource, resolveLocalPlBinaryPath } from \"../common/pl_binary\";\nimport type { MiLogger } from \"@milaboratories/ts-helpers\";\nimport { notEmpty } from \"@milaboratories/ts-helpers\";\nimport type { ChildProcess, SpawnOptions } from \"node:child_process\";\nimport { filePid, readPid, writePid } from \"./pid\";\nimport type { Trace } from \"./trace\";\nimport { withTrace } from \"./trace\";\nimport upath from \"upath\";\nimport fsp from \"node:fs/promises\";\nimport type { Required } from \"utility-types\";\nimport * as os from \"node:os\";\nimport type { ProxySettings } from \"@milaboratories/pl-http\";\nimport { defaultHttpDispatcher } from \"@milaboratories/pl-http\";\nimport { parseHttpAuth } from \"@milaboratories/pl-model-common\";\n\nexport const LocalConfigYaml = \"config-local.yaml\";\n\n/**\n * Represents a local running pl-core,\n * and has methods to start, check if it's running, stop and wait for stopping it.\n * Also, a hook on pl-core closed can be provided.\n */\nexport class LocalPl {\n private instance?: ChildProcess;\n public pid?: number;\n private nRuns: number = 0;\n private lastRunHistory: Trace = {};\n private wasStopped = false;\n\n constructor(\n private readonly logger: MiLogger,\n private readonly workingDir: string,\n private readonly startOptions: ProcessOptions,\n private readonly initialStartHistory: Trace,\n private readonly onClose?: (pl: LocalPl) => Promise<void>,\n private readonly onError?: (pl: LocalPl) => Promise<void>,\n private readonly onCloseAndError?: (pl: LocalPl) => Promise<void>,\n private readonly onCloseAndErrorNoStop?: (pl: LocalPl) => Promise<void>,\n ) {}\n\n async start() {\n await withTrace(this.logger, async (trace, t) => {\n this.wasStopped = false;\n const instance = processRun(this.logger, this.startOptions);\n instance.on(\"error\", (e: any) => {\n this.logger.error(\n `error '${e}', while running platforma, started opts: ${JSON.stringify(this.debugInfo())}`,\n );\n\n // keep in mind there are no awaits here, it will be asynchronous\n if (this.onError !== undefined) void this.onError(this);\n if (this.onCloseAndError !== undefined) void this.onCloseAndError(this);\n if (this.onCloseAndErrorNoStop !== undefined && !this.wasStopped)\n void this.onCloseAndErrorNoStop(this);\n });\n instance.on(\"close\", () => {\n this.logger.warn(`platforma was closed, started opts: ${JSON.stringify(this.debugInfo())}`);\n\n // keep in mind there are no awaits here, it will be asynchronous\n if (this.onClose !== undefined) void this.onClose(this);\n if (this.onCloseAndError !== undefined) void this.onCloseAndError(this);\n if (this.onCloseAndErrorNoStop !== undefined && !this.wasStopped)\n void this.onCloseAndErrorNoStop(this);\n });\n\n trace(\"started\", true);\n\n const pidFile = trace(\"pidFile\", filePid(this.workingDir));\n trace(\"pid\", notEmpty(instance.pid));\n trace(\"pidWritten\", await writePid(pidFile, notEmpty(instance.pid)));\n\n this.nRuns++;\n this.instance = instance;\n this.pid = instance.pid;\n this.lastRunHistory = t;\n });\n }\n\n stop() {\n // TODO use this.instance to stop the process\n this.wasStopped = true;\n processStop(notEmpty(this.pid));\n }\n\n async waitStopped() {\n await processWaitStopped(notEmpty(this.pid), 15000);\n }\n\n stopped() {\n return this.wasStopped;\n }\n\n async isAlive(): Promise<boolean> {\n return await isProcessAlive(notEmpty(this.pid));\n }\n\n debugInfo() {\n return {\n lastRunHistory: this.lastRunHistory,\n nRuns: this.nRuns,\n pid: this.pid,\n workingDir: this.workingDir,\n initialStartHistory: this.initialStartHistory,\n wasStopped: this.wasStopped,\n };\n }\n}\n\n/** Options to start a local pl-core. */\nexport type LocalPlOptions = {\n /** From what directory start a process. */\n readonly workingDir: string;\n /** A string representation of yaml config. */\n readonly config: string;\n /** How to get a binary, download it or get an existing one (default: download latest version) */\n readonly plBinary?: PlBinarySource;\n /** Additional options for a process, environments, stdout, stderr etc. */\n readonly spawnOptions?: SpawnOptions;\n /**\n * If the previous pl-core was started from the same directory,\n * we can check if it's still running and then stop it before starting a new one.\n * (default: true)\n */\n readonly closeOld?: boolean;\n /**\n * Proxy settings to use to fetch the binary and pass it down\n * as a HTTPS_PROXY/HTTP_PROXY environment variable;\n * Backend only supports Basic auth.\n */\n readonly proxy?: ProxySettings;\n\n readonly onClose?: (pl: LocalPl) => Promise<void>;\n readonly onError?: (pl: LocalPl) => Promise<void>;\n readonly onCloseAndError?: (pl: LocalPl) => Promise<void>;\n readonly onCloseAndErrorNoStop?: (pl: LocalPl) => Promise<void>;\n};\n\nexport type LocalPlOptionsFull = Required<LocalPlOptions, \"plBinary\" | \"spawnOptions\" | \"closeOld\">;\n\n/**\n * Starts pl-core, if the option was provided downloads a binary, reads license environments etc.\n */\nexport async function localPlatformaInit(logger: MiLogger, _ops: LocalPlOptions): Promise<LocalPl> {\n // filling-in default values\n\n // Backend could consume a lot of CPU power,\n // we want to keep at least a couple for UI and other apps to work.\n const numCpu = Math.max(os.cpus().length - 2, 1);\n const ops = mergeDefaultOps(_ops, numCpu);\n\n return await withTrace(logger, async (trace, t) => {\n trace(\"startOptions\", { ...ops, config: \"too wordy\" });\n\n const workDir = upath.resolve(ops.workingDir);\n\n if (ops.closeOld) {\n trace(\"closeOld\", await localPlatformaReadPidAndStop(logger, workDir));\n }\n\n const configPath = upath.join(workDir, LocalConfigYaml);\n\n logger.info(`writing configuration '${configPath}'...`);\n await fsp.writeFile(configPath, ops.config);\n\n const plBinPath = upath.join(workDir, \"binaries\");\n const baseBinaryPath = await resolveLocalPlBinaryPath({\n logger,\n downloadDir: plBinPath,\n src: ops.plBinary,\n dispatcher: defaultHttpDispatcher(ops.proxy),\n });\n const binaryPath = trace(\"binaryPath\", upath.join(\"binaries\", baseBinaryPath));\n\n const env = { ...process.env };\n\n if (ops.proxy?.url) {\n const url = new URL(ops.proxy.url);\n if (ops.proxy.auth) {\n const parsed = parseHttpAuth(ops.proxy.auth);\n if (parsed.scheme !== \"Basic\") {\n throw new Error(`\\\nUnsupported auth scheme: ${parsed.scheme}. \\\nOnly Basic auth is supported by the backend.`);\n }\n url.username = parsed.username;\n url.password = parsed.password;\n }\n env.http_proxy = url.toString();\n env.https_proxy = url.toString();\n }\n\n const processOpts = plProcessOps(binaryPath, configPath, ops, workDir, env);\n trace(\"processOpts\", {\n cmd: processOpts.cmd,\n args: processOpts.args,\n cwd: processOpts.opts.cwd,\n });\n\n const pl = new LocalPl(\n logger,\n ops.workingDir,\n processOpts,\n t,\n ops.onClose,\n ops.onError,\n ops.onCloseAndError,\n ops.onCloseAndErrorNoStop,\n );\n await pl.start();\n\n return pl;\n });\n}\n\n/** Reads a pid of the old pl-core if it was started in the same working directory,\n * and closes it. */\nasync function localPlatformaReadPidAndStop(\n logger: MiLogger,\n workingDir: string,\n): Promise<Record<string, any>> {\n return await withTrace(logger, async (trace, t) => {\n const file = trace(\"pidFilePath\", filePid(workingDir));\n\n const oldPid = trace(\"pid\", await readPid(file));\n const alive = trace(\"wasAlive\", await isProcessAlive(oldPid));\n\n if (oldPid !== undefined && alive) {\n trace(\"stopped\", processStop(oldPid));\n try {\n trace(\"waitStopped\", await processWaitStopped(oldPid, 15_000)); // larger, that 10s we provide to backend in config.\n } catch {\n trace(\"forceStopped\", processStop(oldPid, true));\n trace(\"waitForceStopped\", await processWaitStopped(oldPid, 5_000));\n }\n }\n\n return t;\n });\n}\n\n/** Gets default options for the whole init process\n * and overrides them with the provided options. */\nexport function mergeDefaultOps(ops: LocalPlOptions, numCpu: number): LocalPlOptionsFull {\n const result: {\n plBinary: PlBinarySource;\n spawnOptions: SpawnOptions;\n closeOld: boolean;\n } = {\n plBinary: newDefaultPlBinarySource(),\n spawnOptions: {\n env: {\n GOMAXPROCS: String(numCpu),\n },\n },\n closeOld: true,\n };\n\n if (ops.spawnOptions?.env) {\n result.spawnOptions.env = { ...result.spawnOptions.env, ...ops.spawnOptions.env };\n }\n\n if (ops.spawnOptions) {\n const withoutEnv = { ...ops.spawnOptions };\n delete withoutEnv[\"env\"];\n result.spawnOptions = { ...result.spawnOptions, ...withoutEnv };\n }\n\n const withoutSpawnOps = { ...ops };\n delete withoutSpawnOps[\"spawnOptions\"];\n\n return { ...result, ...withoutSpawnOps };\n}\n\n/** Gets default options for a platforma local binary\n * and overrides them with the provided options. */\nexport function plProcessOps(\n binaryPath: any,\n configPath: string,\n ops: LocalPlOptionsFull,\n workDir: string,\n defaultEnv: Record<string, string | undefined>,\n): ProcessOptions {\n const result: ProcessOptions = {\n cmd: binaryPath,\n args: [\"--config\", configPath],\n opts: {\n env: { ...defaultEnv },\n cwd: workDir,\n stdio: [\"pipe\", \"ignore\", \"inherit\"],\n windowsHide: true, // hide a terminal on Windows\n },\n };\n\n if (ops.spawnOptions?.env) {\n result.opts.env = { ...result.opts.env, ...ops.spawnOptions.env };\n }\n\n const withoutEnv = { ...ops.spawnOptions };\n delete withoutEnv[\"env\"];\n result.opts = { ...result.opts, ...withoutEnv };\n\n return result;\n}\n"],"mappings":";;;;;;;;;;;AAkBA,MAAa,kBAAkB;;;;;;AAO/B,IAAa,UAAb,MAAqB;CACnB;CACA;CACA,QAAwB;CACxB,iBAAgC,EAAE;CAClC,aAAqB;CAErB,YACE,QACA,YACA,cACA,qBACA,SACA,SACA,iBACA,uBACA;AARiB,OAAA,SAAA;AACA,OAAA,aAAA;AACA,OAAA,eAAA;AACA,OAAA,sBAAA;AACA,OAAA,UAAA;AACA,OAAA,UAAA;AACA,OAAA,kBAAA;AACA,OAAA,wBAAA;;CAGnB,MAAM,QAAQ;AACZ,QAAM,UAAU,KAAK,QAAQ,OAAO,OAAO,MAAM;AAC/C,QAAK,aAAa;GAClB,MAAM,WAAW,WAAW,KAAK,QAAQ,KAAK,aAAa;AAC3D,YAAS,GAAG,UAAU,MAAW;AAC/B,SAAK,OAAO,MACV,UAAU,EAAE,4CAA4C,KAAK,UAAU,KAAK,WAAW,CAAC,GACzF;AAGD,QAAI,KAAK,YAAY,KAAA,EAAgB,MAAK,QAAQ,KAAK;AACvD,QAAI,KAAK,oBAAoB,KAAA,EAAgB,MAAK,gBAAgB,KAAK;AACvE,QAAI,KAAK,0BAA0B,KAAA,KAAa,CAAC,KAAK,WAC/C,MAAK,sBAAsB,KAAK;KACvC;AACF,YAAS,GAAG,eAAe;AACzB,SAAK,OAAO,KAAK,uCAAuC,KAAK,UAAU,KAAK,WAAW,CAAC,GAAG;AAG3F,QAAI,KAAK,YAAY,KAAA,EAAgB,MAAK,QAAQ,KAAK;AACvD,QAAI,KAAK,oBAAoB,KAAA,EAAgB,MAAK,gBAAgB,KAAK;AACvE,QAAI,KAAK,0BAA0B,KAAA,KAAa,CAA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AC;AAChD,UAAM,oBAAoB,MAAM,mBAAmB,QAAQ,IAAM,CAAC;;;AAItE,SAAO;GACP;;;;AAKJ,SAAgB,gBAAgB,KAAqB,QAAoC;CACvF,MAAM,SAIF;EACF,UAAU,0BAA0B;EACpC,cAAc,EACZ,KAAK,EACH,YAAY,OAAO,OAAO,EAC3B,EACF;EACD,UAAU;EACX;AAED,KAAI,IAAI,cAAc,IACpB,QAAO,aAAa,MAAM;EAAE,GAAG,OAAO,aAAa;EAAK,GAAG,IAAI,aAAa;EAAK;AAGnF,KAAI,IAAI,cAAc;EACpB,MAAM,aAAa,EAAE,GAAG,IAAI,cAAc;AAC1C,SAAO,WAAW;AAClB,SAAO,eAAe;GAAE,GAAG,OAAO;GAAc,GAAG;GAAY;;CAGjE,MAAM,kBAAkB,EAAE,GAAG,KAAK;AAClC,QAAO,gBAAgB;AAEvB,QAAO;EAAE,GAAG;EAAQ,GAAG;EAAiB;;;;AAK1C,SAAgB,aACd,YACA,YACA,KACA,SACA,YACgB;CAChB,MAAM,SAAyB;EAC7B,KAAK;EACL,MAAM,CAAC,YAAY,WAAW;EAC9B,MAAM;GACJ,KAAK,EAAE,GAAG,YAAY;GACtB,KAAK;GACL,OAAO;IAAC;IAAQ;IAAU;IAAU;GACpC,aAAa;GACd;EACF;AAED,KAAI,IAAI,cAAc,IACpB,QAAO,KAAK,MAAM;EAAE,GAAG,OAAO,KAAK;EAAK,GAAG,IAAI,aAAa;EAAK;CAGnE,MAAM,aAAa,EAAE,GAAG,IAAI,cAAc;AAC1C,QAAO,WAAW;AAClB,QAAO,OAAO;EAAE,GAAG,OAAO;EAAM,GAAG;EAAY;AAE/C,QAAO"}
|
package/dist/local/process.cjs
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
require("../_virtual/_rolldown/runtime.cjs");
|
|
2
2
|
let node_child_process = require("node:child_process");
|
|
3
3
|
let _milaboratories_ts_helpers = require("@milaboratories/ts-helpers");
|
|
4
|
-
|
|
5
4
|
//#region src/local/process.ts
|
|
6
5
|
function processRun(logger, opts) {
|
|
7
6
|
logger.info(`Running:
|
|
@@ -46,10 +45,10 @@ async function processWaitStopped(pid, maxMs) {
|
|
|
46
45
|
if (total > maxMs) throw new Error(`The process did not stopped after ${maxMs} ms.`);
|
|
47
46
|
}
|
|
48
47
|
}
|
|
49
|
-
|
|
50
48
|
//#endregion
|
|
51
49
|
exports.isProcessAlive = isProcessAlive;
|
|
52
50
|
exports.processRun = processRun;
|
|
53
51
|
exports.processStop = processStop;
|
|
54
52
|
exports.processWaitStopped = processWaitStopped;
|
|
53
|
+
|
|
55
54
|
//# sourceMappingURL=process.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"process.cjs","names":[],"sources":["../../src/local/process.ts"],"sourcesContent":["import type { SpawnOptions, ChildProcess } from \"node:child_process\";\nimport { spawn } from \"node:child_process\";\nimport { execSync } from \"node:child_process\";\nimport type { MiLogger } from \"@milaboratories/ts-helpers\";\nimport { sleep } from \"@milaboratories/ts-helpers\";\n\nexport type ProcessOptions = {\n cmd: string;\n args: string[];\n opts: SpawnOptions;\n};\n\nexport function processRun(logger: MiLogger, opts: ProcessOptions): ChildProcess {\n logger.info(`Running:\ncmd: ${JSON.stringify([opts.cmd, ...opts.args])}\nwd: ${opts.opts.cwd}`);\n\n logger.info(\" spawning child process\");\n return spawn(opts.cmd, opts.args, opts.opts);\n}\n\n// eslint-disable-next-line @typescript-eslint/require-await\nexport async function isProcessAlive(pid: number) {\n try {\n process.kill(pid, 0);\n\n // Check we look at 'platforma' to not kill wrong process.\n const processName = getProcessName(pid);\n if (process.platform === \"win32\") {\n return processName === \"platforma.exe\"; // process name does not contain path to the file.\n }\n\n // Linux and Mac OS X behave differently (so can different Linux distributions).\n // Process name can contain original path to the binary file or just its name.\n return processName.endsWith(\"/platforma\") || processName === \"platforma\";\n } catch {\n return false;\n }\n}\n\nfunction getProcessName(pid: number): string {\n try {\n if (process.platform === \"win32\") {\n // Windows: use tasklist command\n const output = execSync(`tasklist /FI \"PID eq ${pid}\" /FO CSV /NH`, { encoding: \"utf8\" });\n const lines = output.trim().split(\"\\n\");\n if (lines.length > 0 && lines[0].includes(\",\")) {\n const parts = lines[0].split(\",\");\n if (parts.length >= 1) {\n // Remove quotes and get the executable name\n const exeName = parts[0].replace(/^\"|\"$/g, \"\").trim();\n return exeName;\n }\n }\n } else {\n // Unix-like systems: use ps command\n const output = execSync(`ps -p ${pid} -o comm=`, { encoding: \"utf8\" });\n const processName = output.trim();\n return processName;\n }\n } catch {\n // If we can't get the process name, return empty string\n return \"\";\n }\n return \"\";\n}\n\nexport function processStop(pid: number, force: boolean = false) {\n return process.kill(pid, force ? \"SIGKILL\" : \"SIGINT\");\n}\n\nexport async function processWaitStopped(pid: number, maxMs: number) {\n const sleepMs = 100;\n let total = 0;\n while (await isProcessAlive(pid)) {\n await sleep(sleepMs);\n total += sleepMs;\n if (total > maxMs) {\n throw new Error(`The process did not stopped after ${maxMs} ms.`);\n }\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"process.cjs","names":[],"sources":["../../src/local/process.ts"],"sourcesContent":["import type { SpawnOptions, ChildProcess } from \"node:child_process\";\nimport { spawn } from \"node:child_process\";\nimport { execSync } from \"node:child_process\";\nimport type { MiLogger } from \"@milaboratories/ts-helpers\";\nimport { sleep } from \"@milaboratories/ts-helpers\";\n\nexport type ProcessOptions = {\n cmd: string;\n args: string[];\n opts: SpawnOptions;\n};\n\nexport function processRun(logger: MiLogger, opts: ProcessOptions): ChildProcess {\n logger.info(`Running:\ncmd: ${JSON.stringify([opts.cmd, ...opts.args])}\nwd: ${opts.opts.cwd}`);\n\n logger.info(\" spawning child process\");\n return spawn(opts.cmd, opts.args, opts.opts);\n}\n\n// eslint-disable-next-line @typescript-eslint/require-await\nexport async function isProcessAlive(pid: number) {\n try {\n process.kill(pid, 0);\n\n // Check we look at 'platforma' to not kill wrong process.\n const processName = getProcessName(pid);\n if (process.platform === \"win32\") {\n return processName === \"platforma.exe\"; // process name does not contain path to the file.\n }\n\n // Linux and Mac OS X behave differently (so can different Linux distributions).\n // Process name can contain original path to the binary file or just its name.\n return processName.endsWith(\"/platforma\") || processName === \"platforma\";\n } catch {\n return false;\n }\n}\n\nfunction getProcessName(pid: number): string {\n try {\n if (process.platform === \"win32\") {\n // Windows: use tasklist command\n const output = execSync(`tasklist /FI \"PID eq ${pid}\" /FO CSV /NH`, { encoding: \"utf8\" });\n const lines = output.trim().split(\"\\n\");\n if (lines.length > 0 && lines[0].includes(\",\")) {\n const parts = lines[0].split(\",\");\n if (parts.length >= 1) {\n // Remove quotes and get the executable name\n const exeName = parts[0].replace(/^\"|\"$/g, \"\").trim();\n return exeName;\n }\n }\n } else {\n // Unix-like systems: use ps command\n const output = execSync(`ps -p ${pid} -o comm=`, { encoding: \"utf8\" });\n const processName = output.trim();\n return processName;\n }\n } catch {\n // If we can't get the process name, return empty string\n return \"\";\n }\n return \"\";\n}\n\nexport function processStop(pid: number, force: boolean = false) {\n return process.kill(pid, force ? \"SIGKILL\" : \"SIGINT\");\n}\n\nexport async function processWaitStopped(pid: number, maxMs: number) {\n const sleepMs = 100;\n let total = 0;\n while (await isProcessAlive(pid)) {\n await sleep(sleepMs);\n total += sleepMs;\n if (total > maxMs) {\n throw new Error(`The process did not stopped after ${maxMs} ms.`);\n }\n }\n}\n"],"mappings":";;;;AAYA,SAAgB,WAAW,QAAkB,MAAoC;AAC/E,QAAO,KAAK;OACP,KAAK,UAAU,CAAC,KAAK,KAAK,GAAG,KAAK,KAAK,CAAC,CAAC;MAC1C,KAAK,KAAK,MAAM;AAEpB,QAAO,KAAK,2BAA2B;AACvC,SAAA,GAAA,mBAAA,OAAa,KAAK,KAAK,KAAK,MAAM,KAAK,KAAK;;AAI9C,eAAsB,eAAe,KAAa;AAChD,KAAI;AACF,UAAQ,KAAK,KAAK,EAAE;EAGpB,MAAM,cAAc,eAAe,IAAI;AACvC,MAAI,QAAQ,aAAa,QACvB,QAAO,gBAAgB;AAKzB,SAAO,YAAY,SAAS,aAAa,IAAI,gBAAgB;SACvD;AACN,SAAO;;;AAIX,SAAS,eAAe,KAAqB;AAC3C,KAAI;AACF,MAAI,QAAQ,aAAa,SAAS;GAGhC,MAAM,SAAA,GAAA,mBAAA,UADkB,wBAAwB,IAAI,gBAAgB,EAAE,UAAU,QAAQ,CAAC,CACpE,MAAM,CAAC,MAAM,KAAK;AACvC,OAAI,MAAM,SAAS,KAAK,MAAM,GAAG,SAAS,IAAI,EAAE;IAC9C,MAAM,QAAQ,MAAM,GAAG,MAAM,IAAI;AACjC,QAAI,MAAM,UAAU,EAGlB,QADgB,MAAM,GAAG,QAAQ,UAAU,GAAG,CAAC,MAAM;;QAQzD,SAAA,GAAA,mBAAA,UAFwB,SAAS,IAAI,YAAY,EAAE,UAAU,QAAQ,CAAC,CAC3C,MAAM;SAG7B;AAEN,SAAO;;AAET,QAAO;;AAGT,SAAgB,YAAY,KAAa,QAAiB,OAAO;AAC/D,QAAO,QAAQ,KAAK,KAAK,QAAQ,YAAY,SAAS;;AAGxD,eAAsB,mBAAmB,KAAa,OAAe;CACnE,MAAM,UAAU;CAChB,IAAI,QAAQ;AACZ,QAAO,MAAM,eAAe,IAAI,EAAE;AAChC,SAAA,GAAA,2BAAA,OAAY,QAAQ;AACpB,WAAS;AACT,MAAI,QAAQ,MACV,OAAM,IAAI,MAAM,qCAAqC,MAAM,MAAM"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"process.d.ts","names":[],"sources":["../../src/local/process.ts"],"mappings":";;;;KAMY,cAAA;EACV,GAAA;EACA,IAAA;EACA,IAAA,EAAM,YAAA;AAAA"}
|
package/dist/local/process.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { execSync, spawn } from "node:child_process";
|
|
2
2
|
import { sleep } from "@milaboratories/ts-helpers";
|
|
3
|
-
|
|
4
3
|
//#region src/local/process.ts
|
|
5
4
|
function processRun(logger, opts) {
|
|
6
5
|
logger.info(`Running:
|
|
@@ -45,7 +44,7 @@ async function processWaitStopped(pid, maxMs) {
|
|
|
45
44
|
if (total > maxMs) throw new Error(`The process did not stopped after ${maxMs} ms.`);
|
|
46
45
|
}
|
|
47
46
|
}
|
|
48
|
-
|
|
49
47
|
//#endregion
|
|
50
48
|
export { isProcessAlive, processRun, processStop, processWaitStopped };
|
|
49
|
+
|
|
51
50
|
//# sourceMappingURL=process.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"process.js","names":[],"sources":["../../src/local/process.ts"],"sourcesContent":["import type { SpawnOptions, ChildProcess } from \"node:child_process\";\nimport { spawn } from \"node:child_process\";\nimport { execSync } from \"node:child_process\";\nimport type { MiLogger } from \"@milaboratories/ts-helpers\";\nimport { sleep } from \"@milaboratories/ts-helpers\";\n\nexport type ProcessOptions = {\n cmd: string;\n args: string[];\n opts: SpawnOptions;\n};\n\nexport function processRun(logger: MiLogger, opts: ProcessOptions): ChildProcess {\n logger.info(`Running:\ncmd: ${JSON.stringify([opts.cmd, ...opts.args])}\nwd: ${opts.opts.cwd}`);\n\n logger.info(\" spawning child process\");\n return spawn(opts.cmd, opts.args, opts.opts);\n}\n\n// eslint-disable-next-line @typescript-eslint/require-await\nexport async function isProcessAlive(pid: number) {\n try {\n process.kill(pid, 0);\n\n // Check we look at 'platforma' to not kill wrong process.\n const processName = getProcessName(pid);\n if (process.platform === \"win32\") {\n return processName === \"platforma.exe\"; // process name does not contain path to the file.\n }\n\n // Linux and Mac OS X behave differently (so can different Linux distributions).\n // Process name can contain original path to the binary file or just its name.\n return processName.endsWith(\"/platforma\") || processName === \"platforma\";\n } catch {\n return false;\n }\n}\n\nfunction getProcessName(pid: number): string {\n try {\n if (process.platform === \"win32\") {\n // Windows: use tasklist command\n const output = execSync(`tasklist /FI \"PID eq ${pid}\" /FO CSV /NH`, { encoding: \"utf8\" });\n const lines = output.trim().split(\"\\n\");\n if (lines.length > 0 && lines[0].includes(\",\")) {\n const parts = lines[0].split(\",\");\n if (parts.length >= 1) {\n // Remove quotes and get the executable name\n const exeName = parts[0].replace(/^\"|\"$/g, \"\").trim();\n return exeName;\n }\n }\n } else {\n // Unix-like systems: use ps command\n const output = execSync(`ps -p ${pid} -o comm=`, { encoding: \"utf8\" });\n const processName = output.trim();\n return processName;\n }\n } catch {\n // If we can't get the process name, return empty string\n return \"\";\n }\n return \"\";\n}\n\nexport function processStop(pid: number, force: boolean = false) {\n return process.kill(pid, force ? \"SIGKILL\" : \"SIGINT\");\n}\n\nexport async function processWaitStopped(pid: number, maxMs: number) {\n const sleepMs = 100;\n let total = 0;\n while (await isProcessAlive(pid)) {\n await sleep(sleepMs);\n total += sleepMs;\n if (total > maxMs) {\n throw new Error(`The process did not stopped after ${maxMs} ms.`);\n }\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"process.js","names":[],"sources":["../../src/local/process.ts"],"sourcesContent":["import type { SpawnOptions, ChildProcess } from \"node:child_process\";\nimport { spawn } from \"node:child_process\";\nimport { execSync } from \"node:child_process\";\nimport type { MiLogger } from \"@milaboratories/ts-helpers\";\nimport { sleep } from \"@milaboratories/ts-helpers\";\n\nexport type ProcessOptions = {\n cmd: string;\n args: string[];\n opts: SpawnOptions;\n};\n\nexport function processRun(logger: MiLogger, opts: ProcessOptions): ChildProcess {\n logger.info(`Running:\ncmd: ${JSON.stringify([opts.cmd, ...opts.args])}\nwd: ${opts.opts.cwd}`);\n\n logger.info(\" spawning child process\");\n return spawn(opts.cmd, opts.args, opts.opts);\n}\n\n// eslint-disable-next-line @typescript-eslint/require-await\nexport async function isProcessAlive(pid: number) {\n try {\n process.kill(pid, 0);\n\n // Check we look at 'platforma' to not kill wrong process.\n const processName = getProcessName(pid);\n if (process.platform === \"win32\") {\n return processName === \"platforma.exe\"; // process name does not contain path to the file.\n }\n\n // Linux and Mac OS X behave differently (so can different Linux distributions).\n // Process name can contain original path to the binary file or just its name.\n return processName.endsWith(\"/platforma\") || processName === \"platforma\";\n } catch {\n return false;\n }\n}\n\nfunction getProcessName(pid: number): string {\n try {\n if (process.platform === \"win32\") {\n // Windows: use tasklist command\n const output = execSync(`tasklist /FI \"PID eq ${pid}\" /FO CSV /NH`, { encoding: \"utf8\" });\n const lines = output.trim().split(\"\\n\");\n if (lines.length > 0 && lines[0].includes(\",\")) {\n const parts = lines[0].split(\",\");\n if (parts.length >= 1) {\n // Remove quotes and get the executable name\n const exeName = parts[0].replace(/^\"|\"$/g, \"\").trim();\n return exeName;\n }\n }\n } else {\n // Unix-like systems: use ps command\n const output = execSync(`ps -p ${pid} -o comm=`, { encoding: \"utf8\" });\n const processName = output.trim();\n return processName;\n }\n } catch {\n // If we can't get the process name, return empty string\n return \"\";\n }\n return \"\";\n}\n\nexport function processStop(pid: number, force: boolean = false) {\n return process.kill(pid, force ? \"SIGKILL\" : \"SIGINT\");\n}\n\nexport async function processWaitStopped(pid: number, maxMs: number) {\n const sleepMs = 100;\n let total = 0;\n while (await isProcessAlive(pid)) {\n await sleep(sleepMs);\n total += sleepMs;\n if (total > maxMs) {\n throw new Error(`The process did not stopped after ${maxMs} ms.`);\n }\n }\n}\n"],"mappings":";;;AAYA,SAAgB,WAAW,QAAkB,MAAoC;AAC/E,QAAO,KAAK;OACP,KAAK,UAAU,CAAC,KAAK,KAAK,GAAG,KAAK,KAAK,CAAC,CAAC;MAC1C,KAAK,KAAK,MAAM;AAEpB,QAAO,KAAK,2BAA2B;AACvC,QAAO,MAAM,KAAK,KAAK,KAAK,MAAM,KAAK,KAAK;;AAI9C,eAAsB,eAAe,KAAa;AAChD,KAAI;AACF,UAAQ,KAAK,KAAK,EAAE;EAGpB,MAAM,cAAc,eAAe,IAAI;AACvC,MAAI,QAAQ,aAAa,QACvB,QAAO,gBAAgB;AAKzB,SAAO,YAAY,SAAS,aAAa,IAAI,gBAAgB;SACvD;AACN,SAAO;;;AAIX,SAAS,eAAe,KAAqB;AAC3C,KAAI;AACF,MAAI,QAAQ,aAAa,SAAS;GAGhC,MAAM,QADS,SAAS,wBAAwB,IAAI,gBAAgB,EAAE,UAAU,QAAQ,CAAC,CACpE,MAAM,CAAC,MAAM,KAAK;AACvC,OAAI,MAAM,SAAS,KAAK,MAAM,GAAG,SAAS,IAAI,EAAE;IAC9C,MAAM,QAAQ,MAAM,GAAG,MAAM,IAAI;AACjC,QAAI,MAAM,UAAU,EAGlB,QADgB,MAAM,GAAG,QAAQ,UAAU,GAAG,CAAC,MAAM;;QAQzD,QAFe,SAAS,SAAS,IAAI,YAAY,EAAE,UAAU,QAAQ,CAAC,CAC3C,MAAM;SAG7B;AAEN,SAAO;;AAET,QAAO;;AAGT,SAAgB,YAAY,KAAa,QAAiB,OAAO;AAC/D,QAAO,QAAQ,KAAK,KAAK,QAAQ,YAAY,SAAS;;AAGxD,eAAsB,mBAAmB,KAAa,OAAe;CACnE,MAAM,UAAU;CAChB,IAAI,QAAQ;AACZ,QAAO,MAAM,eAAe,IAAI,EAAE;AAChC,QAAM,MAAM,QAAQ;AACpB,WAAS;AACT,MAAI,QAAQ,MACV,OAAM,IAAI,MAAM,qCAAqC,MAAM,MAAM"}
|
package/dist/local/trace.cjs
CHANGED
package/dist/local/trace.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trace.cjs","names":[],"sources":["../../src/local/trace.ts"],"sourcesContent":["import type { MiLogger } from \"@milaboratories/ts-helpers\";\n\n/** Records all inputs and outputs of one's choice, so if the error happened\n * one can check how it was by just printing this structure. */\nexport type Trace = Record<string, any>;\n\nexport function newTrace(): Trace {\n return {};\n}\n\nexport function trace(t: Trace, k: string, v: any) {\n t[k] = v;\n return v;\n}\n\n/** Creates a trace and runs a function with it. The function can record all its\n * logs or traces using `trace` fn. */\nexport async function withTrace<T>(\n logger: MiLogger,\n fn: (trace: (k: string, v: any) => typeof v, t: Trace) => Promise<T>,\n): Promise<T> {\n const t = newTrace();\n try {\n const result = await fn((k: string, v: any) => trace(t, k, v), t);\n return result;\n } catch (e: any) {\n logger.error(`error ${e} while doing traced operation, state: ${JSON.stringify(t)}`);\n throw e;\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"trace.cjs","names":[],"sources":["../../src/local/trace.ts"],"sourcesContent":["import type { MiLogger } from \"@milaboratories/ts-helpers\";\n\n/** Records all inputs and outputs of one's choice, so if the error happened\n * one can check how it was by just printing this structure. */\nexport type Trace = Record<string, any>;\n\nexport function newTrace(): Trace {\n return {};\n}\n\nexport function trace(t: Trace, k: string, v: any) {\n t[k] = v;\n return v;\n}\n\n/** Creates a trace and runs a function with it. The function can record all its\n * logs or traces using `trace` fn. */\nexport async function withTrace<T>(\n logger: MiLogger,\n fn: (trace: (k: string, v: any) => typeof v, t: Trace) => Promise<T>,\n): Promise<T> {\n const t = newTrace();\n try {\n const result = await fn((k: string, v: any) => trace(t, k, v), t);\n return result;\n } catch (e: any) {\n logger.error(`error ${e} while doing traced operation, state: ${JSON.stringify(t)}`);\n throw e;\n }\n}\n"],"mappings":";AAMA,SAAgB,WAAkB;AAChC,QAAO,EAAE;;AAGX,SAAgB,MAAM,GAAU,GAAW,GAAQ;AACjD,GAAE,KAAK;AACP,QAAO;;;;AAKT,eAAsB,UACpB,QACA,IACY;CACZ,MAAM,IAAI,UAAU;AACpB,KAAI;AAEF,SADe,MAAM,IAAI,GAAW,MAAW,MAAM,GAAG,GAAG,EAAE,EAAE,EAAE;UAE1D,GAAQ;AACf,SAAO,MAAM,SAAS,EAAE,wCAAwC,KAAK,UAAU,EAAE,GAAG;AACpF,QAAM"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trace.d.ts","names":[],"sources":["../../src/local/trace.ts"],"mappings":";;;;;KAIY,KAAA,GAAQ,MAAA"}
|
package/dist/local/trace.js
CHANGED
package/dist/package.cjs
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
|
|
2
1
|
//#region package.json
|
|
3
2
|
var pl_version = "1.46.0";
|
|
4
|
-
|
|
5
3
|
//#endregion
|
|
6
|
-
Object.defineProperty(exports,
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
4
|
+
Object.defineProperty(exports, "pl_version", {
|
|
5
|
+
enumerable: true,
|
|
6
|
+
get: function() {
|
|
7
|
+
return pl_version;
|
|
8
|
+
}
|
|
11
9
|
});
|
|
10
|
+
|
|
12
11
|
//# sourceMappingURL=package.cjs.map
|
package/dist/package.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
require("../_virtual/_rolldown/runtime.cjs");
|
|
2
2
|
let zod = require("zod");
|
|
3
|
-
|
|
4
3
|
//#region src/ssh/connection_info.ts
|
|
5
4
|
/** We store all info about the connection on the server,
|
|
6
5
|
* so that another client could read the file and connect from another machine. */
|
|
@@ -40,7 +39,6 @@ function parseConnectionInfo(content) {
|
|
|
40
39
|
function stringifyConnectionInfo(conn) {
|
|
41
40
|
return JSON.stringify(conn, void 0, 2);
|
|
42
41
|
}
|
|
43
|
-
|
|
44
42
|
//#endregion
|
|
45
43
|
exports.ConnectionInfo = ConnectionInfo;
|
|
46
44
|
exports.PortPair = PortPair;
|
|
@@ -48,4 +46,5 @@ exports.SshPlPorts = SshPlPorts;
|
|
|
48
46
|
exports.newConnectionInfo = newConnectionInfo;
|
|
49
47
|
exports.parseConnectionInfo = parseConnectionInfo;
|
|
50
48
|
exports.stringifyConnectionInfo = stringifyConnectionInfo;
|
|
49
|
+
|
|
51
50
|
//# sourceMappingURL=connection_info.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connection_info.cjs","names":["z"],"sources":["../../src/ssh/connection_info.ts"],"sourcesContent":["/** We store all info about the connection on the server,\n * so that another client could read the file and connect from another machine. */\nimport { z } from \"zod\";\n\n//\n// Types\n//\n\nexport const PortPair = z\n .object({\n local: z.number(),\n remote: z.number(),\n })\n .passthrough();\n/** The pair of ports for forwarding. */\nexport type PortPair = z.infer<typeof PortPair>;\n\nexport const SshPlPorts = z\n .object({\n grpc: PortPair,\n http: PortPair.optional(),\n monitoring: PortPair,\n debug: PortPair,\n /** @deprecated */\n minioPort: PortPair,\n /** @deprecated */\n minioConsolePort: PortPair,\n })\n .passthrough();\n/** All info about ports that are forwarded. */\nexport type SshPlPorts = z.infer<typeof SshPlPorts>;\n\nexport const ConnectionInfo = z\n .object({\n plUser: z.string(),\n plPassword: z.string(),\n ports: SshPlPorts,\n\n // It's false by default because it was added later,\n // and in some deployments there won't be useGlobalAccess flag in the file.\n useGlobalAccess: z.boolean().default(false),\n\n // We added the field afterwards, the pl backend was this version.\n plVersion: z.string().default(\"1.18.3\"),\n\n // It's true by default because it was added later and previous installation use minio.\n minioIsUsed: z.boolean().default(true),\n })\n .passthrough();\n/** The content of the file that holds all the info about the connection on the remote server. */\nexport type ConnectionInfo = z.infer<typeof ConnectionInfo>;\n\n//\n// Funcs\n//\n\nexport function newConnectionInfo(\n plUser: string,\n plPassword: string,\n ports: SshPlPorts,\n useGlobalAccess: boolean,\n plVersion: string,\n minioIsUsed: boolean,\n): ConnectionInfo {\n return {\n plUser,\n plPassword,\n ports,\n useGlobalAccess,\n plVersion,\n minioIsUsed: minioIsUsed,\n };\n}\n\nexport function parseConnectionInfo(content: string): ConnectionInfo {\n return ConnectionInfo.parse(JSON.parse(content));\n}\n\nexport function stringifyConnectionInfo(conn: ConnectionInfo): string {\n return JSON.stringify(conn, undefined, 2);\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"connection_info.cjs","names":["z"],"sources":["../../src/ssh/connection_info.ts"],"sourcesContent":["/** We store all info about the connection on the server,\n * so that another client could read the file and connect from another machine. */\nimport { z } from \"zod\";\n\n//\n// Types\n//\n\nexport const PortPair = z\n .object({\n local: z.number(),\n remote: z.number(),\n })\n .passthrough();\n/** The pair of ports for forwarding. */\nexport type PortPair = z.infer<typeof PortPair>;\n\nexport const SshPlPorts = z\n .object({\n grpc: PortPair,\n http: PortPair.optional(),\n monitoring: PortPair,\n debug: PortPair,\n /** @deprecated */\n minioPort: PortPair,\n /** @deprecated */\n minioConsolePort: PortPair,\n })\n .passthrough();\n/** All info about ports that are forwarded. */\nexport type SshPlPorts = z.infer<typeof SshPlPorts>;\n\nexport const ConnectionInfo = z\n .object({\n plUser: z.string(),\n plPassword: z.string(),\n ports: SshPlPorts,\n\n // It's false by default because it was added later,\n // and in some deployments there won't be useGlobalAccess flag in the file.\n useGlobalAccess: z.boolean().default(false),\n\n // We added the field afterwards, the pl backend was this version.\n plVersion: z.string().default(\"1.18.3\"),\n\n // It's true by default because it was added later and previous installation use minio.\n minioIsUsed: z.boolean().default(true),\n })\n .passthrough();\n/** The content of the file that holds all the info about the connection on the remote server. */\nexport type ConnectionInfo = z.infer<typeof ConnectionInfo>;\n\n//\n// Funcs\n//\n\nexport function newConnectionInfo(\n plUser: string,\n plPassword: string,\n ports: SshPlPorts,\n useGlobalAccess: boolean,\n plVersion: string,\n minioIsUsed: boolean,\n): ConnectionInfo {\n return {\n plUser,\n plPassword,\n ports,\n useGlobalAccess,\n plVersion,\n minioIsUsed: minioIsUsed,\n };\n}\n\nexport function parseConnectionInfo(content: string): ConnectionInfo {\n return ConnectionInfo.parse(JSON.parse(content));\n}\n\nexport function stringifyConnectionInfo(conn: ConnectionInfo): string {\n return JSON.stringify(conn, undefined, 2);\n}\n"],"mappings":";;;;;AAQA,MAAa,WAAWA,IAAAA,EACrB,OAAO;CACN,OAAOA,IAAAA,EAAE,QAAQ;CACjB,QAAQA,IAAAA,EAAE,QAAQ;CACnB,CAAC,CACD,aAAa;AAIhB,MAAa,aAAaA,IAAAA,EACvB,OAAO;CACN,MAAM;CACN,MAAM,SAAS,UAAU;CACzB,YAAY;CACZ,OAAO;CAEP,WAAW;CAEX,kBAAkB;CACnB,CAAC,CACD,aAAa;AAIhB,MAAa,iBAAiBA,IAAAA,EAC3B,OAAO;CACN,QAAQA,IAAAA,EAAE,QAAQ;CAClB,YAAYA,IAAAA,EAAE,QAAQ;CACtB,OA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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAkBf,cAAA,GAAiB,CAAA,CAAE,KAAA,QAAa,cAAA;AAAA,iBAM5B,iBAAA,CACd,MAAA,UACA,UAAA,UACA,KAAA,EAAO,UAAA,EACP,eAAA,WACA,SAAA,UACA,WAAA,YACC,cAAA;AAAA,iBAWa,mBAAA,CAAoB,OAAA,WAAkB,cAAA;AAAA,iBAItC,uBAAA,CAAwB,IAAA,EAAM,cAAA"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
|
|
3
2
|
//#region src/ssh/connection_info.ts
|
|
4
3
|
/** We store all info about the connection on the server,
|
|
5
4
|
* so that another client could read the file and connect from another machine. */
|
|
@@ -39,7 +38,7 @@ function parseConnectionInfo(content) {
|
|
|
39
38
|
function stringifyConnectionInfo(conn) {
|
|
40
39
|
return JSON.stringify(conn, void 0, 2);
|
|
41
40
|
}
|
|
42
|
-
|
|
43
41
|
//#endregion
|
|
44
42
|
export { ConnectionInfo, PortPair, SshPlPorts, newConnectionInfo, parseConnectionInfo, stringifyConnectionInfo };
|
|
43
|
+
|
|
45
44
|
//# sourceMappingURL=connection_info.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connection_info.js","names":[],"sources":["../../src/ssh/connection_info.ts"],"sourcesContent":["/** We store all info about the connection on the server,\n * so that another client could read the file and connect from another machine. */\nimport { z } from \"zod\";\n\n//\n// Types\n//\n\nexport const PortPair = z\n .object({\n local: z.number(),\n remote: z.number(),\n })\n .passthrough();\n/** The pair of ports for forwarding. */\nexport type PortPair = z.infer<typeof PortPair>;\n\nexport const SshPlPorts = z\n .object({\n grpc: PortPair,\n http: PortPair.optional(),\n monitoring: PortPair,\n debug: PortPair,\n /** @deprecated */\n minioPort: PortPair,\n /** @deprecated */\n minioConsolePort: PortPair,\n })\n .passthrough();\n/** All info about ports that are forwarded. */\nexport type SshPlPorts = z.infer<typeof SshPlPorts>;\n\nexport const ConnectionInfo = z\n .object({\n plUser: z.string(),\n plPassword: z.string(),\n ports: SshPlPorts,\n\n // It's false by default because it was added later,\n // and in some deployments there won't be useGlobalAccess flag in the file.\n useGlobalAccess: z.boolean().default(false),\n\n // We added the field afterwards, the pl backend was this version.\n plVersion: z.string().default(\"1.18.3\"),\n\n // It's true by default because it was added later and previous installation use minio.\n minioIsUsed: z.boolean().default(true),\n })\n .passthrough();\n/** The content of the file that holds all the info about the connection on the remote server. */\nexport type ConnectionInfo = z.infer<typeof ConnectionInfo>;\n\n//\n// Funcs\n//\n\nexport function newConnectionInfo(\n plUser: string,\n plPassword: string,\n ports: SshPlPorts,\n useGlobalAccess: boolean,\n plVersion: string,\n minioIsUsed: boolean,\n): ConnectionInfo {\n return {\n plUser,\n plPassword,\n ports,\n useGlobalAccess,\n plVersion,\n minioIsUsed: minioIsUsed,\n };\n}\n\nexport function parseConnectionInfo(content: string): ConnectionInfo {\n return ConnectionInfo.parse(JSON.parse(content));\n}\n\nexport function stringifyConnectionInfo(conn: ConnectionInfo): string {\n return JSON.stringify(conn, undefined, 2);\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"connection_info.js","names":[],"sources":["../../src/ssh/connection_info.ts"],"sourcesContent":["/** We store all info about the connection on the server,\n * so that another client could read the file and connect from another machine. */\nimport { z } from \"zod\";\n\n//\n// Types\n//\n\nexport const PortPair = z\n .object({\n local: z.number(),\n remote: z.number(),\n })\n .passthrough();\n/** The pair of ports for forwarding. */\nexport type PortPair = z.infer<typeof PortPair>;\n\nexport const SshPlPorts = z\n .object({\n grpc: PortPair,\n http: PortPair.optional(),\n monitoring: PortPair,\n debug: PortPair,\n /** @deprecated */\n minioPort: PortPair,\n /** @deprecated */\n minioConsolePort: PortPair,\n })\n .passthrough();\n/** All info about ports that are forwarded. */\nexport type SshPlPorts = z.infer<typeof SshPlPorts>;\n\nexport const ConnectionInfo = z\n .object({\n plUser: z.string(),\n plPassword: z.string(),\n ports: SshPlPorts,\n\n // It's false by default because it was added later,\n // and in some deployments there won't be useGlobalAccess flag in the file.\n useGlobalAccess: z.boolean().default(false),\n\n // We added the field afterwards, the pl backend was this version.\n plVersion: z.string().default(\"1.18.3\"),\n\n // It's true by default because it was added later and previous installation use minio.\n minioIsUsed: z.boolean().default(true),\n })\n .passthrough();\n/** The content of the file that holds all the info about the connection on the remote server. */\nexport type ConnectionInfo = z.infer<typeof ConnectionInfo>;\n\n//\n// Funcs\n//\n\nexport function newConnectionInfo(\n plUser: string,\n plPassword: string,\n ports: SshPlPorts,\n useGlobalAccess: boolean,\n plVersion: string,\n minioIsUsed: boolean,\n): ConnectionInfo {\n return {\n plUser,\n plPassword,\n ports,\n useGlobalAccess,\n plVersion,\n minioIsUsed: minioIsUsed,\n };\n}\n\nexport function parseConnectionInfo(content: string): ConnectionInfo {\n return ConnectionInfo.parse(JSON.parse(content));\n}\n\nexport function stringifyConnectionInfo(conn: ConnectionInfo): string {\n return JSON.stringify(conn, undefined, 2);\n}\n"],"mappings":";;;;AAQA,MAAa,WAAW,EACrB,OAAO;CACN,OAAO,EAAE,QAAQ;CACjB,QAAQ,EAAE,QAAQ;CACnB,CAAC,CACD,aAAa;AAIhB,MAAa,aAAa,EACvB,OAAO;CACN,MAAM;CACN,MAAM,SAAS,UAAU;CACzB,YAAY;CACZ,OAAO;CAEP,WAAW;CAEX,kBAAkB;CACnB,CAAC,CACD,aAAa;AAIhB,MAAa,iBAAiB,EAC3B,OAAO;CACN,QAAQ,EAAE,QAAQ;CAClB,YAAY,EAAE,QAAQ;CACtB,OAAO;CAIP,iBAAiB,EAAE,SAAS,CAAC,QAAQ,MAAM;CAG3C,WAAW,EAAE,QAAQ,CAAC,QAAQ,SAAS;CAGvC,aAAa,EAAE,SAAS,CAAC,QAAQ,KAAK;CACvC,CAAC,CACD,aAAa;AAQhB,SAAgB,kBACd,QACA,YACA,OACA,iBACA,WACA,aACgB;AAChB,QAAO;EACL;EACA;EACA;EACA;EACA;EACa;EACd;;AAGH,SAAgB,oBAAoB,SAAiC;AACnE,QAAO,eAAe,MAAM,KAAK,MAAM,QAAQ,CAAC;;AAGlD,SAAgB,wBAAwB,MAA8B;AACpE,QAAO,KAAK,UAAU,MAAM,KAAA,GAAW,EAAE"}
|
package/dist/ssh/pl.cjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
const require_runtime = require(
|
|
2
|
-
const require_pl_binary_download = require(
|
|
3
|
-
const require_pl_version = require(
|
|
4
|
-
const require_ssh = require(
|
|
5
|
-
const require_pl_paths = require(
|
|
6
|
-
const require_supervisord = require(
|
|
7
|
-
const require_connection_info = require(
|
|
1
|
+
const require_runtime = require("../_virtual/_rolldown/runtime.cjs");
|
|
2
|
+
const require_pl_binary_download = require("../common/pl_binary_download.cjs");
|
|
3
|
+
const require_pl_version = require("../common/pl_version.cjs");
|
|
4
|
+
const require_ssh = require("./ssh.cjs");
|
|
5
|
+
const require_pl_paths = require("./pl_paths.cjs");
|
|
6
|
+
const require_supervisord = require("./supervisord.cjs");
|
|
7
|
+
const require_connection_info = require("./connection_info.cjs");
|
|
8
8
|
let _milaboratories_ts_helpers = require("@milaboratories/ts-helpers");
|
|
9
9
|
let upath = require("upath");
|
|
10
10
|
upath = require_runtime.__toESM(upath);
|
|
@@ -12,7 +12,6 @@ let _milaboratories_pl_http = require("@milaboratories/pl-http");
|
|
|
12
12
|
let node_net = require("node:net");
|
|
13
13
|
node_net = require_runtime.__toESM(node_net);
|
|
14
14
|
let _milaboratories_pl_config = require("@milaboratories/pl-config");
|
|
15
|
-
|
|
16
15
|
//#region src/ssh/pl.ts
|
|
17
16
|
const minRequiredGlibcVersion = 2.28;
|
|
18
17
|
var SshPl = class SshPl {
|
|
@@ -556,8 +555,8 @@ function parseGlibcVersion(output) {
|
|
|
556
555
|
if (!versionMatch) throw new Error(`Could not parse glibc version from: ${output}`);
|
|
557
556
|
return parseFloat(versionMatch[0]);
|
|
558
557
|
}
|
|
559
|
-
|
|
560
558
|
//#endregion
|
|
561
559
|
exports.SshPl = SshPl;
|
|
562
560
|
exports.parseGlibcVersion = parseGlibcVersion;
|
|
561
|
+
|
|
563
562
|
//# sourceMappingURL=pl.cjs.map
|
package/dist/ssh/pl.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pl.cjs","names":["SshClient","supervisorStatus","isAllAlive","supervisorCtlStart","isSupervisordRunning","supervisorCtlShutdown","newConnectionInfo","stringifyConnectionInfo","generateSupervisordConfigWithMinio","generateSupervisordConfig","downloadBinaryNoExtract","parseConnectionInfo","net","getDefaultPlVersion"],"sources":["../../src/ssh/pl.ts"],"sourcesContent":["import type * as ssh from \"ssh2\";\nimport { SshClient } from \"./ssh\";\nimport type { MiLogger } from \"@milaboratories/ts-helpers\";\nimport { sleep, notEmpty } from \"@milaboratories/ts-helpers\";\nimport type { DownloadBinaryResult } from \"../common/pl_binary_download\";\nimport { downloadBinaryNoExtract } from \"../common/pl_binary_download\";\nimport upath from \"upath\";\nimport * as plpath from \"./pl_paths\";\nimport { getDefaultPlVersion } from \"../common/pl_version\";\nimport type { ProxySettings } from \"@milaboratories/pl-http\";\nimport { defaultHttpDispatcher } from \"@milaboratories/pl-http\";\nimport type { Dispatcher } from \"undici\";\n\nimport net from \"node:net\";\nimport type {\n PlConfig,\n PlLicenseMode,\n SshPlConfigGenerationResult,\n} from \"@milaboratories/pl-config\";\nimport { getFreePort, generateSshPlConfigs } from \"@milaboratories/pl-config\";\nimport type { SupervisorStatus } from \"./supervisord\";\nimport {\n supervisorStatus,\n supervisorStop as supervisorCtlShutdown,\n generateSupervisordConfigWithMinio,\n supervisorCtlStart,\n isSupervisordRunning,\n generateSupervisordConfig,\n isAllAlive,\n} from \"./supervisord\";\nimport type { ConnectionInfo, SshPlPorts } from \"./connection_info\";\nimport { newConnectionInfo, parseConnectionInfo, stringifyConnectionInfo } from \"./connection_info\";\nimport type { PlBinarySourceDownload } from \"../common/pl_binary\";\n\nconst minRequiredGlibcVersion = 2.28;\n\nexport class SshPl {\n private initState: PlatformaInitState = { step: \"init\" };\n constructor(\n public readonly logger: MiLogger,\n public readonly sshClient: SshClient,\n private readonly username: string,\n ) {}\n\n public info() {\n return {\n username: this.username,\n initState: this.initState,\n };\n }\n\n public static async init(logger: MiLogger, config: ssh.ConnectConfig): Promise<SshPl> {\n try {\n const sshClient = await SshClient.init(logger, config);\n return new SshPl(logger, sshClient, notEmpty(config.username));\n } catch (e: unknown) {\n logger.error(`Connection error in SshClient.init: ${e}`);\n throw e;\n }\n }\n\n public cleanUp() {\n this.sshClient.close();\n }\n\n /** Provides an info if the platforma and minio are running along with the debug info. */\n public async isAlive(): Promise<SupervisorStatus> {\n const arch = await this.getArch();\n const remoteHome = await this.getUserHomeDirectory();\n return await supervisorStatus(this.logger, this.sshClient, remoteHome, arch.arch);\n }\n\n /** Starts all the services on the server.\n * Idempotent semantic: we could call it several times. */\n public async start(shouldUseMinio: boolean) {\n const arch = await this.getArch();\n const remoteHome = await this.getUserHomeDirectory();\n\n try {\n if (!isAllAlive(await this.isAlive(), shouldUseMinio)) {\n await supervisorCtlStart(this.sshClient, remoteHome, arch.arch);\n\n // We are waiting for Platforma to run to ensure that it has started.\n return await this.checkIsAliveWithInterval(shouldUseMinio);\n }\n } catch (e: unknown) {\n let msg = `SshPl.start: ${e}`;\n\n let logs = \"\";\n try {\n logs = await this.sshClient.readFile(plpath.platformaCliLogs(remoteHome));\n msg += `, platforma cli logs: ${logs}`;\n } catch (e: unknown) {\n msg += `, Can not read platforma cli logs: ${e}`;\n }\n\n this.logger.error(msg);\n throw new Error(msg);\n }\n }\n\n /** Stops all the services on the server.\n * Idempotent semantic: we could call it several times. */\n public async stop() {\n const arch = await this.getArch();\n const remoteHome = await this.getUserHomeDirectory();\n\n try {\n const alive = await this.isAlive();\n if (isSupervisordRunning(alive)) {\n await supervisorCtlShutdown(this.sshClient, remoteHome, arch.arch);\n // Check if Minio is running by looking at the alive status\n const shouldUseMinio = alive.minio === true;\n return await this.checkIsAliveWithInterval(shouldUseMinio, 1000, 15, false);\n }\n } catch (e: unknown) {\n const msg = `PlSsh.stop: ${e}`;\n this.logger.error(msg);\n throw new Error(msg);\n }\n }\n\n /** Stops the services, deletes a directory with the state and closes SSH connection. */\n public async reset(): Promise<boolean> {\n await this.stopAndClean();\n this.cleanUp();\n return true;\n }\n\n /** Stops platforma and deletes its state. */\n public async stopAndClean(): Promise<void> {\n const remoteHome = await this.getUserHomeDirectory();\n\n this.logger.info(`pl.reset: Stop Platforma on the server`);\n await this.stop();\n\n this.logger.info(\n `pl.reset: Deleting Platforma workDir ${plpath.workDir(remoteHome)} on the server`,\n );\n await this.sshClient.deleteFolder(plpath.workDir(remoteHome));\n }\n\n /** Downloads binaries and untar them on the server,\n * generates all the configs, creates necessary dirs,\n * and finally starts all the services. */\n public async platformaInit(options: SshPlConfig): Promise<ConnectionInfo> {\n const state: PlatformaInitState = { localWorkdir: options.localWorkdir, step: \"init\" };\n\n const { onProgress } = options;\n\n // merge options with default ops.\n const ops: SshPlConfig = {\n ...defaultSshPlConfig,\n ...options,\n };\n state.plBinaryOps = ops.plBinary;\n\n try {\n await this.doStepDetectArch(state, onProgress);\n await this.doStepDetectHome(state, onProgress);\n\n const needRestartPlatforma = await this.doStepReadExistedConfig(state, ops, onProgress);\n if (!needRestartPlatforma) {\n await onProgress?.(\"Platforma is already running. Skipping initialization.\");\n return state.existedSettings!;\n }\n await this.doStepStopExistedPlatforma(state, onProgress);\n await this.doStepCheckDbLock(state, onProgress);\n\n await onProgress?.(\"Installation platforma...\");\n\n await this.doStepDownloadBinaries(state, onProgress, ops);\n await this.doStepFetchPorts(state);\n await this.doStepGenerateNewConfig(state, onProgress, ops);\n await this.doStepCreateFoldersAndSaveFiles(state, onProgress);\n await this.doStepConfigureSupervisord(state, onProgress);\n await this.doStepSaveNewConnectionInfo(state, onProgress, ops);\n await this.doStepStartPlatforma(state, onProgress);\n\n return state.connectionInfo!;\n } catch (e: unknown) {\n const msg = `SshPl.platformaInit: ${e}, state: ${JSON.stringify(this.removeSensitiveData(state))}`;\n this.logger.error(msg);\n\n throw new Error(msg);\n }\n }\n\n private async doStepStopExistedPlatforma(\n state: PlatformaInitState,\n onProgress: ((...args: any) => Promise<any>) | undefined,\n ) {\n state.step = \"stopExistedPlatforma\";\n if (!isAllAlive(state.alive!, state.shouldUseMinio ?? false)) {\n return;\n }\n\n await onProgress?.(\"Stopping services...\");\n await this.stop();\n }\n\n private removeSensitiveData(state: PlatformaInitState): PlatformaInitState {\n const stateCopy = { ...state };\n stateCopy.generatedConfig = {\n ...stateCopy.generatedConfig,\n filesToCreate: { skipped: \"sanitized\" },\n } as SshPlConfigGenerationResult;\n return stateCopy;\n }\n\n private async doStepStartPlatforma(\n state: PlatformaInitState,\n onProgress: ((...args: any) => Promise<any>) | undefined,\n ) {\n state.step = \"startPlatforma\";\n await onProgress?.(\"Starting Platforma on the server...\");\n await this.start(state.shouldUseMinio ?? false);\n state.started = true;\n this.initState = state;\n\n await onProgress?.(\"Platforma has been started successfully.\");\n }\n\n private async doStepSaveNewConnectionInfo(\n state: PlatformaInitState,\n onProgress: ((...args: any) => Promise<any>) | undefined,\n ops: SshPlConfig,\n ) {\n state.step = \"saveNewConnectionInfo\";\n const config = state.generatedConfig!;\n await onProgress?.(\"Saving connection information...\");\n state.connectionInfo = newConnectionInfo(\n config.plUser,\n config.plPassword,\n state.ports!,\n notEmpty(ops.useGlobalAccess),\n ops.plBinary!.version,\n state.shouldUseMinio ?? false,\n );\n await this.sshClient.writeFileOnTheServer(\n plpath.connectionInfo(state.remoteHome!),\n stringifyConnectionInfo(state.connectionInfo),\n );\n await onProgress?.(\"Connection information saved.\");\n }\n\n private async doStepCheckDbLock(\n state: PlatformaInitState,\n onProgress?: (...args: any[]) => Promise<any>,\n ) {\n const removeLockFile = async (lockFilePath: string) => {\n try {\n await this.sshClient.exec(`rm -f ${lockFilePath}`);\n this.logger.info(`Removed stale lock file ${lockFilePath}`);\n } catch (e: unknown) {\n const msg = `Failed to remove stale lock file ${lockFilePath}: ${e}`;\n this.logger.error(msg);\n throw new Error(msg);\n }\n };\n\n state.step = \"checkDbLock\";\n await onProgress?.(\"Checking for DB lock...\");\n\n const lockFilePath = plpath.platformaDbLock(state.remoteHome!);\n const lockFileExists = await this.sshClient.checkFileExists(lockFilePath);\n\n if (!lockFileExists) {\n await onProgress?.(\"No DB lock found. Proceeding...\");\n return;\n }\n\n this.logger.info(`DB lock file found at ${lockFilePath}. Checking which process holds it...`);\n const lockProcessInfo = await this.findLockHolder(lockFilePath);\n\n if (!lockProcessInfo) {\n this.logger.warn(\n \"Lock file exists but no process is holding it. Removing stale lock file...\",\n );\n await removeLockFile(lockFilePath);\n return;\n }\n\n this.logger.info(\n `Found process ${lockProcessInfo.pid} (user: ${lockProcessInfo.user}) holding DB lock`,\n );\n\n if (lockProcessInfo.user !== this.username) {\n const msg =\n `DB lock is held by process ${lockProcessInfo.pid} ` +\n `owned by user '${lockProcessInfo.user}', but current user is '${this.username}'. ` +\n \"Cannot kill process owned by different user.\";\n this.logger.error(msg);\n throw new Error(msg);\n }\n\n this.logger.info(\n `Process ${lockProcessInfo.pid} belongs to current user ${this.username}. Killing it...`,\n );\n await this.killRemoteProcess(lockProcessInfo.pid);\n this.logger.info(\"Process holding DB lock has been terminated.\");\n\n // Verify lock file is gone or can be removed\n const lockStillExists = await this.sshClient.checkFileExists(lockFilePath);\n if (lockStillExists) {\n await removeLockFile(lockFilePath);\n }\n }\n\n private async doStepConfigureSupervisord(\n state: PlatformaInitState,\n onProgress: ((...args: any) => Promise<any>) | undefined,\n ) {\n await onProgress?.(\"Writing supervisord configuration...\");\n state.step = \"configureSupervisord\";\n\n const config = state.generatedConfig!;\n\n let supervisorConfig: string;\n if (state.shouldUseMinio) {\n supervisorConfig = generateSupervisordConfigWithMinio(\n config.minioConfig.storageDir,\n config.minioConfig.envs,\n await this.getFreePortForPlatformaOnServer(state.remoteHome!, state.arch!),\n config.workingDir,\n config.plConfig.configPath,\n state.binPaths!.minioRelPath!,\n state.binPaths!.downloadedPl,\n );\n } else {\n supervisorConfig = generateSupervisordConfig(\n await this.getFreePortForPlatformaOnServer(state.remoteHome!, state.arch!),\n config.workingDir,\n config.plConfig.configPath,\n state.binPaths!.downloadedPl,\n );\n }\n\n const writeResult = await this.sshClient.writeFileOnTheServer(\n plpath.supervisorConf(state.remoteHome!),\n supervisorConfig,\n );\n if (!writeResult) {\n throw new Error(\n `Can not write supervisord config on the server ${plpath.workDir(state.remoteHome!)}`,\n );\n }\n await onProgress?.(\"Supervisord configuration written.\");\n }\n\n private async doStepCreateFoldersAndSaveFiles(\n state: PlatformaInitState,\n onProgress: ((...args: any) => Promise<any>) | undefined,\n ) {\n state.step = \"createFoldersAndSaveFiles\";\n const config = state.generatedConfig!;\n await onProgress?.(\"Generating folder structure...\");\n for (const [filePath, content] of Object.entries(config.filesToCreate)) {\n await this.sshClient.writeFileOnTheServer(filePath, content);\n this.logger.info(`Created file ${filePath}`);\n }\n\n for (const dir of config.dirsToCreate) {\n await this.sshClient.ensureRemoteDirCreated(dir);\n this.logger.info(`Created directory ${dir}`);\n }\n await onProgress?.(\"Folder structure created.\");\n }\n\n private async doStepGenerateNewConfig(\n state: PlatformaInitState,\n onProgress: ((...args: any) => Promise<any>) | undefined,\n ops: SshPlConfig,\n ) {\n state.step = \"generateNewConfig\";\n\n await onProgress?.(\"Generating new config...\");\n const config = await generateSshPlConfigs({\n logger: this.logger,\n workingDir: plpath.workDir(state.remoteHome!),\n portsMode: {\n type: \"customWithMinio\",\n ports: {\n debug: state.ports!.debug.remote,\n grpc: state.ports!.grpc.remote,\n http: state.ports!.http!.remote,\n minio: state.ports!.minioPort.remote,\n minioConsole: state.ports!.minioConsolePort.remote,\n monitoring: state.ports!.monitoring.remote,\n\n httpLocal: state.ports!.http!.local,\n grpcLocal: state.ports!.grpc.local,\n minioLocal: state.ports!.minioPort.local,\n },\n },\n licenseMode: ops.license,\n useGlobalAccess: notEmpty(ops.useGlobalAccess),\n plConfigPostprocessing: ops.plConfigPostprocessing,\n useMinio: state.shouldUseMinio ?? false,\n });\n state.generatedConfig = { ...config };\n await onProgress?.(\"New config generated\");\n }\n\n private async doStepFetchPorts(state: PlatformaInitState) {\n state.step = \"fetchPorts\";\n state.ports = await this.fetchPorts(state.remoteHome!, state.arch!);\n\n if (\n !state.ports.debug.remote ||\n !state.ports.grpc.remote ||\n !state.ports.minioPort.remote ||\n !state.ports.minioConsolePort.remote ||\n !state.ports.monitoring.remote ||\n !state.ports.http?.remote\n ) {\n throw new Error(`SshPl.platformaInit: remote ports are not defined`);\n }\n }\n\n private async doStepDownloadBinaries(\n state: PlatformaInitState,\n onProgress: ((...args: any) => Promise<any>) | undefined,\n ops: SshPlConfig,\n ) {\n state.step = \"downloadBinaries\";\n await onProgress?.(\"Downloading and uploading required binaries...\");\n\n const glibcVersion = await getGlibcVersion(this.logger, this.sshClient);\n if (glibcVersion < minRequiredGlibcVersion)\n throw new Error(\n `glibc version ${glibcVersion} is too old. Version ${minRequiredGlibcVersion} or higher is required for Platforma.`,\n );\n\n const downloadRes = await this.downloadBinariesAndUploadToTheServer(\n ops.localWorkdir,\n ops.plBinary!,\n state.remoteHome!,\n state.arch!,\n state.shouldUseMinio ?? false,\n ops.proxy,\n );\n await onProgress?.(\"All required binaries have been downloaded and uploaded.\");\n\n state.binPaths = { ...downloadRes, history: undefined };\n state.downloadedBinaries = downloadRes.history;\n }\n\n private async doStepDetectArch(\n state: PlatformaInitState,\n onProgress: ((...args: any) => Promise<any>) | undefined,\n ) {\n state.step = \"detectArch\";\n await onProgress?.(\"Detecting server architecture...\");\n state.arch = await this.getArch();\n await onProgress?.(\"Server architecture detected.\");\n }\n\n private async doStepDetectHome(\n state: PlatformaInitState,\n onProgress: ((...args: any) => Promise<any>) | undefined,\n ) {\n state.step = \"detectHome\";\n await onProgress?.(\"Fetching user home directory...\");\n state.remoteHome = await this.getUserHomeDirectory();\n await onProgress?.(\"User home directory retrieved.\");\n }\n\n private async doStepReadExistedConfig(\n state: PlatformaInitState,\n ops: SshPlConfig,\n onProgress: ((...args: any) => Promise<any>) | undefined,\n ): Promise<boolean> {\n state.step = \"checkAlive\";\n await onProgress?.(\"Checking platform status...\");\n state.alive = await this.isAlive();\n\n if (!state.alive?.platforma) {\n return true;\n }\n\n await onProgress?.(\"All required services are running.\");\n\n state.existedSettings = await this.readExistedConfig(state.remoteHome!);\n if (!state.existedSettings) {\n throw new Error(`SshPl.platformaInit: platforma is alive but existed settings are not found`);\n }\n\n const sameGA = state.existedSettings.useGlobalAccess == ops.useGlobalAccess;\n const samePlVersion = state.existedSettings.plVersion == ops.plBinary!.version;\n state.needRestart = !(sameGA && samePlVersion);\n this.logger.info(`SshPl.platformaInit: need restart? ${state.needRestart}`);\n\n state.shouldUseMinio = state.existedSettings.minioIsUsed;\n if (state.shouldUseMinio) {\n this.logger.info(`SshPl.platformaInit: minio is used`);\n } else {\n this.logger.info(`SshPl.platformaInit: minio is not used`);\n }\n\n if (!state.needRestart) {\n await onProgress?.(\"Server setup completed.\");\n return false;\n }\n\n await onProgress?.(\"Stopping services...\");\n await this.stop();\n\n return true;\n }\n\n public async downloadBinariesAndUploadToTheServer(\n localWorkdir: string,\n plBinary: PlBinarySourceDownload,\n remoteHome: string,\n arch: Arch,\n shouldUseMinio: boolean,\n proxy?: ProxySettings,\n ) {\n const state: DownloadAndUntarState[] = [];\n const dispatcher = defaultHttpDispatcher(proxy);\n try {\n const pl = await this.downloadAndUntar(\n localWorkdir,\n remoteHome,\n arch,\n \"pl\",\n `pl-${plBinary.version}`,\n dispatcher,\n );\n state.push(pl);\n\n const supervisor = await this.downloadAndUntar(\n localWorkdir,\n remoteHome,\n arch,\n \"supervisord\",\n plpath.supervisordDirName,\n dispatcher,\n );\n state.push(supervisor);\n\n const minioPath = plpath.minioBin(remoteHome, arch.arch);\n if (shouldUseMinio) {\n const minio = await this.downloadAndUntar(\n localWorkdir,\n remoteHome,\n arch,\n \"minio\",\n plpath.minioDirName,\n dispatcher,\n );\n state.push(minio);\n await this.sshClient.chmod(minioPath, 0o750);\n }\n\n return {\n history: state,\n minioRelPath: shouldUseMinio ? minioPath : undefined,\n downloadedPl: plpath.platformaBin(remoteHome, arch.arch),\n };\n } catch (e: unknown) {\n const msg = `SshPl.downloadBinariesAndUploadToServer: ${e}, state: ${JSON.stringify(state)}`;\n this.logger.error(msg);\n throw e;\n } finally {\n await dispatcher.close();\n }\n }\n\n private async findLockHolderWithLsof(lockFilePath: string): Promise<LockProcessInfo | null> {\n try {\n const { stdout } = await this.sshClient.exec(`lsof ${lockFilePath} 2>/dev/null || true`);\n const output = stdout.trim();\n if (!output) {\n return null;\n }\n\n // Example:\n // COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME\n // platforma 11628 rfiskov 10u REG 1,16 0 66670038 ./LOCK\n const lines = output.split(\"\\n\");\n if (lines.length <= 1) {\n return null;\n }\n\n const parts = lines[1].trim().split(/\\s+/);\n if (parts.length < 3) {\n return null;\n }\n\n const pid = Number.parseInt(parts[1], 10);\n const user = parts[2];\n\n return Number.isNaN(pid) || !user ? null : { pid, user };\n } catch (e: unknown) {\n this.logger.warn(`Failed to use lsof to check lock: ${e}`);\n return null;\n }\n }\n\n private async findLockHolderWithFuser(lockFilePath: string): Promise<LockProcessInfo | null> {\n try {\n const { stdout } = await this.sshClient.exec(`fuser ${lockFilePath} 2>/dev/null || true`);\n const output = stdout.trim();\n if (!output) {\n return null;\n }\n\n // Example: ./LOCK: 11628\n const match = output.match(/: (\\d+)/);\n if (!match) {\n return null;\n }\n\n const pid = Number.parseInt(match[1], 10);\n if (Number.isNaN(pid)) {\n return null;\n }\n\n try {\n const psResult = await this.sshClient.exec(`ps -o user= -p ${pid} 2>/dev/null || true`);\n const user = psResult.stdout.trim();\n return user ? { pid, user } : null;\n } catch (e: unknown) {\n this.logger.warn(`Failed to get user for PID ${pid}: ${e}`);\n return null;\n }\n } catch (e: unknown) {\n this.logger.warn(`Failed to use fuser to check lock: ${e}`);\n return null;\n }\n }\n\n private async findLockHolder(lockFilePath: string): Promise<LockProcessInfo | null> {\n const viaLsof = await this.findLockHolderWithLsof(lockFilePath);\n if (viaLsof) {\n return viaLsof;\n }\n return this.findLockHolderWithFuser(lockFilePath);\n }\n\n private async killRemoteProcess(pid: number): Promise<void> {\n this.logger.info(`Killing process ${pid}...`);\n\n try {\n // Try graceful termination first\n await this.sshClient.exec(`kill ${pid} 2>/dev/null || true`);\n await sleep(1000);\n\n // Check if process still exists\n try {\n await this.sshClient.exec(`kill -0 ${pid} 2>/dev/null`);\n // Process still exists, force kill\n this.logger.warn(`Process ${pid} still alive after SIGTERM, forcing kill...`);\n await this.sshClient.exec(`kill -9 ${pid} 2>/dev/null || true`);\n await sleep(500);\n } catch {\n // Process is dead, nothing to do\n }\n } catch (e: unknown) {\n const msg = `Failed to kill process ${pid}: ${e}`;\n this.logger.error(msg);\n throw new Error(msg);\n }\n }\n\n /** We have to extract pl in the remote server,\n * because Windows doesn't support symlinks\n * that are found in Linux pl binaries tgz archive.\n * For this reason, we extract all to the remote server.\n * It requires `tar` to be installed on the server\n * (it's not installed for Rocky Linux for example). */\n public async downloadAndUntar(\n localWorkdir: string,\n remoteHome: string,\n arch: Arch,\n softwareName: string,\n tgzName: string,\n dispatcher?: Dispatcher,\n ): Promise<DownloadAndUntarState> {\n const state: DownloadAndUntarState = {};\n state.binBasePath = plpath.binariesDir(remoteHome);\n await this.sshClient.ensureRemoteDirCreated(state.binBasePath);\n state.binBasePathCreated = true;\n\n let downloadBinaryResult: DownloadBinaryResult | null = null;\n const attempts = 5;\n for (let i = 1; i <= attempts; i++) {\n try {\n downloadBinaryResult = await downloadBinaryNoExtract({\n logger: this.logger,\n baseDir: localWorkdir,\n softwareName,\n tgzName,\n arch: arch.arch,\n platform: arch.platform,\n dispatcher,\n });\n break;\n } catch (e: unknown) {\n await sleep(300);\n if (i == attempts) {\n throw new Error(`downloadAndUntar: ${attempts} attempts, last error: ${e}`);\n }\n }\n }\n state.downloadResult = notEmpty(downloadBinaryResult);\n\n state.localArchivePath = upath.resolve(state.downloadResult.archivePath);\n state.remoteDir = upath.join(state.binBasePath, state.downloadResult.baseName);\n state.remoteArchivePath = state.remoteDir + \".tgz\";\n\n await this.sshClient.ensureRemoteDirCreated(state.remoteDir);\n await this.sshClient.uploadFile(state.localArchivePath, state.remoteArchivePath);\n state.uploadDone = true;\n\n try {\n await this.sshClient.exec(\"hash tar\");\n } catch {\n throw new Error(\n `tar is not installed on the server. Please install it before running Platforma.`,\n );\n }\n\n // TODO: Create a proper archive to avoid xattr warnings\n const untarResult = await this.sshClient.exec(\n `tar --warning=no-all -xvf ${state.remoteArchivePath} --directory=${state.remoteDir}`,\n );\n\n if (untarResult.stderr)\n throw new Error(\n `downloadAndUntar: untar: stderr occurred: ${untarResult.stderr}, stdout: ${untarResult.stdout}`,\n );\n\n state.untarDone = true;\n\n return state;\n }\n\n public async needDownload(remoteHome: string, arch: Arch) {\n const checkPathSupervisor = plpath.supervisorBin(remoteHome, arch.arch);\n const checkPathMinio = plpath.minioDir(remoteHome, arch.arch);\n const checkPathPlatforma = plpath.platformaBin(remoteHome, arch.arch);\n\n if (\n !(await this.sshClient.checkFileExists(checkPathPlatforma)) ||\n !(await this.sshClient.checkFileExists(checkPathMinio)) ||\n !(await this.sshClient.checkFileExists(checkPathSupervisor))\n ) {\n return true;\n }\n\n return false;\n }\n\n public async checkIsAliveWithInterval(\n shouldUseMinio: boolean,\n interval: number = 1000,\n count = 15,\n shouldStart = true,\n ): Promise<void> {\n const maxMs = count * interval;\n\n let total = 0;\n let alive = await this.isAlive();\n while (shouldStart ? !isAllAlive(alive, shouldUseMinio) : isAllAlive(alive, shouldUseMinio)) {\n await sleep(interval);\n total += interval;\n if (total > maxMs) {\n throw new Error(\n `isAliveWithInterval: The process did not ${shouldStart ? \"started\" : \"stopped\"} after ${maxMs} ms. Live status: ${JSON.stringify(alive)}`,\n );\n }\n alive = await this.isAlive();\n }\n }\n\n public async readExistedConfig(remoteHome: string): Promise<ConnectionInfo> {\n const connectionInfo = await this.sshClient.readFile(plpath.connectionInfo(remoteHome));\n return parseConnectionInfo(connectionInfo);\n }\n\n public async fetchPorts(remoteHome: string, arch: Arch): Promise<SshPlPorts> {\n const ports: SshPlPorts = {\n grpc: {\n local: await getFreePort(),\n remote: await this.getFreePortForPlatformaOnServer(remoteHome, arch),\n },\n monitoring: {\n local: await getFreePort(),\n remote: await this.getFreePortForPlatformaOnServer(remoteHome, arch),\n },\n debug: {\n local: await getFreePort(),\n remote: await this.getFreePortForPlatformaOnServer(remoteHome, arch),\n },\n http: {\n local: await getFreePort(),\n remote: await this.getFreePortForPlatformaOnServer(remoteHome, arch),\n },\n minioPort: {\n local: await getFreePort(),\n remote: await this.getFreePortForPlatformaOnServer(remoteHome, arch),\n },\n minioConsolePort: {\n local: await getFreePort(),\n remote: await this.getFreePortForPlatformaOnServer(remoteHome, arch),\n },\n };\n\n return ports;\n }\n\n public async getLocalFreePort(): Promise<number> {\n return new Promise((res) => {\n const srv = net.createServer();\n srv.listen(0, () => {\n const port = (srv.address() as net.AddressInfo).port;\n srv.close((_) => res(port));\n });\n });\n }\n\n public async getFreePortForPlatformaOnServer(remoteHome: string, arch: Arch): Promise<number> {\n const freePortBin = plpath.platformaFreePortBin(remoteHome, arch.arch);\n\n const { stdout, stderr } = await this.sshClient.exec(`${freePortBin}`);\n if (stderr) {\n throw new Error(\n `getFreePortForPlatformaOnServer: stderr is not empty: ${stderr}, stdout: ${stdout}`,\n );\n }\n\n return +stdout;\n }\n\n public async getArch(): Promise<Arch> {\n const { stdout, stderr } = await this.sshClient.exec(\"uname -s && uname -m\");\n if (stderr) throw new Error(`getArch: stderr is not empty: ${stderr}, stdout: ${stdout}`);\n\n const arr = stdout.split(\"\\n\");\n\n return {\n platform: arr[0],\n arch: arr[1],\n };\n }\n\n public async getUserHomeDirectory() {\n const { stdout, stderr } = await this.sshClient.exec(\"echo $HOME\");\n\n if (stderr) {\n const home = `/home/${this.username}`;\n console.warn(\n `getUserHomeDirectory: stderr is not empty: ${stderr}, stdout: ${stdout}, will get a default home: ${home}`,\n );\n\n return home;\n }\n\n return stdout.trim();\n }\n}\n\ntype Arch = { platform: string; arch: string };\n\nexport type SshPlConfig = {\n localWorkdir: string;\n license: PlLicenseMode;\n useGlobalAccess?: boolean;\n plBinary?: PlBinarySourceDownload;\n proxy?: ProxySettings;\n\n onProgress?: (...args: any) => Promise<any>;\n plConfigPostprocessing?: (config: PlConfig) => PlConfig;\n};\n\nexport type LockProcessInfo = { pid: number; user: string };\n\nconst defaultSshPlConfig: Pick<SshPlConfig, \"useGlobalAccess\" | \"plBinary\"> = {\n useGlobalAccess: false,\n plBinary: {\n type: \"Download\",\n version: getDefaultPlVersion(),\n },\n};\n\ntype BinPaths = {\n history?: DownloadAndUntarState[];\n minioRelPath?: string;\n downloadedPl: string;\n};\n\ntype DownloadAndUntarState = {\n binBasePath?: string;\n binBasePathCreated?: boolean;\n downloadResult?: DownloadBinaryResult;\n attempts?: number;\n\n localArchivePath?: string;\n remoteDir?: string;\n remoteArchivePath?: string;\n uploadDone?: boolean;\n untarDone?: boolean;\n};\n\ntype PlatformaInitStep =\n | \"init\"\n | \"detectArch\"\n | \"detectHome\"\n | \"checkAlive\"\n | \"stopExistedPlatforma\"\n | \"checkDbLock\"\n | \"downloadBinaries\"\n | \"fetchPorts\"\n | \"generateNewConfig\"\n | \"createFoldersAndSaveFiles\"\n | \"configureSupervisord\"\n | \"saveNewConnectionInfo\"\n | \"startPlatforma\";\n\ntype PlatformaInitState = {\n step: PlatformaInitStep;\n localWorkdir?: string;\n plBinaryOps?: PlBinarySourceDownload;\n arch?: Arch;\n remoteHome?: string;\n alive?: SupervisorStatus;\n existedSettings?: ConnectionInfo;\n needRestart?: boolean;\n shouldUseMinio?: boolean;\n downloadedBinaries?: DownloadAndUntarState[];\n binPaths?: BinPaths;\n ports?: SshPlPorts;\n generatedConfig?: SshPlConfigGenerationResult;\n connectionInfo?: ConnectionInfo;\n started?: boolean;\n};\n\n/**\n * Gets the glibc version on the remote system\n * @returns The glibc version as a number\n * @throws Error if version cannot be determined\n */\nasync function getGlibcVersion(logger: MiLogger, sshClient: SshClient): Promise<number> {\n try {\n const { stdout, stderr } = await sshClient.exec(\"ldd --version | head -n 1\");\n if (stderr) {\n throw new Error(`Failed to check glibc version: ${stderr}`);\n }\n return parseGlibcVersion(stdout);\n } catch (e: unknown) {\n logger.error(`glibc version check failed: ${e}`);\n throw e;\n }\n}\n\nexport function parseGlibcVersion(output: string): number {\n const versionMatch = output.match(/\\d+\\.\\d+/);\n if (!versionMatch) {\n throw new Error(`Could not parse glibc version from: ${output}`);\n }\n\n return parseFloat(versionMatch[0]);\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAkCA,MAAM,0BAA0B;AAEhC,IAAa,QAAb,MAAa,MAAM;CACjB,AAAQ,YAAgC,EAAE,MAAM,QAAQ;CACxD,YACE,AAAgB,QAChB,AAAgB,WAChB,AAAiB,UACjB;EAHgB;EACA;EACC;;CAGnB,AAAO,OAAO;AACZ,SAAO;GACL,UAAU,KAAK;GACf,WAAW,KAAK;GACjB;;CAGH,aAAoB,KAAK,QAAkB,QAA2C;AACpF,MAAI;AAEF,UAAO,IAAI,MAAM,QADC,MAAMA,sBAAU,KAAK,QAAQ,OAAO,2CACT,OAAO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BAAwE;CAC5E,iBAAiB;CACjB,UAAU;EACR,MAAM;EACN,SAASC,wCAAqB;EAC/B;CACF;;;;;;AA2DD,eAAe,gBAAgB,QAAkB,WAAuC;AACtF,KAAI;EACF,MAAM,EAAE,QAAQ,WAAW,MAAM,UAAU,KAAK,4BAA4B;AAC5E,MAAI,OACF,OAAM,IAAI,MAAM,kCAAkC,SAAS;AAE7D,SAAO,kBAAkB,OAAO;UACzB,GAAY;AACnB,SAAO,MAAM,+BAA+B,IAAI;AAChD,QAAM;;;AAIV,SAAgB,kBAAkB,QAAwB;CACxD,MAAM,eAAe,OAAO,MAAM,WAAW;AAC7C,KAAI,CAAC,aACH,OAAM,IAAI,MAAM,uCAAuC,SAAS;AAGlE,QAAO,WAAW,aAAa,GAAG"}
|
|
1
|
+
{"version":3,"file":"pl.cjs","names":["SshClient","supervisorStatus","isAllAlive","supervisorCtlStart","isSupervisordRunning","supervisorCtlShutdown","newConnectionInfo","stringifyConnectionInfo","generateSupervisordConfigWithMinio","generateSupervisordConfig","downloadBinaryNoExtract","parseConnectionInfo","net","getDefaultPlVersion"],"sources":["../../src/ssh/pl.ts"],"sourcesContent":["import type * as ssh from \"ssh2\";\nimport { SshClient } from \"./ssh\";\nimport type { MiLogger } from \"@milaboratories/ts-helpers\";\nimport { sleep, notEmpty } from \"@milaboratories/ts-helpers\";\nimport type { DownloadBinaryResult } from \"../common/pl_binary_download\";\nimport { downloadBinaryNoExtract } from \"../common/pl_binary_download\";\nimport upath from \"upath\";\nimport * as plpath from \"./pl_paths\";\nimport { getDefaultPlVersion } from \"../common/pl_version\";\nimport type { ProxySettings } from \"@milaboratories/pl-http\";\nimport { defaultHttpDispatcher } from \"@milaboratories/pl-http\";\nimport type { Dispatcher } from \"undici\";\n\nimport net from \"node:net\";\nimport type {\n PlConfig,\n PlLicenseMode,\n SshPlConfigGenerationResult,\n} from \"@milaboratories/pl-config\";\nimport { getFreePort, generateSshPlConfigs } from \"@milaboratories/pl-config\";\nimport type { SupervisorStatus } from \"./supervisord\";\nimport {\n supervisorStatus,\n supervisorStop as supervisorCtlShutdown,\n generateSupervisordConfigWithMinio,\n supervisorCtlStart,\n isSupervisordRunning,\n generateSupervisordConfig,\n isAllAlive,\n} from \"./supervisord\";\nimport type { ConnectionInfo, SshPlPorts } from \"./connection_info\";\nimport { newConnectionInfo, parseConnectionInfo, stringifyConnectionInfo } from \"./connection_info\";\nimport type { PlBinarySourceDownload } from \"../common/pl_binary\";\n\nconst minRequiredGlibcVersion = 2.28;\n\nexport class SshPl {\n private initState: PlatformaInitState = { step: \"init\" };\n constructor(\n public readonly logger: MiLogger,\n public readonly sshClient: SshClient,\n private readonly username: string,\n ) {}\n\n public info() {\n return {\n username: this.username,\n initState: this.initState,\n };\n }\n\n public static async init(logger: MiLogger, config: ssh.ConnectConfig): Promise<SshPl> {\n try {\n const sshClient = await SshClient.init(logger, config);\n return new SshPl(logger, sshClient, notEmpty(config.username));\n } catch (e: unknown) {\n logger.error(`Connection error in SshClient.init: ${e}`);\n throw e;\n }\n }\n\n public cleanUp() {\n this.sshClient.close();\n }\n\n /** Provides an info if the platforma and minio are running along with the debug info. */\n public async isAlive(): Promise<SupervisorStatus> {\n const arch = await this.getArch();\n const remoteHome = await this.getUserHomeDirectory();\n return await supervisorStatus(this.logger, this.sshClient, remoteHome, arch.arch);\n }\n\n /** Starts all the services on the server.\n * Idempotent semantic: we could call it several times. */\n public async start(shouldUseMinio: boolean) {\n const arch = await this.getArch();\n const remoteHome = await this.getUserHomeDirectory();\n\n try {\n if (!isAllAlive(await this.isAlive(), shouldUseMinio)) {\n await supervisorCtlStart(this.sshClient, remoteHome, arch.arch);\n\n // We are waiting for Platforma to run to ensure that it has started.\n return await this.checkIsAliveWithInterval(shouldUseMinio);\n }\n } catch (e: unknown) {\n let msg = `SshPl.start: ${e}`;\n\n let logs = \"\";\n try {\n logs = await this.sshClient.readFile(plpath.platformaCliLogs(remoteHome));\n msg += `, platforma cli logs: ${logs}`;\n } catch (e: unknown) {\n msg += `, Can not read platforma cli logs: ${e}`;\n }\n\n this.logger.error(msg);\n throw new Error(msg);\n }\n }\n\n /** Stops all the services on the server.\n * Idempotent semantic: we could call it several times. */\n public async stop() {\n const arch = await this.getArch();\n const remoteHome = await this.getUserHomeDirectory();\n\n try {\n const alive = await this.isAlive();\n if (isSupervisordRunning(alive)) {\n await supervisorCtlShutdown(this.sshClient, remoteHome, arch.arch);\n // Check if Minio is running by looking at the alive status\n const shouldUseMinio = alive.minio === true;\n return await this.checkIsAliveWithInterval(shouldUseMinio, 1000, 15, false);\n }\n } catch (e: unknown) {\n const msg = `PlSsh.stop: ${e}`;\n this.logger.error(msg);\n throw new Error(msg);\n }\n }\n\n /** Stops the services, deletes a directory with the state and closes SSH connection. */\n public async reset(): Promise<boolean> {\n await this.stopAndClean();\n this.cleanUp();\n return true;\n }\n\n /** Stops platforma and deletes its state. */\n public async stopAndClean(): Promise<void> {\n const remoteHome = await this.getUserHomeDirectory();\n\n this.logger.info(`pl.reset: Stop Platforma on the server`);\n await this.stop();\n\n this.logger.info(\n `pl.reset: Deleting Platforma workDir ${plpath.workDir(remoteHome)} on the server`,\n );\n await this.sshClient.deleteFolder(plpath.workDir(remoteHome));\n }\n\n /** Downloads binaries and untar them on the server,\n * generates all the configs, creates necessary dirs,\n * and finally starts all the services. */\n public async platformaInit(options: SshPlConfig): Promise<ConnectionInfo> {\n const state: PlatformaInitState = { localWorkdir: options.localWorkdir, step: \"init\" };\n\n const { onProgress } = options;\n\n // merge options with default ops.\n const ops: SshPlConfig = {\n ...defaultSshPlConfig,\n ...options,\n };\n state.plBinaryOps = ops.plBinary;\n\n try {\n await this.doStepDetectArch(state, onProgress);\n await this.doStepDetectHome(state, onProgress);\n\n const needRestartPlatforma = await this.doStepReadExistedConfig(state, ops, onProgress);\n if (!needRestartPlatforma) {\n await onProgress?.(\"Platforma is already running. Skipping initialization.\");\n return state.existedSettings!;\n }\n await this.doStepStopExistedPlatforma(state, onProgress);\n await this.doStepCheckDbLock(state, onProgress);\n\n await onProgress?.(\"Installation platforma...\");\n\n await this.doStepDownloadBinaries(state, onProgress, ops);\n await this.doStepFetchPorts(state);\n await this.doStepGenerateNewConfig(state, onProgress, ops);\n await this.doStepCreateFoldersAndSaveFiles(state, onProgress);\n await this.doStepConfigureSupervisord(state, onProgress);\n await this.doStepSaveNewConnectionInfo(state, onProgress, ops);\n await this.doStepStartPlatforma(state, onProgress);\n\n return state.connectionInfo!;\n } catch (e: unknown) {\n const msg = `SshPl.platformaInit: ${e}, state: ${JSON.stringify(this.removeSensitiveData(state))}`;\n this.logger.error(msg);\n\n throw new Error(msg);\n }\n }\n\n private async doStepStopExistedPlatforma(\n state: PlatformaInitState,\n onProgress: ((...args: any) => Promise<any>) | undefined,\n ) {\n state.step = \"stopExistedPlatforma\";\n if (!isAllAlive(state.alive!, state.shouldUseMinio ?? false)) {\n return;\n }\n\n await onProgress?.(\"Stopping services...\");\n await this.stop();\n }\n\n private removeSensitiveData(state: PlatformaInitState): PlatformaInitState {\n const stateCopy = { ...state };\n stateCopy.generatedConfig = {\n ...stateCopy.generatedConfig,\n filesToCreate: { skipped: \"sanitized\" },\n } as SshPlConfigGenerationResult;\n return stateCopy;\n }\n\n private async doStepStartPlatforma(\n state: PlatformaInitState,\n onProgress: ((...args: any) => Promise<any>) | undefined,\n ) {\n state.step = \"startPlatforma\";\n await onProgress?.(\"Starting Platforma on the server...\");\n await this.start(state.shouldUseMinio ?? false);\n state.started = true;\n this.initState = state;\n\n await onProgress?.(\"Platforma has been started successfully.\");\n }\n\n private async doStepSaveNewConnectionInfo(\n state: PlatformaInitState,\n onProgress: ((...args: any) => Promise<any>) | undefined,\n ops: SshPlConfig,\n ) {\n state.step = \"saveNewConnectionInfo\";\n const config = state.generatedConfig!;\n await onProgress?.(\"Saving connection information...\");\n state.connectionInfo = newConnectionInfo(\n config.plUser,\n config.plPassword,\n state.ports!,\n notEmpty(ops.useGlobalAccess),\n ops.plBinary!.version,\n state.shouldUseMinio ?? false,\n );\n await this.sshClient.writeFileOnTheServer(\n plpath.connectionInfo(state.remoteHome!),\n stringifyConnectionInfo(state.connectionInfo),\n );\n await onProgress?.(\"Connection information saved.\");\n }\n\n private async doStepCheckDbLock(\n state: PlatformaInitState,\n onProgress?: (...args: any[]) => Promise<any>,\n ) {\n const removeLockFile = async (lockFilePath: string) => {\n try {\n await this.sshClient.exec(`rm -f ${lockFilePath}`);\n this.logger.info(`Removed stale lock file ${lockFilePath}`);\n } catch (e: unknown) {\n const msg = `Failed to remove stale lock file ${lockFilePath}: ${e}`;\n this.logger.error(msg);\n throw new Error(msg);\n }\n };\n\n state.step = \"checkDbLock\";\n await onProgress?.(\"Checking for DB lock...\");\n\n const lockFilePath = plpath.platformaDbLock(state.remoteHome!);\n const lockFileExists = await this.sshClient.checkFileExists(lockFilePath);\n\n if (!lockFileExists) {\n await onProgress?.(\"No DB lock found. Proceeding...\");\n return;\n }\n\n this.logger.info(`DB lock file found at ${lockFilePath}. Checking which process holds it...`);\n const lockProcessInfo = await this.findLockHolder(lockFilePath);\n\n if (!lockProcessInfo) {\n this.logger.warn(\n \"Lock file exists but no process is holding it. Removing stale lock file...\",\n );\n await removeLockFile(lockFilePath);\n return;\n }\n\n this.logger.info(\n `Found process ${lockProcessInfo.pid} (user: ${lockProcessInfo.user}) holding DB lock`,\n );\n\n if (lockProcessInfo.user !== this.username) {\n const msg =\n `DB lock is held by process ${lockProcessInfo.pid} ` +\n `owned by user '${lockProcessInfo.user}', but current user is '${this.username}'. ` +\n \"Cannot kill process owned by different user.\";\n this.logger.error(msg);\n throw new Error(msg);\n }\n\n this.logger.info(\n `Process ${lockProcessInfo.pid} belongs to current user ${this.username}. Killing it...`,\n );\n await this.killRemoteProcess(lockProcessInfo.pid);\n this.logger.info(\"Process holding DB lock has been terminated.\");\n\n // Verify lock file is gone or can be removed\n const lockStillExists = await this.sshClient.checkFileExists(lockFilePath);\n if (lockStillExists) {\n await removeLockFile(lockFilePath);\n }\n }\n\n private async doStepConfigureSupervisord(\n state: PlatformaInitState,\n onProgress: ((...args: any) => Promise<any>) | undefined,\n ) {\n await onProgress?.(\"Writing supervisord configuration...\");\n state.step = \"configureSupervisord\";\n\n const config = state.generatedConfig!;\n\n let supervisorConfig: string;\n if (state.shouldUseMinio) {\n supervisorConfig = generateSupervisordConfigWithMinio(\n config.minioConfig.storageDir,\n config.minioConfig.envs,\n await this.getFreePortForPlatformaOnServer(state.remoteHome!, state.arch!),\n config.workingDir,\n config.plConfig.configPath,\n state.binPaths!.minioRelPath!,\n state.binPaths!.downloadedPl,\n );\n } else {\n supervisorConfig = generateSupervisordConfig(\n await this.getFreePortForPlatformaOnServer(state.remoteHome!, state.arch!),\n config.workingDir,\n config.plConfig.configPath,\n state.binPaths!.downloadedPl,\n );\n }\n\n const writeResult = await this.sshClient.writeFileOnTheServer(\n plpath.supervisorConf(state.remoteHome!),\n supervisorConfig,\n );\n if (!writeResult) {\n throw new Error(\n `Can not write supervisord config on the server ${plpath.workDir(state.remoteHome!)}`,\n );\n }\n await onProgress?.(\"Supervisord configuration written.\");\n }\n\n private async doStepCreateFoldersAndSaveFiles(\n state: PlatformaInitState,\n onProgress: ((...args: any) => Promise<any>) | undefined,\n ) {\n state.step = \"createFoldersAndSaveFiles\";\n const config = state.generatedConfig!;\n await onProgress?.(\"Generating folder structure...\");\n for (const [filePath, content] of Object.entries(config.filesToCreate)) {\n await this.sshClient.writeFileOnTheServer(filePath, content);\n this.logger.info(`Created file ${filePath}`);\n }\n\n for (const dir of config.dirsToCreate) {\n await this.sshClient.ensureRemoteDirCreated(dir);\n this.logger.info(`Created directory ${dir}`);\n }\n await onProgress?.(\"Folder structure created.\");\n }\n\n private async doStepGenerateNewConfig(\n state: PlatformaInitState,\n onProgress: ((...args: any) => Promise<any>) | undefined,\n ops: SshPlConfig,\n ) {\n state.step = \"generateNewConfig\";\n\n await onProgress?.(\"Generating new config...\");\n const config = await generateSshPlConfigs({\n logger: this.logger,\n workingDir: plpath.workDir(state.remoteHome!),\n portsMode: {\n type: \"customWithMinio\",\n ports: {\n debug: state.ports!.debug.remote,\n grpc: state.ports!.grpc.remote,\n http: state.ports!.http!.remote,\n minio: state.ports!.minioPort.remote,\n minioConsole: state.ports!.minioConsolePort.remote,\n monitoring: state.ports!.monitoring.remote,\n\n httpLocal: state.ports!.http!.local,\n grpcLocal: state.ports!.grpc.local,\n minioLocal: state.ports!.minioPort.local,\n },\n },\n licenseMode: ops.license,\n useGlobalAccess: notEmpty(ops.useGlobalAccess),\n plConfigPostprocessing: ops.plConfigPostprocessing,\n useMinio: state.shouldUseMinio ?? false,\n });\n state.generatedConfig = { ...config };\n await onProgress?.(\"New config generated\");\n }\n\n private async doStepFetchPorts(state: PlatformaInitState) {\n state.step = \"fetchPorts\";\n state.ports = await this.fetchPorts(state.remoteHome!, state.arch!);\n\n if (\n !state.ports.debug.remote ||\n !state.ports.grpc.remote ||\n !state.ports.minioPort.remote ||\n !state.ports.minioConsolePort.remote ||\n !state.ports.monitoring.remote ||\n !state.ports.http?.remote\n ) {\n throw new Error(`SshPl.platformaInit: remote ports are not defined`);\n }\n }\n\n private async doStepDownloadBinaries(\n state: PlatformaInitState,\n onProgress: ((...args: any) => Promise<any>) | undefined,\n ops: SshPlConfig,\n ) {\n state.step = \"downloadBinaries\";\n await onProgress?.(\"Downloading and uploading required binaries...\");\n\n const glibcVersion = await getGlibcVersion(this.logger, this.sshClient);\n if (glibcVersion < minRequiredGlibcVersion)\n throw new Error(\n `glibc version ${glibcVersion} is too old. Version ${minRequiredGlibcVersion} or higher is required for Platforma.`,\n );\n\n const downloadRes = await this.downloadBinariesAndUploadToTheServer(\n ops.localWorkdir,\n ops.plBinary!,\n state.remoteHome!,\n state.arch!,\n state.shouldUseMinio ?? false,\n ops.proxy,\n );\n await onProgress?.(\"All required binaries have been downloaded and uploaded.\");\n\n state.binPaths = { ...downloadRes, history: undefined };\n state.downloadedBinaries = downloadRes.history;\n }\n\n private async doStepDetectArch(\n state: PlatformaInitState,\n onProgress: ((...args: any) => Promise<any>) | undefined,\n ) {\n state.step = \"detectArch\";\n await onProgress?.(\"Detecting server architecture...\");\n state.arch = await this.getArch();\n await onProgress?.(\"Server architecture detected.\");\n }\n\n private async doStepDetectHome(\n state: PlatformaInitState,\n onProgress: ((...args: any) => Promise<any>) | undefined,\n ) {\n state.step = \"detectHome\";\n await onProgress?.(\"Fetching user home directory...\");\n state.remoteHome = await this.getUserHomeDirectory();\n await onProgress?.(\"User home directory retrieved.\");\n }\n\n private async doStepReadExistedConfig(\n state: PlatformaInitState,\n ops: SshPlConfig,\n onProgress: ((...args: any) => Promise<any>) | undefined,\n ): Promise<boolean> {\n state.step = \"checkAlive\";\n await onProgress?.(\"Checking platform status...\");\n state.alive = await this.isAlive();\n\n if (!state.alive?.platforma) {\n return true;\n }\n\n await onProgress?.(\"All required services are running.\");\n\n state.existedSettings = await this.readExistedConfig(state.remoteHome!);\n if (!state.existedSettings) {\n throw new Error(`SshPl.platformaInit: platforma is alive but existed settings are not found`);\n }\n\n const sameGA = state.existedSettings.useGlobalAccess == ops.useGlobalAccess;\n const samePlVersion = state.existedSettings.plVersion == ops.plBinary!.version;\n state.needRestart = !(sameGA && samePlVersion);\n this.logger.info(`SshPl.platformaInit: need restart? ${state.needRestart}`);\n\n state.shouldUseMinio = state.existedSettings.minioIsUsed;\n if (state.shouldUseMinio) {\n this.logger.info(`SshPl.platformaInit: minio is used`);\n } else {\n this.logger.info(`SshPl.platformaInit: minio is not used`);\n }\n\n if (!state.needRestart) {\n await onProgress?.(\"Server setup completed.\");\n return false;\n }\n\n await onProgress?.(\"Stopping services...\");\n await this.stop();\n\n return true;\n }\n\n public async downloadBinariesAndUploadToTheServer(\n localWorkdir: string,\n plBinary: PlBinarySourceDownload,\n remoteHome: string,\n arch: Arch,\n shouldUseMinio: boolean,\n proxy?: ProxySettings,\n ) {\n const state: DownloadAndUntarState[] = [];\n const dispatcher = defaultHttpDispatcher(proxy);\n try {\n const pl = await this.downloadAndUntar(\n localWorkdir,\n remoteHome,\n arch,\n \"pl\",\n `pl-${plBinary.version}`,\n dispatcher,\n );\n state.push(pl);\n\n const supervisor = await this.downloadAndUntar(\n localWorkdir,\n remoteHome,\n arch,\n \"supervisord\",\n plpath.supervisordDirName,\n dispatcher,\n );\n state.push(supervisor);\n\n const minioPath = plpath.minioBin(remoteHome, arch.arch);\n if (shouldUseMinio) {\n const minio = await this.downloadAndUntar(\n localWorkdir,\n remoteHome,\n arch,\n \"minio\",\n plpath.minioDirName,\n dispatcher,\n );\n state.push(minio);\n await this.sshClient.chmod(minioPath, 0o750);\n }\n\n return {\n history: state,\n minioRelPath: shouldUseMinio ? minioPath : undefined,\n downloadedPl: plpath.platformaBin(remoteHome, arch.arch),\n };\n } catch (e: unknown) {\n const msg = `SshPl.downloadBinariesAndUploadToServer: ${e}, state: ${JSON.stringify(state)}`;\n this.logger.error(msg);\n throw e;\n } finally {\n await dispatcher.close();\n }\n }\n\n private async findLockHolderWithLsof(lockFilePath: string): Promise<LockProcessInfo | null> {\n try {\n const { stdout } = await this.sshClient.exec(`lsof ${lockFilePath} 2>/dev/null || true`);\n const output = stdout.trim();\n if (!output) {\n return null;\n }\n\n // Example:\n // COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME\n // platforma 11628 rfiskov 10u REG 1,16 0 66670038 ./LOCK\n const lines = output.split(\"\\n\");\n if (lines.length <= 1) {\n return null;\n }\n\n const parts = lines[1].trim().split(/\\s+/);\n if (parts.length < 3) {\n return null;\n }\n\n const pid = Number.parseInt(parts[1], 10);\n const user = parts[2];\n\n return Number.isNaN(pid) || !user ? null : { pid, user };\n } catch (e: unknown) {\n this.logger.warn(`Failed to use lsof to check lock: ${e}`);\n return null;\n }\n }\n\n private async findLockHolderWithFuser(lockFilePath: string): Promise<LockProcessInfo | null> {\n try {\n const { stdout } = await this.sshClient.exec(`fuser ${lockFilePath} 2>/dev/null || true`);\n const output = stdout.trim();\n if (!output) {\n return null;\n }\n\n // Example: ./LOCK: 11628\n const match = output.match(/: (\\d+)/);\n if (!match) {\n return null;\n }\n\n const pid = Number.parseInt(match[1], 10);\n if (Number.isNaN(pid)) {\n return null;\n }\n\n try {\n const psResult = await this.sshClient.exec(`ps -o user= -p ${pid} 2>/dev/null || true`);\n const user = psResult.stdout.trim();\n return user ? { pid, user } : null;\n } catch (e: unknown) {\n this.logger.warn(`Failed to get user for PID ${pid}: ${e}`);\n return null;\n }\n } catch (e: unknown) {\n this.logger.warn(`Failed to use fuser to check lock: ${e}`);\n return null;\n }\n }\n\n private async findLockHolder(lockFilePath: string): Promise<LockProcessInfo | null> {\n const viaLsof = await this.findLockHolderWithLsof(lockFilePath);\n if (viaLsof) {\n return viaLsof;\n }\n return this.findLockHolderWithFuser(lockFilePath);\n }\n\n private async killRemoteProcess(pid: number): Promise<void> {\n this.logger.info(`Killing process ${pid}...`);\n\n try {\n // Try graceful termination first\n await this.sshClient.exec(`kill ${pid} 2>/dev/null || true`);\n await sleep(1000);\n\n // Check if process still exists\n try {\n await this.sshClient.exec(`kill -0 ${pid} 2>/dev/null`);\n // Process still exists, force kill\n this.logger.warn(`Process ${pid} still alive after SIGTERM, forcing kill...`);\n await this.sshClient.exec(`kill -9 ${pid} 2>/dev/null || true`);\n await sleep(500);\n } catch {\n // Process is dead, nothing to do\n }\n } catch (e: unknown) {\n const msg = `Failed to kill process ${pid}: ${e}`;\n this.logger.error(msg);\n throw new Error(msg);\n }\n }\n\n /** We have to extract pl in the remote server,\n * because Windows doesn't support symlinks\n * that are found in Linux pl binaries tgz archive.\n * For this reason, we extract all to the remote server.\n * It requires `tar` to be installed on the server\n * (it's not installed for Rocky Linux for example). */\n public async downloadAndUntar(\n localWorkdir: string,\n remoteHome: string,\n arch: Arch,\n softwareName: string,\n tgzName: string,\n dispatcher?: Dispatcher,\n ): Promise<DownloadAndUntarState> {\n const state: DownloadAndUntarState = {};\n state.binBasePath = plpath.binariesDir(remoteHome);\n await this.sshClient.ensureRemoteDirCreated(state.binBasePath);\n state.binBasePathCreated = true;\n\n let downloadBinaryResult: DownloadBinaryResult | null = null;\n const attempts = 5;\n for (let i = 1; i <= attempts; i++) {\n try {\n downloadBinaryResult = await downloadBinaryNoExtract({\n logger: this.logger,\n baseDir: localWorkdir,\n softwareName,\n tgzName,\n arch: arch.arch,\n platform: arch.platform,\n dispatcher,\n });\n break;\n } catch (e: unknown) {\n await sleep(300);\n if (i == attempts) {\n throw new Error(`downloadAndUntar: ${attempts} attempts, last error: ${e}`);\n }\n }\n }\n state.downloadResult = notEmpty(downloadBinaryResult);\n\n state.localArchivePath = upath.resolve(state.downloadResult.archivePath);\n state.remoteDir = upath.join(state.binBasePath, state.downloadResult.baseName);\n state.remoteArchivePath = state.remoteDir + \".tgz\";\n\n await this.sshClient.ensureRemoteDirCreated(state.remoteDir);\n await this.sshClient.uploadFile(state.localArchivePath, state.remoteArchivePath);\n state.uploadDone = true;\n\n try {\n await this.sshClient.exec(\"hash tar\");\n } catch {\n throw new Error(\n `tar is not installed on the server. Please install it before running Platforma.`,\n );\n }\n\n // TODO: Create a proper archive to avoid xattr warnings\n const untarResult = await this.sshClient.exec(\n `tar --warning=no-all -xvf ${state.remoteArchivePath} --directory=${state.remoteDir}`,\n );\n\n if (untarResult.stderr)\n throw new Error(\n `downloadAndUntar: untar: stderr occurred: ${untarResult.stderr}, stdout: ${untarResult.stdout}`,\n );\n\n state.untarDone = true;\n\n return state;\n }\n\n public async needDownload(remoteHome: string, arch: Arch) {\n const checkPathSupervisor = plpath.supervisorBin(remoteHome, arch.arch);\n const checkPathMinio = plpath.minioDir(remoteHome, arch.arch);\n const checkPathPlatforma = plpath.platformaBin(remoteHome, arch.arch);\n\n if (\n !(await this.sshClient.checkFileExists(checkPathPlatforma)) ||\n !(await this.sshClient.checkFileExists(checkPathMinio)) ||\n !(await this.sshClient.checkFileExists(checkPathSupervisor))\n ) {\n return true;\n }\n\n return false;\n }\n\n public async checkIsAliveWithInterval(\n shouldUseMinio: boolean,\n interval: number = 1000,\n count = 15,\n shouldStart = true,\n ): Promise<void> {\n const maxMs = count * interval;\n\n let total = 0;\n let alive = await this.isAlive();\n while (shouldStart ? !isAllAlive(alive, shouldUseMinio) : isAllAlive(alive, shouldUseMinio)) {\n await sleep(interval);\n total += interval;\n if (total > maxMs) {\n throw new Error(\n `isAliveWithInterval: The process did not ${shouldStart ? \"started\" : \"stopped\"} after ${maxMs} ms. Live status: ${JSON.stringify(alive)}`,\n );\n }\n alive = await this.isAlive();\n }\n }\n\n public async readExistedConfig(remoteHome: string): Promise<ConnectionInfo> {\n const connectionInfo = await this.sshClient.readFile(plpath.connectionInfo(remoteHome));\n return parseConnectionInfo(connectionInfo);\n }\n\n public async fetchPorts(remoteHome: string, arch: Arch): Promise<SshPlPorts> {\n const ports: SshPlPorts = {\n grpc: {\n local: await getFreePort(),\n remote: await this.getFreePortForPlatformaOnServer(remoteHome, arch),\n },\n monitoring: {\n local: await getFreePort(),\n remote: await this.getFreePortForPlatformaOnServer(remoteHome, arch),\n },\n debug: {\n local: await getFreePort(),\n remote: await this.getFreePortForPlatformaOnServer(remoteHome, arch),\n },\n http: {\n local: await getFreePort(),\n remote: await this.getFreePortForPlatformaOnServer(remoteHome, arch),\n },\n minioPort: {\n local: await getFreePort(),\n remote: await this.getFreePortForPlatformaOnServer(remoteHome, arch),\n },\n minioConsolePort: {\n local: await getFreePort(),\n remote: await this.getFreePortForPlatformaOnServer(remoteHome, arch),\n },\n };\n\n return ports;\n }\n\n public async getLocalFreePort(): Promise<number> {\n return new Promise((res) => {\n const srv = net.createServer();\n srv.listen(0, () => {\n const port = (srv.address() as net.AddressInfo).port;\n srv.close((_) => res(port));\n });\n });\n }\n\n public async getFreePortForPlatformaOnServer(remoteHome: string, arch: Arch): Promise<number> {\n const freePortBin = plpath.platformaFreePortBin(remoteHome, arch.arch);\n\n const { stdout, stderr } = await this.sshClient.exec(`${freePortBin}`);\n if (stderr) {\n throw new Error(\n `getFreePortForPlatformaOnServer: stderr is not empty: ${stderr}, stdout: ${stdout}`,\n );\n }\n\n return +stdout;\n }\n\n public async getArch(): Promise<Arch> {\n const { stdout, stderr } = await this.sshClient.exec(\"uname -s && uname -m\");\n if (stderr) throw new Error(`getArch: stderr is not empty: ${stderr}, stdout: ${stdout}`);\n\n const arr = stdout.split(\"\\n\");\n\n return {\n platform: arr[0],\n arch: arr[1],\n };\n }\n\n public async getUserHomeDirectory() {\n const { stdout, stderr } = await this.sshClient.exec(\"echo $HOME\");\n\n if (stderr) {\n const home = `/home/${this.username}`;\n console.warn(\n `getUserHomeDirectory: stderr is not empty: ${stderr}, stdout: ${stdout}, will get a default home: ${home}`,\n );\n\n return home;\n }\n\n return stdout.trim();\n }\n}\n\ntype Arch = { platform: string; arch: string };\n\nexport type SshPlConfig = {\n localWorkdir: string;\n license: PlLicenseMode;\n useGlobalAccess?: boolean;\n plBinary?: PlBinarySourceDownload;\n proxy?: ProxySettings;\n\n onProgress?: (...args: any) => Promise<any>;\n plConfigPostprocessing?: (config: PlConfig) => PlConfig;\n};\n\nexport type LockProcessInfo = { pid: number; user: string };\n\nconst defaultSshPlConfig: Pick<SshPlConfig, \"useGlobalAccess\" | \"plBinary\"> = {\n useGlobalAccess: false,\n plBinary: {\n type: \"Download\",\n version: getDefaultPlVersion(),\n },\n};\n\ntype BinPaths = {\n history?: DownloadAndUntarState[];\n minioRelPath?: string;\n downloadedPl: string;\n};\n\ntype DownloadAndUntarState = {\n binBasePath?: string;\n binBasePathCreated?: boolean;\n downloadResult?: DownloadBinaryResult;\n attempts?: number;\n\n localArchivePath?: string;\n remoteDir?: string;\n remoteArchivePath?: string;\n uploadDone?: boolean;\n untarDone?: boolean;\n};\n\ntype PlatformaInitStep =\n | \"init\"\n | \"detectArch\"\n | \"detectHome\"\n | \"checkAlive\"\n | \"stopExistedPlatforma\"\n | \"checkDbLock\"\n | \"downloadBinaries\"\n | \"fetchPorts\"\n | \"generateNewConfig\"\n | \"createFoldersAndSaveFiles\"\n | \"configureSupervisord\"\n | \"saveNewConnectionInfo\"\n | \"startPlatforma\";\n\ntype PlatformaInitState = {\n step: PlatformaInitStep;\n localWorkdir?: string;\n plBinaryOps?: PlBinarySourceDownload;\n arch?: Arch;\n remoteHome?: string;\n alive?: SupervisorStatus;\n existedSettings?: ConnectionInfo;\n needRestart?: boolean;\n shouldUseMinio?: boolean;\n downloadedBinaries?: DownloadAndUntarState[];\n binPaths?: BinPaths;\n ports?: SshPlPorts;\n generatedConfig?: SshPlConfigGenerationResult;\n connectionInfo?: ConnectionInfo;\n started?: boolean;\n};\n\n/**\n * Gets the glibc version on the remote system\n * @returns The glibc version as a number\n * @throws Error if version cannot be determined\n */\nasync function getGlibcVersion(logger: MiLogger, sshClient: SshClient): Promise<number> {\n try {\n const { stdout, stderr } = await sshClient.exec(\"ldd --version | head -n 1\");\n if (stderr) {\n throw new Error(`Failed to check glibc version: ${stderr}`);\n }\n return parseGlibcVersion(stdout);\n } catch (e: unknown) {\n logger.error(`glibc version check failed: ${e}`);\n throw e;\n }\n}\n\nexport function parseGlibcVersion(output: string): number {\n const versionMatch = output.match(/\\d+\\.\\d+/);\n if (!versionMatch) {\n throw new Error(`Could not parse glibc version from: ${output}`);\n }\n\n return parseFloat(versionMatch[0]);\n}\n"],"mappings":";;;;;;;;;;;;;;;AAkCA,MAAM,0BAA0B;AAEhC,IAAa,QAAb,MAAa,MAAM;CACjB,YAAwC,EAAE,MAAM,QAAQ;CACxD,YACE,QACA,WACA,UACA;AAHgB,OAAA,SAAA;AACA,OAAA,YAAA;AACC,OAAA,WAAA;;CAGnB,OAAc;AACZ,SAAO;GACL,UAAU,KAAK;GACf,WAAW,KAAK;GACjB;;CAGH,aAAoB,KAAK,QAAkB,QAA2C;AACpF,MAAI;AAEF,UAAO,IAAI,MAAM,QADC,MAAMA,YAAAA,UAAU,KAAK,QAAQ,OAAO,GAAA,GAAA,2BAAA,UACT,OAAO,SAAS,CAAC;WACvD,GAAY;AACnB,UAAO,MAAM,uCAAuC,IAAI;AACxD,SAAM;;;CAIV,UAA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iBAAA,CAAkB,MAAA"}
|
package/dist/ssh/pl.js
CHANGED
|
@@ -9,7 +9,6 @@ import upath from "upath";
|
|
|
9
9
|
import { defaultHttpDispatcher } from "@milaboratories/pl-http";
|
|
10
10
|
import net from "node:net";
|
|
11
11
|
import { generateSshPlConfigs, getFreePort } from "@milaboratories/pl-config";
|
|
12
|
-
|
|
13
12
|
//#region src/ssh/pl.ts
|
|
14
13
|
const minRequiredGlibcVersion = 2.28;
|
|
15
14
|
var SshPl = class SshPl {
|
|
@@ -553,7 +552,7 @@ function parseGlibcVersion(output) {
|
|
|
553
552
|
if (!versionMatch) throw new Error(`Could not parse glibc version from: ${output}`);
|
|
554
553
|
return parseFloat(versionMatch[0]);
|
|
555
554
|
}
|
|
556
|
-
|
|
557
555
|
//#endregion
|
|
558
556
|
export { SshPl, parseGlibcVersion };
|
|
557
|
+
|
|
559
558
|
//# sourceMappingURL=pl.js.map
|