mirror of
https://github.com/go-gitea/gitea
synced 2025-07-16 07:18:37 +00:00
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>
This commit is contained in:
@@ -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,
|
||||
|
Reference in New Issue
Block a user