diff options
author | zeripath <art27@cantab.net> | 2019-11-24 02:11:24 +0000 |
---|---|---|
committer | Antoine GIRARD <sapk@users.noreply.github.com> | 2019-11-24 03:11:24 +0100 |
commit | e3f22ad2cca094cba057683f35f8536e3f71a582 (patch) | |
tree | 9585b6493b3a4bff13d113c9e2d7ed8f26f2c16a /modules/graceful | |
parent | bb2c0c3729b4bb4b1475b176dfe8e1d43f49481f (diff) | |
download | gitea-e3f22ad2cca094cba057683f35f8536e3f71a582.tar.gz gitea-e3f22ad2cca094cba057683f35f8536e3f71a582.zip |
Graceful: Allow graceful restart for unix sockets (#9113)
Previously we could not handle graceful restarts for http over unix
sockets. These can now be handled.
Diffstat (limited to 'modules/graceful')
-rw-r--r-- | modules/graceful/net_unix.go | 15 | ||||
-rw-r--r-- | modules/graceful/restart_unix.go | 5 |
2 files changed, 19 insertions, 1 deletions
diff --git a/modules/graceful/net_unix.go b/modules/graceful/net_unix.go index 2b8efe0353..5550c09f42 100644 --- a/modules/graceful/net_unix.go +++ b/modules/graceful/net_unix.go @@ -16,6 +16,7 @@ import ( "sync" "code.gitea.io/gitea/modules/log" + "code.gitea.io/gitea/modules/setting" ) const ( @@ -165,15 +166,27 @@ func GetListenerUnix(network string, address *net.UnixAddr) (*net.UnixListener, if isSameAddr(l.Addr(), address) { providedListeners = append(providedListeners[:i], providedListeners[i+1:]...) activeListeners = append(activeListeners, l) - return l.(*net.UnixListener), nil + unixListener := l.(*net.UnixListener) + unixListener.SetUnlinkOnClose(true) + return unixListener, nil } } // make a fresh listener + if err := os.Remove(address.Name); err != nil && !os.IsNotExist(err) { + return nil, fmt.Errorf("Failed to remove unix socket %s: %v", address.Name, err) + } + l, err := net.ListenUnix(network, address) if err != nil { return nil, err } + + fileMode := os.FileMode(setting.UnixSocketPermission) + if err = os.Chmod(address.Name, fileMode); err != nil { + return nil, fmt.Errorf("Failed to set permission of unix socket to %s: %v", fileMode.String(), err) + } + activeListeners = append(activeListeners, l) return l, nil } diff --git a/modules/graceful/restart_unix.go b/modules/graceful/restart_unix.go index 8c68965f5d..3fc4f0511d 100644 --- a/modules/graceful/restart_unix.go +++ b/modules/graceful/restart_unix.go @@ -9,6 +9,7 @@ package graceful import ( "fmt" + "net" "os" "os/exec" "strings" @@ -48,6 +49,10 @@ func RestartProcess() (int, error) { if err != nil { return 0, err } + + if unixListener, ok := l.(*net.UnixListener); ok { + unixListener.SetUnlinkOnClose(false) + } // Remember to close these at the end. defer files[i].Close() } |