mirror of
https://github.com/ehang-io/nps.git
synced 2025-07-03 04:53:50 +00:00
nps some config hot reload
This commit is contained in:
parent
7edc65cfde
commit
65e0822b63
@ -17,7 +17,9 @@ import (
|
|||||||
_ "github.com/cnlh/nps/web/routers"
|
_ "github.com/cnlh/nps/web/routers"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
"os/signal"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"syscall"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -34,7 +36,7 @@ func main() {
|
|||||||
test.TestServerConfig()
|
test.TestServerConfig()
|
||||||
log.Println("test ok, no error")
|
log.Println("test ok, no error")
|
||||||
return
|
return
|
||||||
case "start", "restart", "stop", "status":
|
case "start", "restart", "stop", "status","reload":
|
||||||
daemon.InitDaemon("nps", common.GetRunPath(), common.GetTmpPath())
|
daemon.InitDaemon("nps", common.GetRunPath(), common.GetTmpPath())
|
||||||
case "install":
|
case "install":
|
||||||
install.InstallNps()
|
install.InstallNps()
|
||||||
@ -64,5 +66,13 @@ func main() {
|
|||||||
connection.InitConnectionService()
|
connection.InitConnectionService()
|
||||||
crypt.InitTls(filepath.Join(beego.AppPath, "conf", "server.pem"), filepath.Join(beego.AppPath, "conf", "server.key"))
|
crypt.InitTls(filepath.Join(beego.AppPath, "conf", "server.pem"), filepath.Join(beego.AppPath, "conf", "server.key"))
|
||||||
tool.InitAllowPort()
|
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"))
|
server.StartNewServer(bridgePort, task, beego.AppConfig.String("bridge_type"))
|
||||||
}
|
}
|
||||||
|
@ -47,4 +47,5 @@ auth_crypt_key =1234567812345678
|
|||||||
|
|
||||||
#allow_ports=9001-9009,10001,11000-12000
|
#allow_ports=9001-9009,10001,11000-12000
|
||||||
|
|
||||||
|
#Web management multi-user login
|
||||||
#allow_user_login=true
|
#allow_user_login=true
|
||||||
|
@ -24,21 +24,40 @@ func InitDaemon(f string, runPath string, pidPath string) {
|
|||||||
switch os.Args[1] {
|
switch os.Args[1] {
|
||||||
case "start":
|
case "start":
|
||||||
start(args, f, pidPath, runPath)
|
start(args, f, pidPath, runPath)
|
||||||
os.Exit(0)
|
|
||||||
case "stop":
|
case "stop":
|
||||||
stop(f, args[0], pidPath)
|
stop(f, args[0], pidPath)
|
||||||
os.Exit(0)
|
|
||||||
case "restart":
|
case "restart":
|
||||||
stop(f, args[0], pidPath)
|
stop(f, args[0], pidPath)
|
||||||
start(args, f, pidPath, runPath)
|
start(args, f, pidPath, runPath)
|
||||||
os.Exit(0)
|
|
||||||
case "status":
|
case "status":
|
||||||
if status(f, pidPath) {
|
if status(f, pidPath) {
|
||||||
log.Printf("%s is running", f)
|
log.Printf("%s is running", f)
|
||||||
} else {
|
} else {
|
||||||
log.Printf("%s is not running", f)
|
log.Printf("%s is not running", f)
|
||||||
}
|
}
|
||||||
os.Exit(0)
|
case "reload":
|
||||||
|
reload(f, pidPath)
|
||||||
|
}
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
func reload(f string, pidPath string) {
|
||||||
|
if f == "nps" && !common.IsWindows() && !status(f, pidPath) {
|
||||||
|
log.Println("reload fail")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var c *exec.Cmd
|
||||||
|
var err error
|
||||||
|
b, err := ioutil.ReadFile(filepath.Join(pidPath, f+".pid"))
|
||||||
|
if err == nil {
|
||||||
|
c = exec.Command("/bin/bash", "-c", `kill -30 `+string(b))
|
||||||
|
} else {
|
||||||
|
log.Fatalln("reload error,pid file does not exist")
|
||||||
|
}
|
||||||
|
if c.Run() == nil {
|
||||||
|
log.Println("reload success")
|
||||||
|
} else {
|
||||||
|
log.Println("reload fail")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,7 +145,7 @@ func (s *BaseController) CheckUserAuth() {
|
|||||||
if s.controllerName == "index" {
|
if s.controllerName == "index" {
|
||||||
if id := s.GetIntNoErr("id"); id != 0 {
|
if id := s.GetIntNoErr("id"); id != 0 {
|
||||||
belong := false
|
belong := false
|
||||||
if strings.Contains(s.actionName, "H") {
|
if strings.Contains(s.actionName, "h") {
|
||||||
if v, ok := file.GetCsvDb().Hosts.Load(id); ok {
|
if v, ok := file.GetCsvDb().Hosts.Load(id); ok {
|
||||||
if v.(*file.Host).Client.Id == s.GetSession("clientId").(int) {
|
if v.(*file.Host).Client.Id == s.GetSession("clientId").(int) {
|
||||||
belong = true
|
belong = true
|
||||||
|
Loading…
x
Reference in New Issue
Block a user