结束运行进程
This commit is contained in:
parent
c025861afc
commit
12fe2d6ab6
1
main.go
1
main.go
|
@ -162,6 +162,7 @@ func main() {
|
||||||
// 运行相关
|
// 运行相关
|
||||||
http.HandleFunc("/build", output.BuildHandler)
|
http.HandleFunc("/build", output.BuildHandler)
|
||||||
http.HandleFunc("/run", output.RunHandler)
|
http.HandleFunc("/run", output.RunHandler)
|
||||||
|
http.HandleFunc("/stop", output.StopHandler)
|
||||||
http.HandleFunc("/go/get", output.GoGetHandler)
|
http.HandleFunc("/go/get", output.GoGetHandler)
|
||||||
http.HandleFunc("/go/install", output.GoInstallHandler)
|
http.HandleFunc("/go/install", output.GoInstallHandler)
|
||||||
http.HandleFunc("/output/ws", output.WSHandler)
|
http.HandleFunc("/output/ws", output.WSHandler)
|
||||||
|
|
|
@ -520,6 +520,32 @@ func GoGetHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}(rand.Int())
|
}(rand.Int())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 结束正在运行的进程.
|
||||||
|
func StopHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
data := map[string]interface{}{"succ": true}
|
||||||
|
defer util.RetJSON(w, r, data)
|
||||||
|
|
||||||
|
var args map[string]interface{}
|
||||||
|
if err := json.NewDecoder(r.Body).Decode(&args); err != nil {
|
||||||
|
glog.Error(err)
|
||||||
|
data["succ"] = false
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
sid := args["sid"].(string)
|
||||||
|
pid := args["pid"].(int)
|
||||||
|
|
||||||
|
wSession := session.WideSessions.Get(sid)
|
||||||
|
if nil == wSession {
|
||||||
|
data["succ"] = false
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
processes.kill(wSession, pid)
|
||||||
|
}
|
||||||
|
|
||||||
func setCmdEnv(cmd *exec.Cmd, username string) {
|
func setCmdEnv(cmd *exec.Cmd, username string) {
|
||||||
userWorkspace := conf.Wide.GetUserWorkspace(username)
|
userWorkspace := conf.Wide.GetUserWorkspace(username)
|
||||||
|
|
||||||
|
|
|
@ -83,6 +83,8 @@ func (procs *procs) kill(wSession *session.WideSession, pid int) {
|
||||||
|
|
||||||
glog.V(3).Infof("Killed a process [pid=%d] of session [%s]", pid, sid)
|
glog.V(3).Infof("Killed a process [pid=%d] of session [%s]", pid, sid)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue