diff options
author | zeripath <art27@cantab.net> | 2020-10-19 22:03:08 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-19 17:03:08 -0400 |
commit | 2f1353a2f33762e10a304cbebf3a6a8d0381d316 (patch) | |
tree | b345bf060a107341c64447f7132d9e2b8d37a7b3 /routers/install.go | |
parent | 3ddf3f93d6346ac9440a7a571faea4b5c1c329be (diff) | |
download | gitea-2f1353a2f33762e10a304cbebf3a6a8d0381d316.tar.gz gitea-2f1353a2f33762e10a304cbebf3a6a8d0381d316.zip |
Move install pages out of main macaron routes (#13195)
* Move install pages out of main macaron loop
Signed-off-by: Andrew Thornton <art27@cantab.net>
* Update templates/post-install.tmpl
Co-authored-by: Lauris BH <lauris@nix.lv>
* remove prefetch
Signed-off-by: Andrew Thornton <art27@cantab.net>
Diffstat (limited to 'routers/install.go')
-rw-r--r-- | routers/install.go | 36 |
1 files changed, 25 insertions, 11 deletions
diff --git a/routers/install.go b/routers/install.go index a7fe557748..5d0d089dc0 100644 --- a/routers/install.go +++ b/routers/install.go @@ -5,7 +5,7 @@ package routers import ( - "errors" + "net/http" "os" "os/exec" "path/filepath" @@ -27,13 +27,15 @@ import ( const ( // tplInstall template for installation page - tplInstall base.TplName = "install" + tplInstall base.TplName = "install" + tplPostInstall base.TplName = "post-install" ) // InstallInit prepare for rendering installation page func InstallInit(ctx *context.Context) { if setting.InstallLock { - ctx.NotFound("Install", errors.New("Installation is prohibited")) + ctx.Header().Add("Refresh", "1; url="+setting.AppURL+"user/login") + ctx.HTML(200, tplPostInstall) return } @@ -357,7 +359,8 @@ func InstallPost(ctx *context.Context, form auth.InstallForm) { return } - GlobalInit(graceful.GetManager().HammerContext()) + // Re-read settings + PostInstallInit(ctx.Req.Context()) // Create admin account if len(form.AdminName) > 0 { @@ -380,6 +383,11 @@ func InstallPost(ctx *context.Context, form auth.InstallForm) { u, _ = models.GetUserByName(u.Name) } + days := 86400 * setting.LogInRememberDays + ctx.SetCookie(setting.CookieUserName, u.Name, days, setting.AppSubURL, setting.SessionConfig.Domain, setting.SessionConfig.Secure, true) + ctx.SetSuperSecureCookie(base.EncodeMD5(u.Rands+u.Passwd), + setting.CookieRememberName, u.Name, days, setting.AppSubURL, setting.SessionConfig.Domain, setting.SessionConfig.Secure, true) + // Auto-login for admin if err = ctx.Session.Set("uid", u.ID); err != nil { ctx.RenderWithErr(ctx.Tr("install.save_config_failed", err), tplInstall, &form) @@ -397,12 +405,18 @@ func InstallPost(ctx *context.Context, form auth.InstallForm) { } log.Info("First-time run install finished!") - // FIXME: This isn't really enough to completely take account of new configuration - // We should really be restarting: - // - On windows this is probably just a simple restart - // - On linux we can't just use graceful.RestartProcess() everything that was passed in on LISTEN_FDS - // (active or not) needs to be passed out and everything new passed out too. - // This means we need to prevent the cleanup goroutine from running prior to the second GlobalInit + ctx.Flash.Success(ctx.Tr("install.install_success")) - ctx.Redirect(form.AppURL + "user/login") + + ctx.Header().Add("Refresh", "1; url="+setting.AppURL+"user/login") + ctx.HTML(200, tplPostInstall) + + // Now get the http.Server from this request and shut it down + // NB: This is not our hammerable graceful shutdown this is http.Server.Shutdown + srv := ctx.Req.Context().Value(http.ServerContextKey).(*http.Server) + go func() { + if err := srv.Shutdown(graceful.GetManager().HammerContext()); err != nil { + log.Error("Unable to shutdown the install server! Error: %v", err) + } + }() } |