diff --git a/src/backups.js b/src/backups.js index 50f393577..c6f5d08f5 100644 --- a/src/backups.js +++ b/src/backups.js @@ -856,7 +856,7 @@ function runBackupUpload(uploadConfig, progressCallback, callback) { let result = ''; // the script communicates error result as a string - shell.sudo(`backup-${backupId}`, [ BACKUP_UPLOAD_CMD, backupId, format, dataLayout.toString() ], { preserveEnv: true, ipc: true }, function (error) { + shell.sudo(`backup-${backupId}`, [ BACKUP_UPLOAD_CMD, backupId, format, dataLayout.toString() ], { preserveEnv: true, ipc: true, nice: 15 }, function (error) { if (error && (error.code === null /* signal */ || (error.code !== 0 && error.code !== 50))) { // backuptask crashed return callback(new BoxError(BoxError.INTERNAL_ERROR, 'Backuptask crashed')); } else if (error && error.code === 50) { // exited with error diff --git a/src/shell.js b/src/shell.js index 3bb8aa5ae..81342e465 100644 --- a/src/shell.js +++ b/src/shell.js @@ -13,7 +13,8 @@ var assert = require('assert'), once = require('once'), util = require('util'); -var SUDO = '/usr/bin/sudo'; +const SUDO = '/usr/bin/sudo'; +const NICE = '/usr/bin/nice'; function exec(tag, cmd, callback) { assert.strictEqual(typeof tag, 'string'); @@ -39,11 +40,16 @@ function spawn(tag, file, args, options, callback) { callback = once(callback); // exit may or may not be called after an 'error' - debug(tag + ' spawn: %s %s', file, args.join(' ')); - if (options.ipc) options.stdio = ['pipe', 'pipe', 'pipe', 'ipc']; - var cp = child_process.spawn(file, args, options); + if (options.nice) { + args = ['-n', options.nice, file].concat(args); + file = NICE; + } + + debug(tag + ' spawn: %s %s', file, args.join(' ')); + const cp = child_process.spawn(file, args, options); + if (options.logStream) { cp.stdout.pipe(options.logStream); cp.stderr.pipe(options.logStream);