check_xray_running_job.go 565 B

1234567891011121314151617181920212223242526272829303132
  1. package job
  2. import (
  3. "x-ui/logger"
  4. "x-ui/web/service"
  5. )
  6. type CheckXrayRunningJob struct {
  7. xrayService service.XrayService
  8. checkTime int
  9. }
  10. func NewCheckXrayRunningJob() *CheckXrayRunningJob {
  11. return new(CheckXrayRunningJob)
  12. }
  13. func (j *CheckXrayRunningJob) Run() {
  14. if j.xrayService.IsXrayRunning() {
  15. j.checkTime = 0
  16. } else {
  17. j.checkTime++
  18. // only restart if it's down 2 times in a row
  19. if j.checkTime > 1 {
  20. err := j.xrayService.RestartXray(false)
  21. j.checkTime = 0
  22. if err != nil {
  23. logger.Error("Restart xray failed:", err)
  24. }
  25. }
  26. }
  27. }