worker.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace app\admin;
  3. class worker extends Base
  4. {
  5. public $workerlog = IN_TMP_PATH . "worker/worker.log";
  6. public $worker_statuslog = IN_TMP_PATH . "worker/worker_status.log";
  7. function initialize()
  8. {
  9. parent::initialize();
  10. @creatdir(IN_TMP_PATH . "worker/");
  11. }
  12. function index()
  13. {
  14. if (in_array($this->action, ["start", "restart", "stop"])) {
  15. exec("php worker.php " . $this->action . " -d", $_var_0);
  16. $_var_0 = json_encode($_var_0);
  17. if ($this->action == "start") {
  18. @file_put_contents($this->workerlog, "");
  19. @file_put_contents($this->worker_statuslog, 1);
  20. if (strstr($_var_0, "Start success")) {
  21. return reJSON("签名服务启动成功", 1);
  22. }
  23. if (strstr($_var_0, "already running")) {
  24. return reJSON("签名服务已经启动了,请勿重复", 1);
  25. }
  26. return reJSON("启动失败", 0);
  27. } elseif ($this->action == "restart") {
  28. @file_put_contents($this->workerlog, "");
  29. @file_put_contents($this->worker_statuslog, 1);
  30. if (strstr($_var_0, "Start success")) {
  31. return reJSON("签名服务重启成功", 1);
  32. }
  33. return reJSON("重启失败", 0);
  34. } elseif ($this->action == "stop") {
  35. @file_put_contents($this->worker_statuslog, 0);
  36. if (strstr($_var_0, "stop success")) {
  37. return reJSON("签名服务停止成功", 0);
  38. }
  39. if (strstr($_var_0, "not run")) {
  40. return reJSON("签名服务已经是停止状态了", 0);
  41. }
  42. return reJSON("停止失败", 0);
  43. }
  44. } else {
  45. if ($this->action == "logs") {
  46. $_var_1 = @file_get_contents($this->workerlog);
  47. $_var_1 = str_replace("\n", "<br>", $_var_1 ?: "暂无日志");
  48. return reJSON($_var_1, $this->workerlog);
  49. }
  50. }
  51. $_var_1 = @file_get_contents($this->worker_statuslog);
  52. return reJSON($_var_1);
  53. }
  54. }