start-relay-client.js 931 B

12345678910111213141516171819202122232425262728293031
  1. #!/usr/bin/env node
  2. 'use strict';
  3. const path = require('path');
  4. const { pathToFileURL } = require('url');
  5. async function main() {
  6. const moduleUrl = pathToFileURL(path.join(__dirname, '..', 'runtime', 'callback-service', 'src', 'index.mjs')).href;
  7. const { startRuntime } = await import(moduleUrl);
  8. const runtime = await startRuntime({
  9. forceMode: 'enterprise',
  10. guid: process.argv[2] || '',
  11. dashboard: false,
  12. });
  13. process.stdout.write(`[RelayClient] ESM runtime started. pid=${process.pid}, mode=${runtime.mode}\n`);
  14. let shuttingDown = false;
  15. const shutdown = signal => {
  16. if (shuttingDown) return;
  17. shuttingDown = true;
  18. runtime.stop(signal).finally(() => process.exit(0));
  19. };
  20. process.once('SIGINT', () => shutdown('SIGINT'));
  21. process.once('SIGTERM', () => shutdown('SIGTERM'));
  22. }
  23. main().catch(error => {
  24. process.stderr.write(`[RelayClient] ${error.message}\n`);
  25. process.exit(1);
  26. });