stabilize, add daemon state, add base build script
This commit is contained in:
parent
a1963cf491
commit
241d50e42a
12 changed files with 512 additions and 46 deletions
|
@ -1 +1,37 @@
|
|||
// wrapper
|
||||
|
||||
import { log_from, sleep } from "./utils.ts";
|
||||
|
||||
const log = log_from("nspawn");
|
||||
|
||||
export function container_command(name: string, directory: string, opts?: {
|
||||
veth?: boolean;
|
||||
boot?: boolean;
|
||||
cmd_opts?: Deno.CommandOptions;
|
||||
}) {
|
||||
const args = [
|
||||
`--machine=${name}`,
|
||||
`--directory=${directory}`,
|
||||
];
|
||||
if (opts?.veth ?? false) args.push("--network-veth");
|
||||
if (opts?.boot ?? false) args.push("--boot");
|
||||
const command = new Deno.Command("systemd-nspawn", { ...opts?.cmd_opts, args });
|
||||
return command;
|
||||
}
|
||||
|
||||
export async function get_container_addresses(name: string) {
|
||||
const command = new Deno.Command("machinectl", { args: ["status", name], stdout: "piped" });
|
||||
while (true) {
|
||||
await sleep(500);
|
||||
log("getting address of", name);
|
||||
const { code, stdout } = await command.output();
|
||||
if (code != 0) continue;
|
||||
const output = new TextDecoder().decode(stdout);
|
||||
const [_, rest] = output.split(" Address: ");
|
||||
if (rest === undefined) continue;
|
||||
const [raw] = rest.split(" OS: ");
|
||||
const addresses = raw.trim().split("\n").map((l) => l.trim());
|
||||
if (addresses.length === 0) continue;
|
||||
return addresses;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue