convert more execSync to async
This commit is contained in:
@@ -41,6 +41,7 @@ const apps = require('./apps.js'),
|
||||
dashboard = require('./dashboard.js'),
|
||||
debug = require('debug')('box:docker'),
|
||||
Docker = require('dockerode'),
|
||||
fs = require('fs'),
|
||||
paths = require('./paths.js'),
|
||||
promiseRetry = require('./promise-retry.js'),
|
||||
services = require('./services.js'),
|
||||
@@ -237,16 +238,18 @@ async function getMounts(app) {
|
||||
|
||||
// This only returns ipv4 addresses
|
||||
// We dont bind to ipv6 interfaces, public prefix changes and container restarts wont work
|
||||
function getAddressesForPort53() {
|
||||
const deviceLinks = safe.fs.readdirSync('/sys/class/net'); // https://man7.org/linux/man-pages/man5/sysfs.5.html
|
||||
if (!deviceLinks) return [];
|
||||
async function getAddressesForPort53() {
|
||||
const [error, deviceLinks] = await safe(fs.promises.readdir('/sys/class/net')); // https://man7.org/linux/man-pages/man5/sysfs.5.html
|
||||
if (error) return [];
|
||||
|
||||
const devices = deviceLinks.map(d => { return { name: d, link: safe.fs.readlinkSync(`/sys/class/net/${d}`) }; });
|
||||
const physicalDevices = devices.filter(d => d.link && !d.link.includes('virtual'));
|
||||
|
||||
const addresses = [];
|
||||
for (const phy of physicalDevices) {
|
||||
const inet = safe.JSON.parse(safe.child_process.execSync(`ip -f inet -j addr show dev ${phy.name} scope global`, { encoding: 'utf8' }));
|
||||
const [error, output] = await safe(shell.promises.exec('getAddressesForPort53', `ip -f inet -j addr show dev ${phy.name} scope global`, { encoding: 'utf8' }));
|
||||
if (error) continue;
|
||||
const inet = safe.JSON.parse(output) || [];
|
||||
for (const r of inet) {
|
||||
const address = safe.query(r, 'addr_info[0].local');
|
||||
if (address) addresses.push(address);
|
||||
@@ -290,7 +293,7 @@ async function createSubcontainer(app, name, cmd, options) {
|
||||
const ports = portType == 'tcp' ? manifest.tcpPorts : manifest.udpPorts;
|
||||
const containerPort = ports[portName].containerPort || hostPort;
|
||||
const portCount = ports[portName].portCount || 1;
|
||||
const hostIps = hostPort === 53 ? getAddressesForPort53() : [ '0.0.0.0', '::0' ]; // port 53 is special because it is possibly taken by systemd-resolved
|
||||
const hostIps = hostPort === 53 ? await getAddressesForPort53() : [ '0.0.0.0', '::0' ]; // port 53 is special because it is possibly taken by systemd-resolved
|
||||
|
||||
portEnv.push(`${portName}=${hostPort}`);
|
||||
if (portCount > 1) portEnv.push(`${portName}_COUNT=${portCount}`);
|
||||
|
||||
Reference in New Issue
Block a user