move to correct structure
This commit is contained in:
parent
44825c4c31
commit
54c4e91af8
12 changed files with 118 additions and 1 deletions
42
instance/daemon.ts
Executable file
42
instance/daemon.ts
Executable file
|
@ -0,0 +1,42 @@
|
|||
#!/bin/env -S deno run -A --unstable
|
||||
|
||||
import { daemon_listen, Runner, start_runner } from "./src/lib.ts";
|
||||
import { new_container_config } from "./src/lib/config.ts";
|
||||
import { socket_path } from "./src/lib/paths.ts";
|
||||
|
||||
await main();
|
||||
async function main() {
|
||||
const enabled = new Map<string, Runner>();
|
||||
|
||||
for await (const { cmd, respond } of daemon_listen(socket_path())) {
|
||||
console.log("received", { cmd });
|
||||
|
||||
if (cmd.kind === "status") {
|
||||
await respond(JSON.stringify(Array.from(enabled.keys())));
|
||||
continue;
|
||||
}
|
||||
|
||||
if (cmd.kind === "enable") {
|
||||
const config = new_container_config(cmd.name); // TODO
|
||||
const runner = start_runner(config);
|
||||
enabled.set(cmd.name, runner);
|
||||
await respond("enabled");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (cmd.kind === "disable") {
|
||||
await enabled.get(cmd.name)?.stop();
|
||||
enabled.delete(cmd.name);
|
||||
await respond("disabled");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (cmd.kind === "stop") {
|
||||
await respond(JSON.stringify("stopping, ++"));
|
||||
for (const runner of enabled.values()) await runner.stop();
|
||||
Deno.exit(0);
|
||||
}
|
||||
|
||||
await respond("unknown");
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue