结束运行进程

This commit is contained in:
Liang Ding 2014-09-22 17:44:07 +08:00
parent c025861afc
commit 12fe2d6ab6
3 changed files with 29 additions and 0 deletions

View File

@ -162,6 +162,7 @@ func main() {
// 运行相关
http.HandleFunc("/build", output.BuildHandler)
http.HandleFunc("/run", output.RunHandler)
http.HandleFunc("/stop", output.StopHandler)
http.HandleFunc("/go/get", output.GoGetHandler)
http.HandleFunc("/go/install", output.GoInstallHandler)
http.HandleFunc("/output/ws", output.WSHandler)

View File

@ -520,6 +520,32 @@ func GoGetHandler(w http.ResponseWriter, r *http.Request) {
}(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) {
userWorkspace := conf.Wide.GetUserWorkspace(username)

View File

@ -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)
}
return
}
}
}