Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions modules/graceful/restart.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,24 @@ import (
"os"
"os/exec"
"strings"
"sync"
"syscall"
)

var killParent sync.Once

// KillParent sends the kill signal to the parent process if we are a child
func KillParent() {
killParent.Do(func() {
if IsChild {
ppid := syscall.Getppid()
if ppid > 1 {
_ = syscall.Kill(ppid, syscall.SIGTERM)
}
}
})
}

// RestartProcess starts a new process passing it the active listeners. It
// doesn't fork, but starts a new process using the same environment and
// arguments as when it was originally started. This allows for a newly
Expand Down
8 changes: 2 additions & 6 deletions modules/graceful/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,7 @@ func (srv *Server) ListenAndServe(serve ServeFunction) error {

srv.listener = newWrappedListener(l, srv)

if IsChild {
_ = syscall.Kill(syscall.Getppid(), syscall.SIGTERM)
}
KillParent()

srv.BeforeBegin(srv.network, srv.address)

Expand Down Expand Up @@ -156,9 +154,7 @@ func (srv *Server) ListenAndServeTLSConfig(tlsConfig *tls.Config, serve ServeFun
wl := newWrappedListener(l, srv)
srv.listener = tls.NewListener(wl, tlsConfig)

if IsChild {
_ = syscall.Kill(syscall.Getppid(), syscall.SIGTERM)
}
KillParent()
srv.BeforeBegin(srv.network, srv.address)

return srv.Serve(serve)
Expand Down