mirror of
https://github.com/11notes/docker-traefik-labels.git
synced 2026-07-19 10:22:03 -05:00
33 lines
1.1 KiB
JavaScript
33 lines
1.1 KiB
JavaScript
const { spawn } = require('node:child_process');
|
|
const { elevenLogJSON } = require('/labels/lib/util.js');
|
|
|
|
exports.nsupdate = async(server, key, commands) => {
|
|
|
|
commands.unshift(`server ${server}`);
|
|
commands.push('send');
|
|
commands.push('quit');
|
|
|
|
return(new Promise((resolve, reject) => {
|
|
elevenLogJSON('debug', {method:'nsupdate()', params:{server:server, key:'******', commands:commands}});
|
|
const nsupdate = spawn('/usr/bin/nsupdate', ['-y', key]);
|
|
const io = {stdout:'', stderr:''};
|
|
nsupdate.stderr.on('data', data => {io.stderr += data.toString()});
|
|
nsupdate.stdout.on('data', data => {io.stdout += (data.toString()).replace(/[\r\n]*$/ig, '')});
|
|
nsupdate.on('error', error => {reject(error)});
|
|
nsupdate.on('close', code =>{
|
|
if(code === 0){
|
|
if(io.stderr.length > 0){
|
|
reject(io.stderr);
|
|
}else{
|
|
resolve(io.stdout);
|
|
}
|
|
}else{
|
|
reject(io.stderr);
|
|
}
|
|
});
|
|
for(const command of commands){
|
|
nsupdate.stdin.write(`${command}\n`);
|
|
}
|
|
nsupdate.stdin.end();
|
|
}));
|
|
} |