45 lines
1.0 KiB
TypeScript
45 lines
1.0 KiB
TypeScript
|
|
// 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
|
||
|
|
|
||
|
|
}
|