Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
worker.on('online', co.wrap(function* () {
try {
// Set scheduling policy to SCHED_IDLE (`-i` flag);
// `0` is only possible value for priority ('cause this policy doesn't allow to set it)
yield execFile('chrt', [ '-i', '-p', '0', worker.process.pid ]);
} catch (__) {
// If `chrt` not exists, try fallback to `renice`.
try {
yield execFile('renice', [ '-n', '19', '-p', worker.process.pid ]);
log.warn('Cannot set scheduling policy for queue using `chrt`, falling back to `renice`');
} catch (___) {
log.error('Cannot lower priority for queue ' +
'(both `renice` and `chrt` have failed), continuing with default priority');
}
}
}));
const darwinFindGroupDetails = (context, nameOrId) => {
// in dscl, everything is a string
nameOrId = `${nameOrId}`
return execFile('dscl', ['-plist', '.', 'readall', '/groups', 'PrimaryGroupID', 'RecordName', 'GroupMembership'])
.then(([stdout]) => plist.parse(stdout))
.then(groups => groups.filter(group => plistValue(group, 'dsAttrTypeStandard:PrimaryGroupID') === nameOrId))
.then(groups => groups.pop())
.then(group => {
return {
name: plistValue(group, 'dsAttrTypeStandard:RecordName'),
gid: parseInt(plistValue(group, 'dsAttrTypeStandard:PrimaryGroupID'), 10),
members: group['dsAttrTypeStandard:GroupMembership']
}
})
}
.then(pk12util => {
logger.debug('Installing certificate')
logger.debug(pk12util, '-i', p12Path, '-d', profileDirectory, '-W', password)
return execFile(pk12util, ['-i', p12Path, '-d', profileDirectory, '-W', password])
})
}
async function run(command: string, args: Array): Promise<{ stdout: string, stderr: string }> {
let [ stdout, stderr ] = await execFile(command, args);
return { stdout, stderr };
}
async function getOutput(command: string, ...args: string[]) {
const [stdout] = await execFile(command, args);
return stdout;
}
const getOs = (context) => {
if (!promise) {
promise = execFile('uname', ['-a'])
.then(result => {
const stdout = result[0].toLowerCase()
if (stdout.indexOf('centos') !== -1) {
return 'centos'
} else if (stdout.indexOf('darwin') !== -1) {
return 'darwin'
} else if (stdout.indexOf('debian') !== -1) {
return 'debian'
} else if (stdout.indexOf('fedora') !== -1) {
return 'fedora'
} else if (stdout.indexOf('freebsd') !== -1) {
return 'freebsd'
} else if (stdout.indexOf('mint') !== -1) {
return 'mint'
} else if (stdout.indexOf('netbsd') !== -1) {
const launchdStopProcess = (context, name) => {
const plist = path.join(config.PLIST_LOCATIONS, `${config.DAEMON_NAME}.${name}.plist`)
context.log([DEBUG, CONTEXT], `running launchctl unload -w ${plist}`)
return execFile(config.LAUNCHCTL_PATH, ['unload', '-w', plist])
.then(([stdout, stderr]) => {
if (stdout) {
context.log([DEBUG, CONTEXT], stdout.trim())
}
if (stderr) {
context.log([WARN, CONTEXT], stderr.trim())
}
return operations.findProcess(context, name)
})
}
async function run(command: string, args: Array): Promise<{ stdout: string; stderr: string }> {
const [stdout, stderr] = await execFile(command, args);
return { stdout, stderr };
}