mirror of
https://github.com/tale/headplane.git
synced 2026-07-26 07:48:14 +00:00
0512565f8e
Apparently I didn't use my brain cells and rely on the /version endpoint that Headscale has exposed since 0.26 (our lowest supported version). Switching to that significantly simplifies the API surface.
65 lines
1.4 KiB
TypeScript
65 lines
1.4 KiB
TypeScript
import { platform } from "node:os";
|
|
|
|
import { type } from "arktype";
|
|
|
|
import type { HeadscaleClient } from "~/server/headscale/api";
|
|
import log from "~/utils/log";
|
|
|
|
import { Integration } from "./abstract";
|
|
import { findHeadscaleServe, signalAndWaitHealthy } from "./proc-helper";
|
|
|
|
const configSchema = {
|
|
full: type({
|
|
enabled: "boolean",
|
|
}),
|
|
|
|
partial: type({
|
|
enabled: "boolean?",
|
|
}).partial(),
|
|
};
|
|
|
|
export default class ProcIntegration extends Integration<typeof configSchema.full.infer> {
|
|
private pid: number | undefined;
|
|
|
|
get name() {
|
|
return "Native Linux (/proc)";
|
|
}
|
|
|
|
static get configSchema() {
|
|
return configSchema;
|
|
}
|
|
|
|
async isAvailable() {
|
|
if (platform() !== "linux") {
|
|
log.error("config", "/proc is only available on Linux");
|
|
return false;
|
|
}
|
|
|
|
try {
|
|
const result = await findHeadscaleServe();
|
|
if (!result) {
|
|
log.error("config", "Could not find headscale serve process");
|
|
return false;
|
|
}
|
|
|
|
this.pid = result;
|
|
log.info("config", "Found headscale serve (PID %d)", this.pid);
|
|
return true;
|
|
} catch (error) {
|
|
log.error("config", "Failed to scan /proc: %s", error);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
async onConfigChange(client: HeadscaleClient) {
|
|
if (!this.pid) {
|
|
return;
|
|
}
|
|
|
|
await signalAndWaitHealthy(client, {
|
|
pid: this.pid,
|
|
signal: "SIGHUP",
|
|
});
|
|
}
|
|
}
|