Skip to content

Commit

Permalink
run without service ehang-io#407
Browse files Browse the repository at this point in the history
  • Loading branch information
ffdfgdfg committed Feb 18, 2020
1 parent ae3dde5 commit 29819e0
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 20 deletions.
24 changes: 17 additions & 7 deletions cmd/npc/npc.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"os"
"runtime"
"strings"
"sync"
"time"
)

Expand Down Expand Up @@ -107,7 +108,12 @@ func main() {
}
s, err := service.New(prg, svcConfig)
if err != nil {
logs.Error(err)
logs.Error(err, "service function disabled")
run()
// run without service
wg := sync.WaitGroup{}
wg.Add(1)
wg.Wait()
return
}
if len(os.Args) >= 2 {
Expand Down Expand Up @@ -172,6 +178,15 @@ func (p *npc) run() error {
logs.Warning("npc: panic serving %v: %v\n%s", err, string(buf))
}
}()
run()
select {
case <-p.exit:
logs.Warning("stop...")
}
return nil
}

func run() {
common.InitPProfFromArg(*pprofAddr)
//p2p or secret command
if *password != "" {
Expand All @@ -187,7 +202,7 @@ func (p *npc) run() error {
commonConfig.Client = new(file.Client)
commonConfig.Client.Cnf = new(file.Config)
go client.StartLocalServer(localServer, commonConfig)
return nil
return
}
env := common.GetEnvMap()
if *serverAddr == "" {
Expand All @@ -211,9 +226,4 @@ func (p *npc) run() error {
}
go client.StartFromFile(*configPath)
}
select {
case <-p.exit:
logs.Warning("stop...")
}
return nil
}
36 changes: 23 additions & 13 deletions cmd/nps/nps.go
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
package main

import (
"ehang.io/nps/lib/crypt"
"ehang.io/nps/lib/file"
"ehang.io/nps/lib/install"
"ehang.io/nps/lib/version"
"ehang.io/nps/server"
"ehang.io/nps/server/connection"
"ehang.io/nps/server/tool"
"ehang.io/nps/web/routers"
"flag"
"log"
"os"
"path/filepath"
"runtime"
"strings"
"sync"

"ehang.io/nps/lib/common"
"ehang.io/nps/lib/crypt"
"ehang.io/nps/lib/daemon"
"ehang.io/nps/lib/file"
"ehang.io/nps/lib/version"
"ehang.io/nps/server"
"ehang.io/nps/server/connection"
"ehang.io/nps/server/tool"
"github.com/astaxie/beego"
"github.com/astaxie/beego/logs"

"ehang.io/nps/web/routers"
"github.com/kardianos/service"
)

Expand Down Expand Up @@ -97,7 +98,12 @@ func main() {
prg.exit = make(chan struct{})
s, err := service.New(prg, svcConfig)
if err != nil {
logs.Error(err)
logs.Error(err, "service function disabled")
run()
// run without service
wg := sync.WaitGroup{}
wg.Add(1)
wg.Wait()
return
}
if len(os.Args) > 1 && os.Args[1] != "service" {
Expand Down Expand Up @@ -166,6 +172,15 @@ func (p *nps) run() error {
logs.Warning("nps: panic serving %v: %v\n%s", err, string(buf))
}
}()
run()
select {
case <-p.exit:
logs.Warning("stop...")
}
return nil
}

func run() {
routers.Init()
task := &file.Tunnel{
Mode: "webServer",
Expand All @@ -181,9 +196,4 @@ func (p *nps) run() error {
tool.InitAllowPort()
tool.StartSystemInfo()
go server.StartNewServer(bridgePort, task, beego.AppConfig.String("bridge_type"))
select {
case <-p.exit:
logs.Warning("stop...")
}
return nil
}

0 comments on commit 29819e0

Please # to comment.