feat: Add in the new changes for the new init system that is going to be used in the startos

This commit is contained in:
J H
2023-11-28 13:15:15 -07:00
parent 27127f58d4
commit 125c7a2ac3
3 changed files with 32 additions and 7 deletions

View File

@@ -11,6 +11,7 @@ import {
ExtractStore,
InterfaceId,
PackageId,
Signals,
ValidIfNoStupidEscape,
} from "../types"
import { GetSystemSmtp } from "./GetSystemSmtp"
@@ -38,6 +39,10 @@ import * as CP from "node:child_process"
import { promisify } from "node:util"
import { splitCommand } from "./splitCommand"
export const SIGTERM: Signals = "SIGTERM"
export const SIGKILL: Signals = "SIGTERM"
export const NO_TIMEOUT = -1
const childProcess = {
exec: promisify(CP.exec),
execFile: promisify(CP.execFile),
@@ -204,8 +209,19 @@ export const utils = <Store = never, WrapperOverWrite = { const: never }>(
wait() {
return answer
},
async term() {
childProcess.kill()
async term({ signal = SIGTERM, timeout = NO_TIMEOUT } = {}) {
childProcess.kill(signal)
if (timeout <= NO_TIMEOUT) {
const didTimeout = await Promise.race([
new Promise((resolve) => setTimeout(resolve, timeout)).then(
() => true,
),
answer.then(() => false),
])
if (didTimeout) childProcess.kill(SIGKILL)
}
await answer
},
}
},