#!/usr/bin/env node // pithos-hosted entry: node hosted/main.js --config /etc/pithos-hosted.json import fs from 'node:fs'; import { createHosted } from './server.js'; const DEFAULTS = { listen: '127.0.0.1:8720', publicUrl: 'https://s3.silentmode.st', root: '/var/lib/pithos-hosted', s3dBinary: null, portBase: 21000, maxRunning: 30, idleMinutes: 30, bufferLimitBytes: 2 * 1024 ** 3, maxDataBytes: 4 * 1024 ** 3, downloadCapBytes: 50 * 1024 ** 3, trustProxy: false, gate: { bns: { api: 'https://navigate.st' }, deposit: null, invites: [], perIpPerDay: 3 }, }; const i = process.argv.indexOf('--config'); const file = i > 0 ? process.argv[i + 1] : process.env.PITHOS_HOSTED_CONFIG; if (!file) { console.error('usage: pithos-hosted --config '); process.exit(2); } const cfg = { ...DEFAULTS, ...JSON.parse(fs.readFileSync(file, 'utf8')) }; if (!cfg.s3dBinary || !fs.existsSync(cfg.s3dBinary)) { console.error(`s3dBinary not found: ${cfg.s3dBinary}`); process.exit(2); } cfg.publicUrl = cfg.publicUrl.replace(/\/$/, ''); const hosted = await createHosted(cfg); let stopping = false; for (const sig of ['SIGTERM', 'SIGINT']) { process.on(sig, async () => { if (stopping) return; stopping = true; console.log(`${sig}: flushing and stopping every s3d`); await hosted.close().catch((e) => console.error(e)); process.exit(0); }); }