chore: Add in the possibility to get the status code from the executed health check

This commit is contained in:
J H
2024-03-07 13:36:38 -07:00
parent efbbaa5741
commit 328beaba35
2 changed files with 54 additions and 7 deletions

View File

@@ -73,6 +73,15 @@ export class DockerProcedureContainer {
}
}
async execSpawn(commands: string[]) {
try {
const spawned = await this.overlay.spawn(commands)
return spawned
} finally {
await this.overlay.destroy()
}
}
async spawn(commands: string[]): Promise<cp.ChildProcessWithoutNullStreams> {
return await this.overlay.spawn(commands)
}

View File

@@ -3,6 +3,7 @@ import { DockerProcedureContainer } from "./DockerProcedureContainer"
import { SystemForEmbassy } from "."
import { HostSystemStartOs } from "../../HostSystemStartOs"
import { util, Daemons, types as T } from "@start9labs/start-sdk"
import { exec } from "child_process"
const EMBASSY_HEALTH_INTERVAL = 15 * 1000
const EMBASSY_PROPERTIES_LOOP = 30 * 1000
@@ -117,17 +118,54 @@ export class MainLoop {
actionProcedure,
manifest.volumes,
)
const executed = await container.exec([
const executed = await container.execSpawn([
actionProcedure.entrypoint,
...actionProcedure.args,
JSON.stringify(timeChanged),
])
const stderr = executed.stderr.toString()
if (stderr)
console.error(
`Error running health check ${value.name}: ${stderr}`,
)
return executed.stdout.toString()
if (executed.exitCode === 59) {
await effects.setHealth({
name: healthId,
status: "disabled",
message:
executed.stderr.toString() || executed.stdout.toString(),
})
return
}
if (executed.exitCode === 60) {
await effects.setHealth({
name: healthId,
status: "starting",
message:
executed.stderr.toString() || executed.stdout.toString(),
})
return
}
if (executed.exitCode === 61) {
await effects.setHealth({
name: healthId,
status: "warning",
message:
executed.stderr.toString() || executed.stdout.toString(),
})
return
}
const errorMessage = executed.stderr.toString()
const message = executed.stdout.toString()
if (!!errorMessage) {
await effects.setHealth({
name: healthId,
status: "failure",
message: errorMessage,
})
return
}
await effects.setHealth({
name: healthId,
status: "passing",
message,
})
return
} else {
actionProcedure
const moduleCode = await this.system.moduleCode