MCPcopy Index your code
hub / github.com/GoEdgeLab/EdgeNode / main

Function main

cmd/edge-node/main.go:30–567  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

28)
29
30func main() {
31 var app = apps.NewAppCmd().
32 Version(teaconst.Version).
33 Product(teaconst.ProductName).
34 Usage(teaconst.ProcessName + " [-v|start|stop|restart|status|quit|test|reload|service|daemon|config|pprof|accesslog|uninstall]").
35 Usage(teaconst.ProcessName + " [trackers|goman|conns|gc|bandwidth|disk|cache.garbage]").
36 Usage(teaconst.ProcessName + " [ip.drop|ip.reject|ip.remove|ip.close] IP")
37
38 app.On("start:before", func() {
39 // validate config
40 _, err := configs.LoadAPIConfig()
41 if err != nil {
42 // validate cluster config
43 _, clusterErr := configs.LoadClusterConfig()
44 if clusterErr != nil { // fail again
45 fmt.Println("[ERROR]start failed: load api config from '" + Tea.ConfigFile(configs.ConfigFileName) + "' failed: " + err.Error())
46 os.Exit(0)
47 }
48 }
49 })
50 app.On("uninstall", func() {
51 // service
52 fmt.Println("Uninstall service ...")
53 var manager = utils.NewServiceManager(teaconst.ProcessName, teaconst.ProductName)
54 go func() {
55 _ = manager.Uninstall()
56 }()
57
58 // stop
59 fmt.Println("Stopping ...")
60 _, _ = gosock.NewTmpSock(teaconst.ProcessName).SendTimeout(&gosock.Command{Code: "stop"}, 1*time.Second)
61
62 // delete files
63 var exe, _ = os.Executable()
64 if len(exe) == 0 {
65 return
66 }
67
68 var dir = filepath.Dir(filepath.Dir(exe)) // ROOT / bin / exe
69
70 // verify dir
71 {
72 fmt.Println("Checking '" + dir + "' ...")
73 for _, subDir := range []string{"bin/" + filepath.Base(exe), "configs", "logs"} {
74 _, err := os.Stat(dir + "/" + subDir)
75 if err != nil {
76 fmt.Println("[ERROR]program directory structure has been broken, please remove it manually.")
77 return
78 }
79 }
80
81 fmt.Println("Removing '" + dir + "' ...")
82 err := os.RemoveAll(dir)
83 if err != nil {
84 fmt.Println("[ERROR]remove failed: " + err.Error())
85 }
86 }
87

Callers

nothing calls this directly

Calls 15

NewAppCmdFunction · 0.92
LoadAPIConfigFunction · 0.92
LoadClusterConfigFunction · 0.92
NewServiceManagerFunction · 0.92
NewNodeFunction · 0.92
UsageMethod · 0.80
ProductMethod · 0.80
VersionMethod · 0.80
OnMethod · 0.80
WriteStringMethod · 0.80
DaemonMethod · 0.80
InstallSystemServiceMethod · 0.80

Tested by

no test coverage detected