mirror of
https://github.com/zoriya/flood.git
synced 2025-12-06 07:16:18 +00:00
config.cli: store PID of managed rTorrent process
This commit is contained in:
@@ -146,10 +146,28 @@ const {argv} = require('yargs')
|
||||
hidden: true,
|
||||
type: 'string',
|
||||
})
|
||||
.option('test', {
|
||||
default: false,
|
||||
describe: 'DEV ONLY: Test setup',
|
||||
hidden: true,
|
||||
type: 'boolean',
|
||||
})
|
||||
.version(require('./package.json').version)
|
||||
.alias('v', 'version')
|
||||
.help();
|
||||
|
||||
process.on('SIGINT', () => {
|
||||
process.exit();
|
||||
});
|
||||
|
||||
try {
|
||||
fs.mkdirSync(path.join(argv.rundir, 'db'), {recursive: true});
|
||||
fs.mkdirSync(path.join(argv.rundir, 'temp'), {recursive: true});
|
||||
} catch (error) {
|
||||
console.error('Failed to access runtime directory');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
if (argv.rtorrent) {
|
||||
const args = [];
|
||||
let opts = 'system.daemon.set=true';
|
||||
@@ -161,12 +179,16 @@ if (argv.rtorrent) {
|
||||
|
||||
const rTorrentProcess = spawn('rtorrent', args.concat(['-o', opts]), {stdio: 'inherit'});
|
||||
|
||||
rTorrentProcess.on('close', () => {
|
||||
process.exit(1);
|
||||
});
|
||||
rTorrentProcess.on('error', () => {
|
||||
process.exit(1);
|
||||
});
|
||||
fs.writeFileSync(path.join(argv.rundir, 'rtorrent.pid'), `${rTorrentProcess.pid}`);
|
||||
|
||||
if (!argv.test) {
|
||||
rTorrentProcess.on('close', () => {
|
||||
process.exit(1);
|
||||
});
|
||||
rTorrentProcess.on('error', () => {
|
||||
process.exit(1);
|
||||
});
|
||||
}
|
||||
|
||||
process.on('exit', () => {
|
||||
console.log('Killing rTorrent daemon...');
|
||||
@@ -174,18 +196,6 @@ if (argv.rtorrent) {
|
||||
});
|
||||
}
|
||||
|
||||
process.on('SIGINT', () => {
|
||||
process.exit();
|
||||
});
|
||||
|
||||
try {
|
||||
fs.mkdirSync(path.join(argv.rundir, 'db'), {recursive: true});
|
||||
fs.mkdirSync(path.join(argv.rundir, 'temp'), {recursive: true});
|
||||
} catch (error) {
|
||||
console.error('Failed to access runtime directory');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const DEFAULT_SECRET_PATH = path.join(argv.rundir, 'flood.secret');
|
||||
let secret;
|
||||
|
||||
|
||||
@@ -26,8 +26,10 @@ process.argv.push('--rtsocket', rTorrentSocket);
|
||||
process.argv.push('--allowedpath', temporaryRuntimeDirectory);
|
||||
process.argv.push('--rtorrent');
|
||||
process.argv.push('--rtconfig', `${temporaryRuntimeDirectory}/rtorrent.rc`);
|
||||
process.argv.push('--test');
|
||||
|
||||
afterAll((done) => {
|
||||
process.kill(Number(fs.readFileSync(`${temporaryRuntimeDirectory}/rtorrent.pid`).toString()));
|
||||
if (process.env.CI !== 'true') {
|
||||
// TODO: This leads to test flakiness caused by ENOENT error
|
||||
// NeDB provides no method to close database connection
|
||||
|
||||
Reference in New Issue
Block a user