import { Injectable } from '@nestjs/common'; import { ConfigService } from '@nestjs/config'; import { exec } from 'child_process'; @Injectable() export class RNDCService { private host = this.config.get('rndc.host'); private port = this.config.get('rndc.port'); private keyFile = this.config.get('rndc.keyFile'); constructor(private config: ConfigService) {} private async rndc(command: string, data: string): Promise { 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 { return this.rndc('reload', domain); } }