cross.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. "use strict";
  2. const { Service } = require("ee-core");
  3. const Cross = require("ee-core/cross");
  4. const Log = require("ee-core/log");
  5. const Ps = require("ee-core/ps");
  6. const path = require("path");
  7. const Is = require("ee-core/utils/is");
  8. /**
  9. * cross(service层为单例)
  10. * @class
  11. */
  12. class CrossService extends Service {
  13. constructor(ctx) {
  14. super(ctx);
  15. }
  16. /**
  17. * create go service
  18. * In the default configuration, services can be started with applications.
  19. * Developers can turn off the configuration and create it manually.
  20. */
  21. async createGoServer() {
  22. // method 1: Use the default Settings
  23. //const entity = await Cross.run(serviceName);
  24. // method 2: Use custom configuration
  25. const serviceName = "go";
  26. const opt = {
  27. name: "goapp",
  28. cmd: path.join(Ps.getExtraResourcesDir(), "goapp"),
  29. directory: Ps.getExtraResourcesDir(),
  30. args: ["--port=7073"],
  31. appExit: true,
  32. };
  33. const entity = await Cross.run(serviceName, opt);
  34. Log.info("server name:", entity.name);
  35. Log.info("server config:", entity.config);
  36. Log.info("server url:", entity.getUrl());
  37. return;
  38. }
  39. /**
  40. * create java server
  41. */
  42. async createJavaServer() {
  43. const serviceName = "java";
  44. const jarPath = path.join(Ps.getExtraResourcesDir(), "java-app.jar");
  45. const opt = {
  46. name: "javaapp",
  47. cmd: path.join(Ps.getExtraResourcesDir(), "jre1.8.0_201/bin/javaw.exe"),
  48. directory: Ps.getExtraResourcesDir(),
  49. args: [
  50. "-jar",
  51. "-server",
  52. "-Xms512M",
  53. "-Xmx512M",
  54. "-Xss512k",
  55. "-Dspring.profiles.active=prod",
  56. `-Dserver.port=18080`,
  57. `-Dlogging.file.path=${Ps.getLogDir()}`,
  58. `${jarPath}`,
  59. ],
  60. appExit: false,
  61. };
  62. if (Is.macOS()) {
  63. // Setup Java program
  64. opt.cmd = path.join(
  65. Ps.getExtraResourcesDir(),
  66. "jre1.8.0_201.jre/Contents/Home/bin/java"
  67. );
  68. }
  69. if (Is.linux()) {
  70. // Setup Java program
  71. }
  72. const entity = await Cross.run(serviceName, opt);
  73. Log.info("server name:", entity.name);
  74. Log.info("server config:", entity.config);
  75. Log.info("server url:", Cross.getUrl(entity.name));
  76. return;
  77. }
  78. /**
  79. * create python service
  80. * In the default configuration, services can be started with applications.
  81. * Developers can turn off the configuration and create it manually.
  82. */
  83. async createPythonServer() {
  84. // method 1: Use the default Settings
  85. //const entity = await Cross.run(serviceName);
  86. // method 2: Use custom configuration
  87. const serviceName = "python";
  88. const opt = {
  89. name: "pyapp",
  90. cmd: path.join(Ps.getExtraResourcesDir(), "py", "pyapp"),
  91. directory: path.join(Ps.getExtraResourcesDir(), "py"),
  92. args: ["--port=7074"],
  93. windowsExtname: true,
  94. appExit: true,
  95. };
  96. const entity = await Cross.run(serviceName, opt);
  97. Log.info("server name:", entity.name);
  98. Log.info("server config:", entity.config);
  99. Log.info("server url:", entity.getUrl());
  100. return;
  101. }
  102. }
  103. CrossService.toString = () => "[class CrossService]";
  104. module.exports = CrossService;