aboutsummaryrefslogtreecommitdiffstats
path: root/modules/graceful/restart_unix.go
diff options
context:
space:
mode:
authorFrank <frankli0324@hotmail.com>2022-08-14 05:31:33 +0800
committerGitHub <noreply@github.com>2022-08-13 22:31:33 +0100
commit1f0638747bd51deb7b6f113ad085b6ae68289d27 (patch)
treea486cc89d3e7d4c1aa51613e5df2ba5441bc1ea4 /modules/graceful/restart_unix.go
parent99efa02edf4e3750e19bc28f7b856791356d1583 (diff)
downloadgitea-1f0638747bd51deb7b6f113ad085b6ae68289d27.tar.gz
gitea-1f0638747bd51deb7b6f113ad085b6ae68289d27.zip
Preserve unix socket file (#20499)
By default Gitea will always unlink any sockets that are provided using the `LISTEN_FDS` environment variable. This is because it uses this variable to handle passing when it is doing a graceful restart. However, this same mechanism is used by systemd - which explicitly expects that passed in sockets should not be unlinked by the receiving process. This PR adjusts Gitea's graceful restart mechanism to use an additional environment variable which tracks if a listening socket was opened by Gitea - and therefore should be unlinked on shutdown by Gitea. Fix #20490 Co-authored-by: zeripath <art27@cantab.net>
Diffstat (limited to 'modules/graceful/restart_unix.go')
-rw-r--r--modules/graceful/restart_unix.go15
1 files changed, 15 insertions, 0 deletions
diff --git a/modules/graceful/restart_unix.go b/modules/graceful/restart_unix.go
index 2654ddfb94..1d0d1059e9 100644
--- a/modules/graceful/restart_unix.go
+++ b/modules/graceful/restart_unix.go
@@ -12,6 +12,7 @@ import (
"net"
"os"
"os/exec"
+ "strconv"
"strings"
"sync"
"syscall"
@@ -75,6 +76,20 @@ func RestartProcess() (int, error) {
}
env = append(env, fmt.Sprintf("%s=%d", listenFDs, len(listeners)))
+ sb := &strings.Builder{}
+ for i, unlink := range getActiveListenersToUnlink() {
+ if !unlink {
+ continue
+ }
+ _, _ = sb.WriteString(strconv.Itoa(i))
+ _, _ = sb.WriteString(",")
+ }
+ unlinkStr := sb.String()
+ if len(unlinkStr) > 0 {
+ unlinkStr = unlinkStr[:len(unlinkStr)-1]
+ env = append(env, fmt.Sprintf("%s=%s", unlinkFDs, unlinkStr))
+ }
+
allFiles := append([]*os.File{os.Stdin, os.Stdout, os.Stderr}, files...)
process, err := os.StartProcess(argv0, os.Args, &os.ProcAttr{
Dir: originalWD,