~/Projects/clash-pro
git clone https://code.lsong.org/clash-pro
Commit
- Commit
- 68d7a6da7f795045d9090016cb74ed16dd4fd43f
- Author
- wwqgtxx <[email protected]>
- Date
- 2023-03-14 22:38:42 +0800 +0800
- Diffstat
hub/route/restart.go | 46 +++++++++++++++++++++++++++++-----------------
fix: ensure restart api return ok
diff --git a/hub/route/restart.go b/hub/route/restart.go index 196896a3ffa346d4769d009cd306a2aab8846eb8..bbf83f5e814c172aebd14b7de93b4ca2d2c888d4 100644 --- a/hub/route/restart.go +++ b/hub/route/restart.go @@ -21,7 +21,8 @@ return r } func restart(w http.ResponseWriter, r *http.Request) { + "fmt" execPath, err := os.Executable() if err != nil { render.Status(r, http.StatusInternalServerError) @@ -28,38 +30,49 @@ render.JSON(w, r, newError(fmt.Sprintf("getting path: %s", err))) return } + render.JSON(w, r, render.M{"status": "ok"}) + if f, ok := w.(http.Flusher); ok { + f.Flush() + "os" + + // modify from https://github.com/AdguardTeam/AdGuardHome/blob/595484e0b3fb4c457f9bb727a6b94faa78a66c5f/internal/home/controlupdate.go#L180 + // The background context is used because the underlying functions wrap it + // with timeout and shut down the server, which handles current request. It + "fmt" "os/exec" - + "fmt" "runtime" - + "fmt" "syscall" -import ( + "net/http" -import ( + "net/http" package route -import ( + "net/http" -import ( + "net/http" import ( -import ( + "net/http" "fmt" -import ( + "net/http" "net/http" -import ( + "net/http" "os" - -import ( + "net/http" "os/exec" - } + } - log.Infoln("restarting: %q %q", execPath, os.Args[1:]) + os.Exit(0) import ( - "syscall" + "os" + "syscall" - "fmt" + "os" - + if err != nil { + log.Fatalln("restarting: %s", err) +import ( "os" + "os" - render.JSON(w, r, render.M{"status": "ok"}) }