Skip to content

Commit 730612c

Browse files
authored
feat: fix StopOldInstance bug to check gateway ports before binding (#104)
1 parent 2f8d053 commit 730612c

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

main.go

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,41 @@ func main() {
6868
}
6969
beego.BConfig.WebConfig.Session.SessionGCMaxLifetime = 3600 * 24 * 365
7070

71-
service.Start()
72-
7371
port := beego.AppConfig.DefaultInt("httpport", 17000)
7472

75-
err := util.StopOldInstance(port)
73+
// Stop old instances on all ports before starting new services
74+
// Check gateway ports first since they bind first in service.Start()
75+
gatewayEnabled, err := beego.AppConfig.Bool("gatewayEnabled")
7676
if err != nil {
7777
panic(err)
7878
}
7979

80+
if gatewayEnabled {
81+
gatewayHttpPort, err := beego.AppConfig.Int("gatewayHttpPort")
82+
if err != nil {
83+
panic(err)
84+
}
85+
err = util.StopOldInstance(gatewayHttpPort)
86+
if err != nil {
87+
panic(err)
88+
}
89+
90+
gatewayHttpsPort, err := beego.AppConfig.Int("gatewayHttpsPort")
91+
if err != nil {
92+
panic(err)
93+
}
94+
err = util.StopOldInstance(gatewayHttpsPort)
95+
if err != nil {
96+
panic(err)
97+
}
98+
}
99+
100+
err = util.StopOldInstance(port)
101+
if err != nil {
102+
panic(err)
103+
}
104+
105+
service.Start()
106+
80107
beego.Run(fmt.Sprintf(":%v", port))
81108
}

0 commit comments

Comments
 (0)