3x-ui/web/job/check_xray_running_job.go

33 lines
613 B
Go
Raw Normal View History

2023-02-09 19:18:06 +00:00
package job
import (
2025-09-19 08:05:43 +00:00
"github.com/mhsanaei/3x-ui/v2/logger"
"github.com/mhsanaei/3x-ui/v2/web/service"
)
2023-02-09 19:18:06 +00:00
type CheckXrayRunningJob struct {
xrayService service.XrayService
checkTime int
}
func NewCheckXrayRunningJob() *CheckXrayRunningJob {
return new(CheckXrayRunningJob)
}
func (j *CheckXrayRunningJob) Run() {
if !j.xrayService.DidXrayCrash() {
2023-02-09 19:18:06 +00:00
j.checkTime = 0
} else {
j.checkTime++
// only restart if it's down 2 times in a row
if j.checkTime > 1 {
err := j.xrayService.RestartXray(false)
j.checkTime = 0
if err != nil {
logger.Error("Restart xray failed:", err)
}
}
2023-02-09 19:18:06 +00:00
}
}