From 89e45d069501875ba25cb595106da48b277a2bcd Mon Sep 17 00:00:00 2001 From: Praveen raj Mani Date: Thu, 21 Mar 2019 10:50:30 +0530 Subject: [PATCH] Restart process should use the current process' pid (#7373) This fixes varying pids for server-respawns. And avoids duplicate process creating multiple pids when the server restart signal is triggered with service restart enabled. Fixes #7350 --- cmd/service.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/cmd/service.go b/cmd/service.go index 1a31a9516..46d1af5db 100644 --- a/cmd/service.go +++ b/cmd/service.go @@ -19,6 +19,7 @@ package cmd import ( "os" "os/exec" + "syscall" ) // Type of service signals currently supported. @@ -56,9 +57,7 @@ func restartProcess() error { return err } - // Pass on the environment and replace the old count key with the new one. - cmd := exec.Command(argv0, os.Args[1:]...) - cmd.Stdout = os.Stdout - cmd.Stderr = os.Stderr - return cmd.Start() + // Invokes the execve system call. + // Re-uses the same pid. This preserves the pid over multiple server-respawns. + return syscall.Exec(argv0, os.Args, os.Environ()) }