Consolidate MangaCircus app, scraper, and Compose baseline
This commit is contained in:
1 parent
cfb2d79103
commit
eef4ffa07c
103 files changed
+9316
-172
No files matched your search
@@ -0,0 +1,23 @@
|
||||
#!/usr/bin/env node
|
||||
'use strict';
|
||||
|
||||
const fs = require('fs'), path = require('path');
|
||||
const { Supervisor } = require('../runtime/supervisor');
|
||||
const root = path.resolve(__dirname, '..');
|
||||
const lock = path.resolve(process.env.SCRAPER_DATA || path.join(process.env.DATA || path.join(root, 'data'), 'scraper'), 'supervisor.lock');
|
||||
fs.mkdirSync(path.dirname(lock), { recursive: true });
|
||||
if (fs.existsSync(lock)) {
|
||||
const pid = Number(fs.readFileSync(lock, 'utf8'));
|
||||
try { process.kill(pid, 0); throw new Error(`Supervisor already alive (PID ${pid})`); }
|
||||
catch (e) { if (e.code !== 'ESRCH') throw e; fs.unlinkSync(lock); }
|
||||
}
|
||||
fs.writeFileSync(lock, String(process.pid), { flag: 'wx' });
|
||||
const supervisors = ['reader', 'scraper', 'sentinel'].map(name => new Supervisor(name, { root }));
|
||||
supervisors.forEach(service => service.start());
|
||||
const keepalive = setInterval(() => {}, 60000);
|
||||
let closing = false;
|
||||
for (const signal of ['SIGINT', 'SIGTERM']) process.on(signal, async () => {
|
||||
if (closing) return; closing = true; clearInterval(keepalive);
|
||||
await Promise.all(supervisors.map(service => service.close()));
|
||||
fs.unlinkSync(lock); process.exit(0);
|
||||
});
|
||||
Reference in new issue
Block a user