mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-30 12:11:56 +00:00
feat: Add the stop/start loop for the service
This commit is contained in:
@@ -276,7 +276,13 @@ export type Effects = {
|
||||
}): Promise<unknown>
|
||||
|
||||
/** A low level api used by makeOverlay */
|
||||
createOverlayedImage(options: { imageId: string }): Promise<string>
|
||||
createOverlayedImage(options: { imageId: string }): Promise<[string, string]>
|
||||
|
||||
/** A low level api used by destroyOverlay + makeOverlay:destroy */
|
||||
destroyOverlayedImage(options: {
|
||||
imageId: string
|
||||
guid: string
|
||||
}): Promise<void>
|
||||
|
||||
/** Removes all network bindings */
|
||||
clearBindings(): Promise<void>
|
||||
|
||||
@@ -10,9 +10,10 @@ export class Overlay {
|
||||
readonly effects: T.Effects,
|
||||
readonly imageId: string,
|
||||
readonly rootfs: string,
|
||||
readonly guid: string,
|
||||
) {}
|
||||
static async of(effects: T.Effects, imageId: string) {
|
||||
const rootfs = await effects.createOverlayedImage({ imageId })
|
||||
const [rootfs, guid] = await effects.createOverlayedImage({ imageId })
|
||||
|
||||
for (const dirPart of ["dev", "sys", "proc", "run"] as const) {
|
||||
await fs.mkdir(`${rootfs}/${dirPart}`, { recursive: true })
|
||||
@@ -23,7 +24,7 @@ export class Overlay {
|
||||
])
|
||||
}
|
||||
|
||||
return new Overlay(effects, imageId, rootfs)
|
||||
return new Overlay(effects, imageId, rootfs, guid)
|
||||
}
|
||||
|
||||
async mount(options: MountOptions, path: string): Promise<Overlay> {
|
||||
@@ -51,8 +52,9 @@ export class Overlay {
|
||||
}
|
||||
|
||||
async destroy() {
|
||||
await execFile("umount", ["-R", this.rootfs])
|
||||
await fs.rm(this.rootfs, { recursive: true, force: true })
|
||||
const imageId = this.imageId
|
||||
const guid = this.guid
|
||||
await this.effects.destroyOverlayedImage({ imageId, guid })
|
||||
}
|
||||
|
||||
async exec(
|
||||
|
||||
@@ -246,7 +246,7 @@ export const createUtils = <
|
||||
console.error(data.toString())
|
||||
})
|
||||
|
||||
childProcess.on("close", (code: any) => {
|
||||
childProcess.on("exit", (code: any) => {
|
||||
if (code === 0) {
|
||||
return resolve(null)
|
||||
}
|
||||
@@ -262,7 +262,7 @@ export const createUtils = <
|
||||
try {
|
||||
childProcess.kill(signal)
|
||||
|
||||
if (timeout <= NO_TIMEOUT) {
|
||||
if (timeout > NO_TIMEOUT) {
|
||||
const didTimeout = await Promise.race([
|
||||
new Promise((resolve) => setTimeout(resolve, timeout)).then(
|
||||
() => true,
|
||||
@@ -270,6 +270,7 @@ export const createUtils = <
|
||||
answer.then(() => false),
|
||||
])
|
||||
if (didTimeout) childProcess.kill(SIGKILL)
|
||||
return
|
||||
}
|
||||
await answer
|
||||
} finally {
|
||||
|
||||
Reference in New Issue
Block a user