enable nginx config management
This commit is contained in:
parent
686ed543ab
commit
466239d0e6
4 changed files with 55 additions and 20 deletions
|
@ -6,6 +6,7 @@ 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 { NginxController } from "./lib/nginx.ts";
|
||||
|
||||
const log = log_from("lib");
|
||||
|
||||
|
@ -70,15 +71,22 @@ export async function daemon_send(sock_path: string, command: Cmd) {
|
|||
export class Runner {
|
||||
name;
|
||||
config;
|
||||
loop: LoopProcess | null;
|
||||
nginx;
|
||||
loop;
|
||||
|
||||
constructor(config: ContainerConfig) {
|
||||
constructor(config: ContainerConfig, nginx: NginxController) {
|
||||
this.name = config.name;
|
||||
this.config = config;
|
||||
this.loop = null;
|
||||
this.nginx = nginx;
|
||||
this.loop = null as LoopProcess | null;
|
||||
}
|
||||
|
||||
start() {
|
||||
this.update_proxies();
|
||||
this.start_process();
|
||||
}
|
||||
|
||||
private start_process() {
|
||||
const paths = container_paths(name);
|
||||
const command = container_command(name, paths.root, {
|
||||
boot: true,
|
||||
|
@ -99,4 +107,18 @@ export class Runner {
|
|||
async stop() {
|
||||
await this.loop?.kill();
|
||||
}
|
||||
|
||||
async update_proxies() {
|
||||
const paths = container_paths(name);
|
||||
await Deno.mkdir(paths.sites, { recursive: true });
|
||||
const sites = new Set<string>();
|
||||
for (const redir of this.config.redirections) {
|
||||
if (redir.kind !== "http") continue;
|
||||
await this.nginx.add_proxy(redir.domain, redir.port, paths.sites);
|
||||
sites.add(redir.domain);
|
||||
}
|
||||
for await (const domains of this.nginx.read_all_in_dir(paths.sites)) {
|
||||
if (!sites.has(domains)) this.nginx.remove_proxy(domains, paths.sites);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue