mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2025-09-05 01:36:19 +00:00
Reduce outage time on Xray errors
This commit is contained in:
parent
78d3680ced
commit
4939474e89
3 changed files with 19 additions and 12 deletions
|
@ -1,6 +1,9 @@
|
|||
package job
|
||||
|
||||
import "x-ui/web/service"
|
||||
import (
|
||||
"x-ui/logger"
|
||||
"x-ui/web/service"
|
||||
)
|
||||
|
||||
type CheckXrayRunningJob struct {
|
||||
xrayService service.XrayService
|
||||
|
@ -15,11 +18,15 @@ func NewCheckXrayRunningJob() *CheckXrayRunningJob {
|
|||
func (j *CheckXrayRunningJob) Run() {
|
||||
if j.xrayService.IsXrayRunning() {
|
||||
j.checkTime = 0
|
||||
return
|
||||
} 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)
|
||||
}
|
||||
}
|
||||
}
|
||||
j.checkTime++
|
||||
if j.checkTime < 2 {
|
||||
return
|
||||
}
|
||||
j.xrayService.SetToNeedRestart()
|
||||
}
|
||||
|
|
|
@ -185,7 +185,7 @@ func (s *XrayService) RestartXray(isForce bool) error {
|
|||
return err
|
||||
}
|
||||
|
||||
if p != nil && p.IsRunning() {
|
||||
if s.IsXrayRunning() {
|
||||
if !isForce && p.GetConfig().Equals(xrayConfig) {
|
||||
logger.Debug("It does not need to restart xray")
|
||||
return nil
|
||||
|
|
|
@ -240,11 +240,11 @@ func (s *Server) startTask() {
|
|||
if err != nil {
|
||||
logger.Warning("start xray failed:", err)
|
||||
}
|
||||
// Check whether xray is running every 30 seconds
|
||||
s.cron.AddJob("@every 30s", job.NewCheckXrayRunningJob())
|
||||
// Check whether xray is running every second
|
||||
s.cron.AddJob("@every 1s", job.NewCheckXrayRunningJob())
|
||||
|
||||
// Check if xray needs to be restarted
|
||||
s.cron.AddFunc("@every 10s", func() {
|
||||
// Check if xray needs to be restarted every 30 seconds
|
||||
s.cron.AddFunc("@every 30s", func() {
|
||||
if s.xrayService.IsNeedRestartAndSetFalse() {
|
||||
err := s.xrayService.RestartXray(false)
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in a new issue