diff --git a/service/service.go b/service/service.go index e6a73f2a..304d1e1b 100644 --- a/service/service.go +++ b/service/service.go @@ -45,6 +45,14 @@ func StartWithouttSession() { Middlewares...) } +// StopWithouttSession 关闭服务 +func StopWithouttSession(onComplete func()) { + shutdown <- true + <-shutdownComplete + gou.KillPlugins() + onComplete() +} + // Stop 关闭服务 func Stop(onComplete func()) { shutdown <- true diff --git a/service/watch.go b/service/watch.go index ed6afc41..92247d3f 100644 --- a/service/watch.go +++ b/service/watch.go @@ -67,7 +67,7 @@ func WatchGlobal(root string) { fmt.Println(color.RedString("Fatal: %s", err.Error())) return } - Stop(func() { + StopWithouttSession(func() { fmt.Println(color.GreenString("Service Restarted")) go StartWithouttSession() }) @@ -137,7 +137,7 @@ func WatchAPI(root string, prefix string) { // 重启服务器 if op == "write" || op == "create" || op == "remove" || op == "rename" { - Stop(func() { + StopWithouttSession(func() { fmt.Println(color.GreenString("Service Restarted")) go StartWithouttSession() }) @@ -268,7 +268,7 @@ func WatchTable(root string, prefix string) { // 重启服务器 if op == "write" || op == "create" || op == "remove" || op == "rename" { - Stop(func() { + StopWithouttSession(func() { fmt.Println(color.GreenString("Service Restarted")) go StartWithouttSession() }) @@ -335,7 +335,7 @@ func WatchChart(root string, prefix string) { // 重启服务器 if op == "write" || op == "create" || op == "remove" || op == "rename" { - Stop(func() { + StopWithouttSession(func() { fmt.Println(color.GreenString("Service Restarted")) go StartWithouttSession() }) @@ -402,7 +402,7 @@ func WatchPage(root string, prefix string) { // 重启服务器 if op == "write" || op == "create" || op == "remove" || op == "rename" { - Stop(func() { + StopWithouttSession(func() { fmt.Println(color.GreenString("Service Restarted")) go StartWithouttSession() }) @@ -450,7 +450,7 @@ func WatchWorkFlow(root string, prefix string) { // 重启服务器 if op == "write" || op == "create" || op == "remove" || op == "rename" { - Stop(func() { + StopWithouttSession(func() { fmt.Println(color.GreenString("Service Restarted")) go StartWithouttSession() })