42 lines
1 KiB
TypeScript
Executable file
42 lines
1 KiB
TypeScript
Executable file
#!/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");
|
|
}
|
|
}
|