fix: Making the daemons keep up the status. (#2617)

* complete get_primary_url fn

* complete clear_network_interfaces fn

* formatting

* complete remove_address fn

* get_system_smtp wip

* complete get_system_smtp and set_system_smtp

* add SetSystemSmtpParams struct

* add set_system_smtp subcommand

* Remove 'Copy' implementation from `HostAddress`

Co-authored-by: Aiden McClelland <3732071+dr-bonez@users.noreply.github.com>

* Refactor `get_host_primary` fn and clone  resulting `HostAddress`

Co-authored-by: Aiden McClelland <3732071+dr-bonez@users.noreply.github.com>

* misc fixes and debug info

* seed hosts with a tor address

* fix: Making the daemons keep up the status.

* wipFix: Making a service start

* fix: Both the start + stop of the service.

* fix: Weird edge case of failure and kids

---------

Co-authored-by: Shadowy Super Coder <musashidisciple@proton.me>
Co-authored-by: Aiden McClelland <3732071+dr-bonez@users.noreply.github.com>
Co-authored-by: Aiden McClelland <me@drbonez.dev>
This commit is contained in:
Jade
2024-05-13 10:50:25 -06:00
committed by GitHub
parent 800b0763e4
commit 0b8a142de0
14 changed files with 467 additions and 168 deletions

View File

@@ -3,6 +3,7 @@ import { DockerProcedureContainer } from "./DockerProcedureContainer"
import { SystemForEmbassy } from "."
import { HostSystemStartOs } from "../../HostSystemStartOs"
import { Daemons, T, daemons } from "@start9labs/start-sdk"
import { Daemon } from "@start9labs/start-sdk/cjs/lib/mainFn/Daemon"
const EMBASSY_HEALTH_INTERVAL = 15 * 1000
const EMBASSY_PROPERTIES_LOOP = 30 * 1000
@@ -21,8 +22,7 @@ export class MainLoop {
private mainEvent:
| Promise<{
daemon: T.DaemonReturned
wait: Promise<unknown>
daemon: Daemon
}>
| undefined
constructor(
@@ -51,7 +51,7 @@ export class MainLoop {
if (jsMain) {
throw new Error("Unreachable")
}
const daemon = await daemons.runDaemon()(
const daemon = await Daemon.of()(
this.effects,
{ id: this.system.manifest.main.image },
currentCommand,
@@ -59,14 +59,9 @@ export class MainLoop {
overlay: dockerProcedureContainer.overlay,
},
)
daemon.start()
return {
daemon,
wait: daemon.wait().finally(() => {
this.clean()
effects
.setMainStatus({ status: "stopped" })
.catch((e) => console.error("Could not set the status to stopped"))
}),
}
}
@@ -121,7 +116,8 @@ export class MainLoop {
const main = await mainEvent
delete this.mainEvent
delete this.healthLoops
if (mainEvent) await main?.daemon.term()
await main?.daemon.stop().catch((e) => console.error(e))
this.effects.setMainStatus({ status: "stopped" })
if (healthLoops) healthLoops.forEach((x) => clearInterval(x.interval))
}

View File

@@ -385,13 +385,15 @@ export class SystemForEmbassy implements System {
timeoutMs: number | null,
): Promise<Duration> {
const { currentRunning } = this
this.currentRunning?.clean()
delete this.currentRunning
if (currentRunning) {
await currentRunning.clean({
timeout: this.manifest.main["sigterm-timeout"],
})
}
return duration(this.manifest.main["sigterm-timeout"], "s")
const durationValue = duration(this.manifest.main["sigterm-timeout"], "s")
return durationValue
}
private async createBackup(
effects: HostSystemStartOs,

View File

@@ -116,7 +116,7 @@ export class PolyfillEffects implements oet.Effects {
this.manifest.volumes,
)
const daemon = dockerProcedureContainer.then((dockerProcedureContainer) =>
daemons.runDaemon()(
daemons.runCommand()(
this.effects,
{ id: this.manifest.main.image },
[input.command, ...(input.args || [])],

View File

@@ -2,5 +2,5 @@ export type TimeUnit = "d" | "h" | "s" | "ms"
export type Duration = `${number}${TimeUnit}`
export function duration(timeValue: number, timeUnit: TimeUnit = "s") {
return `${timeValue}${timeUnit}` as Duration
return `${timeValue > 0 ? timeValue : 0}${timeUnit}` as Duration
}

View File

@@ -1,5 +1,3 @@
import { types as T } from "@start9labs/start-sdk"
export type Effects = T.Effects & {
setMainStatus(o: { status: "running" | "stopped" }): Promise<void>
}
export type Effects = T.Effects