mirror of https://github.com/perkeep/perkeep.git
pkg/osutil: add arguments to RestartProcess
use it to restart server with -reindex Fixes #753 Change-Id: Iff4a8c725820f8204d9539b9bafe5f4d3b65780c
This commit is contained in:
parent
99a3dac0a8
commit
af3d0dc1f2
|
@ -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())
|
||||
}
|
||||
|
|
|
@ -243,7 +243,8 @@ func (sh *StatusHandler) serveStatusHTML(rw http.ResponseWriter, req *http.Reque
|
|||
f("</ul>")
|
||||
|
||||
f("<h2>Admin</h2>")
|
||||
f("<form method='post' action='restart' onsubmit='return confirm(\"Really restart now?\")'><button>restart server</button></form>")
|
||||
f("<form method='post' action='restart' onsubmit='return confirm(\"Really restart now?\")'><button>restart server</button>")
|
||||
f("<input type='checkbox' name='reindex'> reindex<br></form>")
|
||||
|
||||
f("<h2>Handlers</h2>")
|
||||
f("<p>As JSON: <a href='status.json'>status.json</a>; and the <a href='%s?camli.mode=config'>discovery JSON</a>.</p>", 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
|
||||
|
|
Loading…
Reference in New Issue