linux版本中间件

main.cpp 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. #include <iostream>
  2. #include "Log.h"
  3. #include "FsProxy.h"
  4. #include "Config.h"
  5. #include "TimeScheduler.h"
  6. #include "TtsBaidu.h"
  7. #include "SqlWrite.h"
  8. #include "SoftAuth.h"
  9. #include <string>
  10. #ifdef WIN32
  11. //
  12. #else
  13. #include <sys/resource.h>
  14. #define CORE_SIZE 1024 * 1024 * 500
  15. #endif // WIN32
  16. void AuthFun()
  17. {
  18. bool isStop = false;
  19. while (!isStop)
  20. {
  21. std::this_thread::sleep_for(std::chrono::hours(1));
  22. if (!SoftAuth::GetInstance()->isExpire()) // 授权到期,关闭程序
  23. {
  24. LOG_WARN("授权到期,自动关闭程序!");
  25. isStop = true;
  26. CFsProxy::GetInstance().release();
  27. exit(EXIT_SUCCESS);
  28. }
  29. }
  30. }
  31. int main()
  32. {
  33. MYLog::instance()->Init("log4cpp.conf");
  34. LOG_INFO_S("程序开始启动...");
  35. struct rlimit crlmt;
  36. if (getrlimit(RLIMIT_CORE, &crlmt) == -1) {
  37. return -1;
  38. }
  39. //printf("Before set rlimit CORE dump current is:%d, max is:%d\n", (int)crlmt.rlim_cur, (int)crlmt.rlim_max);
  40. LOG_INFO("Before set rlimit CORE dump current is:%d, max is:%d\n", (int)crlmt.rlim_cur, (int)crlmt.rlim_max);
  41. crlmt.rlim_cur = (rlim_t)CORE_SIZE;
  42. crlmt.rlim_max = (rlim_t)CORE_SIZE;
  43. if (setrlimit(RLIMIT_CORE, &crlmt) == -1) {
  44. return -1;
  45. }
  46. if (getrlimit(RLIMIT_CORE, &crlmt) == -1) {
  47. return -1;
  48. }
  49. //printf("After set rlimit CORE dump current is:%d, max is:%d\n", (int)crlmt.rlim_cur, (int)crlmt.rlim_max);
  50. LOG_INFO("After set rlimit CORE dump current is:%d, max is:%d\n", (int)crlmt.rlim_cur, (int)crlmt.rlim_max);
  51. //if (!SoftAuth::GetInstance()->Auth())
  52. //{
  53. // std::cout << "该机器未授权,请授权后使用" << std::endl;
  54. // std::string hardc;
  55. // SoftAuth::GetInstance()->getMachineCode(hardc);
  56. // //std::cout << SoftAuth::GetInstance()->getMachineCode(hardc) << std::endl;
  57. // std::cout << "机器码:" << hardc << std::endl;
  58. // //SoftAuth::GetInstance()->MakeAuth(hardc);
  59. //
  60. // std::string code;// = "MWEyZGZmYzctYTVjNC00OWEwLTgxNTgtMTQ3YjNmYTA3Zjc4CjIwMjAwNzE2";
  61. // std::cout << "请输入授权码:" << std::endl;
  62. // std::cin >> code;
  63. // if (!SoftAuth::GetInstance()->Auth(code))
  64. // {
  65. // LOG_WARN("授权验证失败,自动关闭程序!");
  66. // CFsProxy::GetInstance().release();
  67. // //exit(EXIT_SUCCESS);
  68. // return 0;
  69. // }
  70. //}
  71. if (!SoftAuth::GetInstance()->AuthV2())
  72. {
  73. std::cout << "该机器未授权,请授权后使用" << std::endl;
  74. std::string hardc;
  75. if (!SoftAuth::GetInstance()->getMachineCode(hardc))
  76. {
  77. std::cout << "机器码获取失败,请用root权限运行!" << std::endl;
  78. return 0;
  79. }
  80. std::cout << "机器码:" << hardc << std::endl;
  81. std::string code;// = "MWEyZGZmYzctYTVjNC00OWEwLTgxNTgtMTQ3YjNmYTA3Zjc4CjIwMjAwNzE2";
  82. std::cout << "请输入授权码:" << std::endl;
  83. std::cin >> code;
  84. if (!SoftAuth::GetInstance()->AuthV2(code))
  85. {
  86. LOG_WARN("授权验证失败,自动关闭程序!");
  87. CFsProxy::GetInstance().release();
  88. //exit(EXIT_SUCCESS);
  89. return 0;
  90. }
  91. }
  92. AuthInfo aInfo;
  93. SoftAuth::GetInstance()->getAuthInfo(aInfo);
  94. LOG_INFO_S("授权到期时间:" + aInfo.data);
  95. LOG_INFO_S("授权中继数量:" + std::to_string(aInfo.trunkNum));
  96. LOG_INFO_S("授权坐席数量:" + std::to_string(aInfo.agentNum));
  97. if (!SoftAuth::GetInstance()->isExpire()) // 授权到期,关闭程序
  98. {
  99. LOG_WARN("授权到期,自动关闭程序!");
  100. return 0;
  101. }
  102. std::thread(std::bind(AuthFun)).detach();
  103. CConfig *cfg = CConfig::GetInstance();
  104. if (!cfg->load())
  105. {
  106. LOG_WARN_S("配置文件加载失败!");
  107. cfg->write();
  108. return 0;
  109. }
  110. if (CFsProxy::GetInstance().init())
  111. {
  112. LOG_INFO_S("程序初始化完成,开始运行...");
  113. CFsProxy::GetInstance().run();
  114. }
  115. else
  116. LOG_ERROR_S("程序初始化失败,程序即将关闭");
  117. CFsProxy::GetInstance().release();
  118. exit(EXIT_SUCCESS);
  119. return 0;
  120. }