fixes leftover container

This commit is contained in:
JOLIMAITRE Matthieu 2024-02-04 02:58:09 +01:00
parent 2fa4ab9b12
commit 6c0038b421
3 changed files with 16 additions and 8 deletions

View file

@ -1,11 +1,10 @@
export type { Base, BaseContext } from "./lib/create.ts";
import { toText } from "https://deno.land/std@0.208.0/streams/to_text.ts";
import { lines, log_from, loop_process, run } from "./lib/utils.ts";
import { lines, log_from, loop_process, LoopProcess, run } from "./lib/utils.ts";
import { ContainerConfig } from "./lib/config.ts";
import { container_paths } from "./lib/paths.ts";
import { container_command } from "./lib/nspawn.ts";
import { LoopProcess } from "./lib/utils.ts";
import { container_command, stop_container } from "./lib/nspawn.ts";
import { NginxController } from "./lib/nginx.ts";
const log = log_from("lib");
@ -81,8 +80,9 @@ export class Runner {
this.loop = null as LoopProcess | null;
}
start() {
this.update_proxies();
async start() {
await stop_container(this.name);
await this.update_proxies();
this.start_process();
}

View file

@ -1,4 +1,4 @@
import { run } from "./utils.ts";
import { exists, run } from "./utils.ts";
import * as path from "https://deno.land/std@0.214.0/path/mod.ts";
export class NginxController {
@ -24,7 +24,7 @@ server {
const conf_file_path = path.join(conf_dir, domain + ".conf");
const enabled_conf_file_path = path.join(this.enabled_conf_dir, domain + ".conf");
await Deno.writeTextFile(conf_file_path, conf_file_content);
await Deno.remove(enabled_conf_file_path, { recursive: true });
if (await exists(enabled_conf_file_path)) await Deno.remove(enabled_conf_file_path);
await run("ln", "-s", await Deno.realPath(conf_file_path), enabled_conf_file_path);
await this.reload();
return conf_file_path;

View file

@ -1,6 +1,6 @@
// wrapper
import { log_from, sleep } from "./utils.ts";
import { log_from, run, sleep } from "./utils.ts";
import { ContainerConfigRedirection } from "./config.ts";
const log = log_from("nspawn");
@ -30,6 +30,14 @@ export function container_command(name: string, directory: string, opts?: {
return command;
}
export async function stop_container(name: string) {
try {
await run("machinectl", "stop", name);
} catch (_) {
//
}
}
export async function get_container_addresses(name: string) {
const command = new Deno.Command("machinectl", { args: ["status", name], stdout: "piped" });
while (true) {