mirror of
				https://github.com/TeaOSLab/EdgeNode.git
				synced 2025-11-04 07:40:56 +08:00 
			
		
		
		
	支持优雅退出
This commit is contained in:
		@@ -5,15 +5,19 @@ import (
 | 
			
		||||
	"github.com/TeaOSLab/EdgeNode/internal/apps"
 | 
			
		||||
	teaconst "github.com/TeaOSLab/EdgeNode/internal/const"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeNode/internal/nodes"
 | 
			
		||||
	"github.com/iwind/TeaGo/Tea"
 | 
			
		||||
	_ "github.com/iwind/TeaGo/bootstrap"
 | 
			
		||||
	"github.com/iwind/TeaGo/types"
 | 
			
		||||
	"io/ioutil"
 | 
			
		||||
	"os"
 | 
			
		||||
	"syscall"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func main() {
 | 
			
		||||
	app := apps.NewAppCmd().
 | 
			
		||||
		Version(teaconst.Version).
 | 
			
		||||
		Product(teaconst.ProductName).
 | 
			
		||||
		Usage(teaconst.ProcessName + " [-v|start|stop|restart|sync|update|test]")
 | 
			
		||||
		Usage(teaconst.ProcessName + " [-v|start|stop|restart|quit|sync|update|test]")
 | 
			
		||||
 | 
			
		||||
	app.On("test", func() {
 | 
			
		||||
		err := nodes.NewNode().Test()
 | 
			
		||||
@@ -29,6 +33,27 @@ func main() {
 | 
			
		||||
		// TODO
 | 
			
		||||
		fmt.Println("not implemented yet")
 | 
			
		||||
	})
 | 
			
		||||
	app.On("quit", func() {
 | 
			
		||||
		pidFile := Tea.Root + "/bin/pid"
 | 
			
		||||
		data, err := ioutil.ReadFile(pidFile)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			fmt.Println("[ERROR]quit failed: " + err.Error())
 | 
			
		||||
			return
 | 
			
		||||
		}
 | 
			
		||||
		pid := types.Int(string(data))
 | 
			
		||||
		if pid == 0 {
 | 
			
		||||
			fmt.Println("[ERROR]quit failed: pid=0")
 | 
			
		||||
			return
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		process, err := os.FindProcess(pid)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return
 | 
			
		||||
		}
 | 
			
		||||
		if process != nil {
 | 
			
		||||
			_ = process.Signal(syscall.SIGQUIT)
 | 
			
		||||
		}
 | 
			
		||||
	})
 | 
			
		||||
	app.Run(func() {
 | 
			
		||||
		node := nodes.NewNode()
 | 
			
		||||
		node.Start()
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user