From af3d0dc1f20db8d07dad8d77f87db3526c9883ff Mon Sep 17 00:00:00 2001 From: mpl Date: Fri, 6 May 2016 19:53:44 +0200 Subject: [PATCH] pkg/osutil: add arguments to RestartProcess use it to restart server with -reindex Fixes #753 Change-Id: Iff4a8c725820f8204d9539b9bafe5f4d3b65780c --- pkg/osutil/restart_unix.go | 22 +++++++++++++++++----- pkg/server/status.go | 7 +++++-- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/pkg/osutil/restart_unix.go b/pkg/osutil/restart_unix.go index 84d5a5cb7..a1c0805c3 100644 --- a/pkg/osutil/restart_unix.go +++ b/pkg/osutil/restart_unix.go @@ -56,13 +56,25 @@ func SelfPath() (string, error) { return "", errors.New("SelfPath not implemented for " + runtime.GOOS) } -// RestartProcess returns an error if things couldn't be -// restarted. On success, this function never returns -// because the process becomes the new process. -func RestartProcess() error { +// RestartProcess restarts the process with the given arguments, if any, +// replacing the original process's arguments. It defaults to os.Args otherwise. It +// returns an error if things couldn't be restarted. On success, this function +// never returns because the process becomes the new process. +func RestartProcess(arg ...string) error { path, err := SelfPath() if err != nil { return fmt.Errorf("RestartProcess failed: %v", err) } - return syscall.Exec(path, os.Args, os.Environ()) + + var args []string + if len(arg) > 0 { + args = append(args, os.Args[0]) + for _, v := range arg { + args = append(args, v) + } + } else { + args = os.Args + } + + return syscall.Exec(path, args, os.Environ()) } diff --git a/pkg/server/status.go b/pkg/server/status.go index 2f6465e46..ec743c89f 100644 --- a/pkg/server/status.go +++ b/pkg/server/status.go @@ -243,7 +243,8 @@ func (sh *StatusHandler) serveStatusHTML(rw http.ResponseWriter, req *http.Reque f("") f("

Admin

") - f("
") + f("
") + f(" reindex
") f("

Handlers

") f("

As JSON: status.json; and the discovery JSON.

", st.rootPrefix) @@ -285,13 +286,15 @@ func (sh *StatusHandler) serveRestart(rw http.ResponseWriter, req *http.Request) } } + reindex := (req.FormValue("reindex") == "on") + log.Println("Restarting camlistored") rw.Header().Set("Connection", "close") http.Redirect(rw, req, sh.prefix, http.StatusFound) if f, ok := rw.(http.Flusher); ok { f.Flush() } - osutil.RestartProcess() + osutil.RestartProcess(fmt.Sprintf("-reindex=%t", reindex)) } var cgoEnabled bool