diff --git a/src/sftp.js b/src/sftp.js index 0f10c8ad9..2dc3bc75d 100644 --- a/src/sftp.js +++ b/src/sftp.js @@ -34,7 +34,8 @@ async function ensureKeys() { debug(`ensureSecrets: generating new sftp keys of type ${keyType}`); safe.fs.unlinkSync(publicKeyFile); safe.fs.unlinkSync(privateKeyFile); - if (!safe.child_process.execSync(`ssh-keygen -m PEM -t ${keyType} -f "${paths.SFTP_KEYS_DIR}/ssh_host_${keyType}_key" -q -N ""`)) throw new BoxError(BoxError.OPENSSL_ERROR, `Could not generate sftp ${keyType} keys: ${safe.error.message}`); + const [error] = await safe(shell.promises.exec('ensureKeys', `ssh-keygen -m PEM -t ${keyType} -f "${paths.SFTP_KEYS_DIR}/ssh_host_${keyType}_key" -q -N ""`, {})); + if (error) throw new BoxError(BoxError.OPENSSL_ERROR, `Could not generate sftp ${keyType} keys: ${error.message}`); const newPublicKey = safe.fs.readFileSync(publicKeyFile); await blobs.set(`sftp_${keyType}_public_key`, newPublicKey); const newPrivateKey = safe.fs.readFileSync(privateKeyFile); diff --git a/src/shell.js b/src/shell.js index f830031ae..f8852431f 100644 --- a/src/shell.js +++ b/src/shell.js @@ -33,9 +33,6 @@ function exec(tag, cmd, options, callback) { const stdoutResult = stdout ? stdout.toString('utf8') : null; const stderrResult = stderr ? stderr.toString('utf8') : null; - debug(`${tag} (stdout): %s`, stdoutResult); - debug(`${tag} (stderr): %s`, stderrResult); - if (error) error.stdout = stdoutResult; // when promisified, this is the way to get stdout if (error) error.stderr = stderrResult; // when promisified, this is the way to get stderr diff --git a/src/system.js b/src/system.js index 139a02bea..6f5e51fcc 100644 --- a/src/system.js +++ b/src/system.js @@ -68,8 +68,8 @@ async function hdparm(file) { } async function getSwaps() { - const stdout = safe.child_process.execSync('swapon --noheadings --raw --bytes --show=type,size,used,name', { encoding: 'utf8' }); - if (!stdout) return {}; + const [error, stdout] = await safe(shell.promises.exec('getSwaps', 'swapon --noheadings --raw --bytes --show=type,size,used,name', { encoding: 'utf8' })); + if (error) return {}; const swaps = {}; for (const line of stdout.trim().split('\n')) { @@ -329,8 +329,10 @@ async function getLogs(unit, options) { } async function getBlockDevices() { - const info = safe.JSON.parse(safe.child_process.execSync('lsblk --paths --json --list --fs', { encoding: 'utf8' })); - if (!info) throw new BoxError(BoxError.INTERNAL_ERROR, safe.error.message); + const [error, result] = await safe(shell.promises.exec('getBlockDevices', 'lsblk --paths --json --list --fs', { encoding: 'utf8' })); + if (error) throw new BoxError(BoxError.INTERNAL_ERROR, `lsblk failed: ${error.message}`); + const info = safe.JSON.parse(result); + if (!info) throw new BoxError(BoxError.INTERNAL_ERROR, `failed to parse lsblk: ${safe.error.message}`); const devices = info.blockdevices.filter(d => d.fstype === 'ext4' || d.fstype === 'xfs');