diff --git a/instance/src/lib.ts b/instance/src/lib.ts index 6e1e18f..84382c1 100644 --- a/instance/src/lib.ts +++ b/instance/src/lib.ts @@ -74,26 +74,27 @@ export function start_runner(config: ContainerConfig) { const command = container_command(name, paths.root, { boot: true, veth: true, + ports: config.redirects, cmd_opts: { stdin: "null", stdout: "null", }, }); - const proxies = [] as LoopProcess[]; + // const proxies = [] as LoopProcess[]; const container_loop = loop_process(command, { on_start: () => { log("container", name, "started"); - (async () => { - await sleep(1_000); - const [address] = await get_container_addresses(name); - proxies.push(...start_proxies(address, config.redirects)); - })(); + // (async () => { + // await sleep(1_000); + // const [address] = await get_container_addresses(name); + // proxies.push(...start_proxies(address, config.redirects)); + // })(); }, on_stop: async () => { log("container", name, "stopped"); - for (const p of proxies) await p.kill(); - await sleep(500); - proxies.splice(0, proxies.length); + // for (const p of proxies) await p.kill(); + // await sleep(500); + // proxies.splice(0, proxies.length); }, }); return { @@ -101,7 +102,7 @@ export function start_runner(config: ContainerConfig) { config, container_loop, stop: async () => { - for (const p of proxies) await p.kill(); + // for (const p of proxies) await p.kill(); await container_loop.kill(); }, }; diff --git a/instance/src/lib/nspawn.ts b/instance/src/lib/nspawn.ts index d5fc189..eb7527f 100644 --- a/instance/src/lib/nspawn.ts +++ b/instance/src/lib/nspawn.ts @@ -7,6 +7,7 @@ const log = log_from("nspawn"); export function container_command(name: string, directory: string, opts?: { veth?: boolean; boot?: boolean; + ports?: [number, number][]; cmd_opts?: Deno.CommandOptions; }) { const args = [ @@ -15,6 +16,7 @@ export function container_command(name: string, directory: string, opts?: { ]; if (opts?.veth ?? false) args.push("--network-veth"); if (opts?.boot ?? false) args.push("--boot"); + for (const [from, to] of opts?.ports ?? []) args.push(`--port=${from}:${to}`); const command = new Deno.Command("systemd-nspawn", { ...opts?.cmd_opts, args }); return command; }