完成网络音乐、工具页面与安装器体验升级
This commit is contained in:
+59
@@ -0,0 +1,59 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
'use strict';
|
||||
|
||||
const { once } = require('node:events');
|
||||
const { consturctServer } = require('./server');
|
||||
|
||||
const protocolVersion = 1;
|
||||
const commit = '4581660209c9cdd07669e8bd5bcbe136b7d91e02';
|
||||
const token = process.env.YMHUT_INTERNAL_TOKEN;
|
||||
const parentPid = Number(process.env.YMHUT_PARENT_PID || '0');
|
||||
|
||||
if (!token || token.length < 32 || !Number.isInteger(parentPid) || parentPid <= 0) {
|
||||
process.stderr.write('Invalid sidecar bootstrap environment.\n');
|
||||
process.exit(2);
|
||||
}
|
||||
|
||||
async function main() {
|
||||
const app = await consturctServer();
|
||||
const server = app.listen(0, '127.0.0.1');
|
||||
await once(server, 'listening');
|
||||
const address = server.address();
|
||||
if (!address || typeof address === 'string') throw new Error('Loopback listener did not expose a port.');
|
||||
|
||||
let stopping = false;
|
||||
const stop = () => {
|
||||
if (stopping) return;
|
||||
stopping = true;
|
||||
clearInterval(parentWatchdog);
|
||||
server.close(() => process.exit(0));
|
||||
setTimeout(() => process.exit(0), 1500).unref();
|
||||
};
|
||||
|
||||
app.once('ymhut-shutdown', stop);
|
||||
process.once('SIGINT', stop);
|
||||
process.once('SIGTERM', stop);
|
||||
|
||||
const parentWatchdog = setInterval(() => {
|
||||
try {
|
||||
process.kill(parentPid, 0);
|
||||
} catch {
|
||||
stop();
|
||||
}
|
||||
}, 2000);
|
||||
parentWatchdog.unref();
|
||||
|
||||
process.stdout.write(JSON.stringify({
|
||||
type: 'ready',
|
||||
protocolVersion,
|
||||
commit,
|
||||
pid: process.pid,
|
||||
port: address.port,
|
||||
}) + '\n');
|
||||
}
|
||||
|
||||
main().catch((error) => {
|
||||
process.stderr.write(`Sidecar startup failed: ${error && error.message ? error.message : 'unknown error'}\n`);
|
||||
process.exit(1);
|
||||
});
|
||||
Reference in New Issue
Block a user