Skip to content

Commit

Permalink
hot reload
Browse files Browse the repository at this point in the history
  • Loading branch information
刘河 committed Mar 26, 2019
1 parent 8fa3e8f commit 5beee73
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
12 changes: 1 addition & 11 deletions cmd/nps/nps.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ import (
_ "github.com/cnlh/nps/web/routers"
"log"
"os"
"os/signal"
"path/filepath"
"syscall"
)

var (
Expand All @@ -36,7 +34,7 @@ func main() {
test.TestServerConfig()
log.Println("test ok, no error")
return
case "start", "restart", "stop", "status","reload":
case "start", "restart", "stop", "status", "reload":
daemon.InitDaemon("nps", common.GetRunPath(), common.GetTmpPath())
case "install":
install.InstallNps()
Expand Down Expand Up @@ -66,13 +64,5 @@ func main() {
connection.InitConnectionService()
crypt.InitTls(filepath.Join(beego.AppPath, "conf", "server.pem"), filepath.Join(beego.AppPath, "conf", "server.key"))
tool.InitAllowPort()
s := make(chan os.Signal, 1)
signal.Notify(s, syscall.SIGUSR1)
go func() {
for {
<-s
beego.LoadAppConfig("ini", filepath.Join(common.GetRunPath(), "conf", "nps.conf"))
}
}()
server.StartNewServer(bridgePort, task, beego.AppConfig.String("bridge_type"))
}
23 changes: 23 additions & 0 deletions lib/daemon/reload.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// +build !windows

package daemon

import (
"github.com/cnlh/nps/lib/common"
"github.com/cnlh/nps/vender/github.com/astaxie/beego"
"os"
"os/signal"
"path/filepath"
"syscall"
)

func init() {
s := make(chan os.Signal, 1)
signal.Notify(s, syscall.SIGUSR1)
go func() {
for {
<-s
beego.LoadAppConfig("ini", filepath.Join(common.GetRunPath(), "conf", "nps.conf"))
}
}()
}

0 comments on commit 5beee73

Please sign in to comment.