summaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2019-11-30 08:40:22 -0600
committerLauris BH <lauris@nix.lv>2019-11-30 16:40:22 +0200
commit60c5339042a605076482320313e8f9498dd72af9 (patch)
treebef1e4a0fb9565140fbf142f13d3b7e5f334031d /routers
parent8f8c250ddbe8dfe785340cb45cbae71c4833acf3 (diff)
downloadgitea-60c5339042a605076482320313e8f9498dd72af9.tar.gz
gitea-60c5339042a605076482320313e8f9498dd72af9.zip
Graceful: Cancel Process on monitor pages & HammerTime (#9213)
* Graceful: Create callbacks to with contexts * Graceful: Say when Gitea is completely finished * Graceful: Git and Process within HammerTime Force all git commands to terminate at HammerTime Force all process commands to terminate at HammerTime Move almost all git processes to run as git Commands * Graceful: Always Hammer after Shutdown * ProcessManager: Add cancel functionality * Fix tests * Make sure that process.Manager.Kill() cancels * Make threadsafe access to Processes and remove own unused Kill * Remove cmd from the process manager as it is no longer used * the default context is the correct context * get rid of double till
Diffstat (limited to 'routers')
-rw-r--r--routers/admin/admin.go11
-rw-r--r--routers/repo/http.go10
-rw-r--r--routers/routes/routes.go1
3 files changed, 20 insertions, 2 deletions
diff --git a/routers/admin/admin.go b/routers/admin/admin.go
index 45bdbfe7f2..9f155ff008 100644
--- a/routers/admin/admin.go
+++ b/routers/admin/admin.go
@@ -352,7 +352,16 @@ func Monitor(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("admin.monitor")
ctx.Data["PageIsAdmin"] = true
ctx.Data["PageIsAdminMonitor"] = true
- ctx.Data["Processes"] = process.GetManager().Processes
+ ctx.Data["Processes"] = process.GetManager().Processes()
ctx.Data["Entries"] = cron.ListTasks()
ctx.HTML(200, tplMonitor)
}
+
+// MonitorCancel cancels a process
+func MonitorCancel(ctx *context.Context) {
+ pid := ctx.ParamsInt64("pid")
+ process.GetManager().Cancel(pid)
+ ctx.JSON(200, map[string]interface{}{
+ "redirect": ctx.Repo.RepoLink + "/admin/monitor",
+ })
+}
diff --git a/routers/repo/http.go b/routers/repo/http.go
index 0025ba2af4..c66d7aae65 100644
--- a/routers/repo/http.go
+++ b/routers/repo/http.go
@@ -8,6 +8,7 @@ package repo
import (
"bytes"
"compress/gzip"
+ gocontext "context"
"fmt"
"net/http"
"os"
@@ -24,6 +25,7 @@ import (
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log"
+ "code.gitea.io/gitea/modules/process"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/timeutil"
)
@@ -463,8 +465,10 @@ func serviceRPC(h serviceHandler, service string) {
// set this for allow pre-receive and post-receive execute
h.environ = append(h.environ, "SSH_ORIGINAL_COMMAND="+service)
+ ctx, cancel := gocontext.WithCancel(git.DefaultContext)
+ defer cancel()
var stderr bytes.Buffer
- cmd := exec.Command(git.GitExecutable, service, "--stateless-rpc", h.dir)
+ cmd := exec.CommandContext(ctx, git.GitExecutable, service, "--stateless-rpc", h.dir)
cmd.Dir = h.dir
if service == "receive-pack" {
cmd.Env = append(os.Environ(), h.environ...)
@@ -472,6 +476,10 @@ func serviceRPC(h serviceHandler, service string) {
cmd.Stdout = h.w
cmd.Stdin = reqBody
cmd.Stderr = &stderr
+
+ pid := process.GetManager().Add(fmt.Sprintf("%s %s %s [repo_path: %s]", git.GitExecutable, service, "--stateless-rpc", h.dir), cancel)
+ defer process.GetManager().Remove(pid)
+
if err := cmd.Run(); err != nil {
log.Error("Fail to serve RPC(%s): %v - %s", service, err, stderr.String())
return
diff --git a/routers/routes/routes.go b/routers/routes/routes.go
index 6de293c507..bac7d37916 100644
--- a/routers/routes/routes.go
+++ b/routers/routes/routes.go
@@ -422,6 +422,7 @@ func RegisterRoutes(m *macaron.Macaron) {
m.Get("/config", admin.Config)
m.Post("/config/test_mail", admin.SendTestMail)
m.Get("/monitor", admin.Monitor)
+ m.Post("/monitor/cancel/:pid", admin.MonitorCancel)
m.Group("/users", func() {
m.Get("", admin.Users)