SSL-Sniffer/src/lib/server/utils/nginx-utils.ts

45 lines
1.0 KiB
TypeScript
Raw Normal View History

2025-07-02 14:49:23 +00:00
// TODO: remove bun dependencies
import { logger } from "./logger"
import { shell } from "./shell-commands"
export async function reloadNginx() {
if (!await validateSchema()) {
// UGLY: make this a specific error
throw new Error("Something went wrong while validating")
}
// Start nginx, should be side-effect free
startNginx()
const output = await shell(`rc-service nginx reload`)
logger.debug(`rc-service reload output:\n${output.stdout}`, "NGINX - RELOAD")
}
export async function startNginx() {
if (!await validateSchema()) {
// UGLY: make this a specific error
throw new Error("Something went wrong while validating")
}
const output = await shell(`rc-service nginx start`)
}
export async function validateSchema() {
const output = await shell(`nginx -t 2>&1`)
logger.debug(`nginx -t output:\n${output.stdout}`, "NGINX - VALIDATE")
const successRegex = new RegExp("test is successful", "gm")
const result = successRegex.test(output.stdout)
return result
}