client.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. try {
  9. // 开机前做一次,清除确保环境干净(删除可能遗留的as程序)
  10. robot.closeAppAll()
  11. // 配置环境
  12. config.init()
  13. // 启动web
  14. web.init()
  15. // 定时任务
  16. interval.init()
  17. } catch (e) {
  18. logger.error(e.stack)
  19. logger.error(e)
  20. }
  21. //node关机前的一些操作
  22. // 当进程即将退出时执行一些操作
  23. process.on('exit', (code) => {
  24. logger.info(`即将退出,退出码:${code}`);
  25. logger.error(`即将退出,退出码2:${code}`);
  26. // 在这里执行清理工作
  27. });
  28. // 监听SIGINT信号(例如用户按下Ctrl+C)
  29. process.on('SIGINT', () => {
  30. logger.info('收到SIGINT信号,准备退出...');
  31. // 在这里执行清理工作
  32. process.exit(); // 这将触发exit事件
  33. });
  34. // 监听SIGTERM信号(通常是系统请求进程终止)
  35. process.on('SIGTERM', async () => {
  36. logger.info('收到SIGTERM信号,准备退出...');
  37. logger.error('收到SIGTERM信号,准备退出...2');
  38. logger.info('关机前的一些操作...');
  39. // 关机前为了防止 node 更新,需要吧map 里面的pid 写在本地文件
  40. await robot.closeAppAll()
  41. logger.info('自我关闭~~...');
  42. // 在这里执行清理工作
  43. process.exit(); // 这将触发exit事件
  44. });
  45. // 还可以处理未捕获的异常
  46. process.on('uncaughtException', (err) => {
  47. logger.error('捕获到未处理的异常:', err);
  48. logger.info('捕获到未处理的异常', err);
  49. // 在这里执行清理工作
  50. process.exit(1); // 非零退出码表示异常退出
  51. });