fix: ensure restart api return ok
This commit is contained in:
parent
ce14c86e4c
commit
d2b5e19b68
1 changed files with 29 additions and 20 deletions
|
@ -21,7 +21,7 @@ func restartRouter() http.Handler {
|
||||||
}
|
}
|
||||||
|
|
||||||
func restart(w http.ResponseWriter, r *http.Request) {
|
func restart(w http.ResponseWriter, r *http.Request) {
|
||||||
// modify from https://github.com/AdguardTeam/AdGuardHome/blob/595484e0b3fb4c457f9bb727a6b94faa78a66c5f/internal/home/controlupdate.go#L180
|
// modify from https://github.com/AdguardTeam/AdGuardHome/blob/595484e0b3fb4c457f9bb727a6b94faa78a66c5f/internal/home/controlupdate.go#L108
|
||||||
execPath, err := os.Executable()
|
execPath, err := os.Executable()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
render.Status(r, http.StatusInternalServerError)
|
render.Status(r, http.StatusInternalServerError)
|
||||||
|
@ -29,6 +29,16 @@ func restart(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
render.JSON(w, r, render.M{"status": "ok"})
|
||||||
|
if f, ok := w.(http.Flusher); ok {
|
||||||
|
f.Flush()
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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
|
||||||
|
// also should be done in a separate goroutine for the same reason.
|
||||||
|
go func() {
|
||||||
if runtime.GOOS == "windows" {
|
if runtime.GOOS == "windows" {
|
||||||
cmd := exec.Command(execPath, os.Args[1:]...)
|
cmd := exec.Command(execPath, os.Args[1:]...)
|
||||||
log.Infoln("restarting: %q %q", execPath, os.Args[1:])
|
log.Infoln("restarting: %q %q", execPath, os.Args[1:])
|
||||||
|
@ -48,6 +58,5 @@ func restart(w http.ResponseWriter, r *http.Request) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln("restarting: %s", err)
|
log.Fatalln("restarting: %s", err)
|
||||||
}
|
}
|
||||||
|
}()
|
||||||
render.JSON(w, r, render.M{"status": "ok"})
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue