36 lines
861 B
TypeScript
36 lines
861 B
TypeScript
import { exec } from 'child_process';
|
|
|
|
export class ReloadExecutor {
|
|
constructor(
|
|
private host = '127.0.0.1',
|
|
private port = 953,
|
|
private keyFile = 'rndc.key'
|
|
) {}
|
|
|
|
static fromEnvironment(): ReloadExecutor {
|
|
return new ReloadExecutor(
|
|
process.env.RNDC_SERVER,
|
|
parseInt(process.env.RNDC_PORT || '953', 10),
|
|
process.env.RNDC_KEYFILE
|
|
)
|
|
}
|
|
|
|
private async rndc(command: string, data: string): Promise<string> {
|
|
return new Promise((resolve, reject) => {
|
|
exec(`rndc -k ${this.keyFile} -s ${this.host} -p ${this.port} ${command} ${data}`,
|
|
(error, stdout) => {
|
|
if (error) {
|
|
reject(error);
|
|
return;
|
|
}
|
|
resolve(stdout);
|
|
}
|
|
);
|
|
});
|
|
}
|
|
|
|
public async reload(domain: string): Promise<string> {
|
|
return this.rndc('reload', domain);
|
|
}
|
|
}
|