64 lines
1.8 KiB
JavaScript
64 lines
1.8 KiB
JavaScript
import { bootstrapMindSpaceService } from './mindspace-service-bootstrap.mjs';
|
|
import { startMindSpaceRpcServer } from './mindspace-rpc-server.mjs';
|
|
import fs from 'node:fs/promises';
|
|
import path from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
|
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
|
|
const logger = console;
|
|
|
|
async function readBuildInfo() {
|
|
try {
|
|
const raw = await fs.readFile(
|
|
path.join(__dirname, 'build-info.json'),
|
|
'utf8',
|
|
);
|
|
return JSON.parse(raw);
|
|
} catch {
|
|
return {};
|
|
}
|
|
}
|
|
|
|
async function main() {
|
|
const buildInfo = await readBuildInfo();
|
|
const service = await bootstrapMindSpaceService({ env: process.env, logger });
|
|
const rpc = await startMindSpaceRpcServer({
|
|
adapter: service.adapter,
|
|
env: process.env,
|
|
logger,
|
|
serviceMeta: {
|
|
operationBasePath: service.runtime.remote.operationBasePath,
|
|
buildId: buildInfo.buildId,
|
|
gitSha: buildInfo.gitSha,
|
|
builtAt: buildInfo.builtAt,
|
|
},
|
|
});
|
|
|
|
logger.log(
|
|
`MindSpace service listening on http://${rpc.host}:${rpc.port}${service.runtime.remote.operationBasePath}`,
|
|
);
|
|
logger.log(`Memind root: ${service.memindRoot}`);
|
|
logger.log(`Standalone data root: ${service.standaloneDataRoot}`);
|
|
logger.log(`Standalone agent worker: ${service.backgroundJobs.agentWorker ? 'enabled' : 'disabled'}`);
|
|
|
|
const shutdown = async (signal) => {
|
|
logger.log(`Received ${signal}, shutting down MindSpace service...`);
|
|
await rpc.close().catch(() => {});
|
|
await service.close().catch(() => {});
|
|
process.exit(0);
|
|
};
|
|
|
|
process.on('SIGINT', () => {
|
|
void shutdown('SIGINT');
|
|
});
|
|
process.on('SIGTERM', () => {
|
|
void shutdown('SIGTERM');
|
|
});
|
|
}
|
|
|
|
main().catch((error) => {
|
|
console.error('MindSpace service failed to start:', error);
|
|
process.exit(1);
|
|
});
|