nps.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package main
  2. import (
  3. "flag"
  4. "github.com/cnlh/nps/lib/common"
  5. "github.com/cnlh/nps/lib/daemon"
  6. "github.com/cnlh/nps/lib/file"
  7. "github.com/cnlh/nps/lib/install"
  8. "github.com/cnlh/nps/lib/lg"
  9. "github.com/cnlh/nps/server"
  10. "github.com/cnlh/nps/server/test"
  11. "github.com/cnlh/nps/vender/github.com/astaxie/beego"
  12. _ "github.com/cnlh/nps/web/routers"
  13. "log"
  14. "net/http"
  15. _ "net/http/pprof"
  16. "os"
  17. "path/filepath"
  18. )
  19. const VERSION = "v0.0.15"
  20. var (
  21. logType = flag.String("log", "stdout", "Log output mode(stdout|file)")
  22. )
  23. func main() {
  24. log.SetFlags(log.Lshortfile)
  25. flag.Parse()
  26. if len(os.Args) > 1 {
  27. switch os.Args[1] {
  28. case "test":
  29. test.TestServerConfig()
  30. log.Println("test ok, no error")
  31. return
  32. case "start", "restart", "stop", "status":
  33. daemon.InitDaemon("nps", common.GetRunPath(), common.GetTmpPath())
  34. case "install":
  35. install.InstallNps()
  36. return
  37. }
  38. }
  39. go func() {
  40. http.ListenAndServe("0.0.0.0:8899", nil)
  41. }()
  42. if *logType == "stdout" {
  43. lg.InitLogFile("nps", true, common.GetLogPath())
  44. } else {
  45. lg.InitLogFile("nps", false, common.GetLogPath())
  46. }
  47. task := &file.Tunnel{
  48. Mode: "webServer",
  49. }
  50. bridgePort, err := beego.AppConfig.Int("bridgePort")
  51. if err != nil {
  52. lg.Fatalln("Getting bridgePort error", err)
  53. }
  54. beego.LoadAppConfig("ini", filepath.Join(common.GetRunPath(), "conf", "app.conf"))
  55. server.StartNewServer(bridgePort, task, beego.AppConfig.String("bridgeType"))
  56. }