From 6c51ba09bd98e30c3311a671a59b8f944afb0a13 Mon Sep 17 00:00:00 2001 From: eson <474420502@qq.com> Date: Sat, 22 Dec 2018 23:28:28 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0ppp2=E5=88=A4=E6=96=AD?= =?UTF-8?q?=E6=8F=92=E5=85=A5,=20=E5=BD=93=E5=87=BA=E7=8E=B0ppp2=E7=9A=84?= =?UTF-8?q?=E6=97=B6=E5=80=99,=20=E9=94=99=E8=AF=AF=E6=9E=81=E5=B0=91?= =?UTF-8?q?=E6=9C=89=E5=8F=AF=E8=83=BD=E6=8C=BD=E5=9B=9E=EF=BC=8C=20?= =?UTF-8?q?=E8=87=AA=E6=9D=80=E9=87=8D=E5=90=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dutiesnet.go | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) 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 }