20 lines
1.0 KiB
JavaScript
20 lines
1.0 KiB
JavaScript
// User-unit entry point: validate config and both pinned assets before executing anything.
|
|
import { spawnSync } from 'node:child_process';
|
|
import path from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
import { startVerifiedProxy } from './runner.mjs';
|
|
const repo = fileURLToPath(new URL('../../../', import.meta.url));
|
|
try {
|
|
const result = spawnSync(process.execPath, [path.join(repo, 'scripts/mosaic-config.mjs'), 'validate'], { encoding: 'utf8', env: process.env });
|
|
if (result.status !== 0) throw Error('proxy-config-invalid');
|
|
const config = JSON.parse(result.stdout);
|
|
const child = startVerifiedProxy(config, {
|
|
onError: code => { process.stderr.write(code + '\n'); process.exitCode = 3; },
|
|
onExit: code => { process.exitCode = code; },
|
|
});
|
|
for (const signal of ['SIGTERM', 'SIGINT']) process.on(signal, () => child.kill(signal));
|
|
} catch (e) {
|
|
process.stderr.write((/^proxy-[a-z-]+$/.test(e.code ?? e.message) ? (e.code ?? e.message) : 'proxy-start-failed') + '\n');
|
|
process.exitCode = 3;
|
|
}
|