remove old env variable on restart
This commit is contained in:
parent
c0e92551f5
commit
ae3f6c71a7
14
grace.go
14
grace.go
@ -29,7 +29,8 @@ var (
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
// Used to indicate a graceful restart in the new process.
|
// Used to indicate a graceful restart in the new process.
|
||||||
envCountKey = "LISTEN_FDS"
|
envCountKey = "LISTEN_FDS"
|
||||||
|
envCountKeyPrefix = envCountKey + "="
|
||||||
|
|
||||||
// The error returned by the standard library when the socket is closed.
|
// The error returned by the standard library when the socket is closed.
|
||||||
errClosed = "use of closed network connection"
|
errClosed = "use of closed network connection"
|
||||||
@ -221,10 +222,19 @@ func Restart(listeners []Listener) (err error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var env []string
|
||||||
|
for _, v := range os.Environ() {
|
||||||
|
if !strings.HasPrefix(v, envCountKeyPrefix) {
|
||||||
|
env = append(env, v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
env = append(env, fmt.Sprintf("%s%d", envCountKeyPrefix, len(listeners)))
|
||||||
|
|
||||||
allFiles := append([]*os.File{os.Stdin, os.Stdout, os.Stderr}, files...)
|
allFiles := append([]*os.File{os.Stdin, os.Stdout, os.Stderr}, files...)
|
||||||
_, err = os.StartProcess(argv0, os.Args, &os.ProcAttr{
|
_, err = os.StartProcess(argv0, os.Args, &os.ProcAttr{
|
||||||
Dir: wd,
|
Dir: wd,
|
||||||
Env: append(os.Environ(), fmt.Sprintf("%s=%d", envCountKey, len(listeners))),
|
Env: env,
|
||||||
Files: allFiles,
|
Files: allFiles,
|
||||||
})
|
})
|
||||||
return err
|
return err
|
||||||
|
Loading…
Reference in New Issue
Block a user