diff --git a/dutiesnet.go b/dutiesnet.go index bfde4fb..fe7f365 100644 --- a/dutiesnet.go +++ b/dutiesnet.go @@ -49,15 +49,15 @@ func (duties *DutiesNet) IsPPP0Up() bool { return true } -// IsPPP1Exist ppp1是否是UP的状态 -func (duties *DutiesNet) IsPPP1Exist() bool { +// IsPPPNExist ppp1是否是UP的状态 +func (duties *DutiesNet) IsPPPNExist(pppname string) bool { ifaces, err := net.Interfaces() if ErrorLog(err) { return false } for _, i := range ifaces { - if i.Name == "ppp1" { + if i.Name == pppname { return true } } @@ -97,7 +97,7 @@ func (duties *DutiesNet) SetRestart() { } func (duties *DutiesNet) checkError1() bool { - if duties.IsPPP1Exist() { + if duties.IsPPPNExist("ppp1") { log.Println("IsPPP1Exist not") duties.PPP0Restart() return true @@ -122,6 +122,16 @@ func (duties *DutiesNet) checkError2() bool { return false } +func (duties *DutiesNet) checkError3() bool { + if duties.IsPPPNExist("ppp2") { + log.Println("IsPPP2Exist not") + _, err := exec.Command("pkill", "pppoe_control").Output() + ErrorLog(err) + return true + } + return false // 检测错误才返回true 否则 false +} + //Duties 核心循环过程, 保证pppoe的网络可行 func (duties *DutiesNet) Duties() { for { @@ -138,6 +148,10 @@ func (duties *DutiesNet) Duties() { time.Sleep(time.Second * 1) atomic.AddInt64(&duties.CmdRestart, 1) // 重启因素的积累, 出一次错误就积累一次. 达到最大值后重启 + if duties.checkError3() { + continue + } + if duties.checkError1() { continue }