client.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. const web = require('./src/web')
  2. const config = require('./src/config')
  3. const interval = require('./src/Interval')
  4. const robot = require('./src/robot')
  5. const {getRustConfig} = require("./src/config");
  6. const {logger} = require("./src/utils/logger");
  7. const {exec} = require("child_process");
  8. config.init()
  9. // 启动web
  10. web.init()
  11. // 定时任务
  12. interval.init()
  13. //node关机前的一些操作
  14. // 当进程即将退出时执行一些操作
  15. process.on('exit', (code) => {
  16. console.log(`即将退出,退出码:${code}`);
  17. // 在这里执行清理工作
  18. });
  19. // 监听SIGINT信号(例如用户按下Ctrl+C)
  20. process.on('SIGINT', () => {
  21. console.log('收到SIGINT信号,准备退出...');
  22. // 在这里执行清理工作
  23. process.exit(); // 这将触发exit事件
  24. });
  25. // 监听SIGTERM信号(通常是系统请求进程终止)
  26. process.on('SIGTERM', async () => {
  27. console.log('收到SIGTERM信号,准备退出...');
  28. // 关机前为了防止 node 更新,需要吧map 里面的pid 写在本地文件
  29. await robot.closeAppAll()
  30. // 在这里执行清理工作
  31. process.exit(); // 这将触发exit事件
  32. });
  33. // 还可以处理未捕获的异常
  34. process.on('uncaughtException', (err) => {
  35. console.error('捕获到未处理的异常:', err);
  36. // 在这里执行清理工作
  37. process.exit(1); // 非零退出码表示异常退出
  38. });