mirror of
https://github.com/Kong/go-pluginserver.git
synced 2025-10-11 02:50:50 +08:00
feat(*) exit if parent died
Run a goroutine every minute to check if parent died and exit. Assumption: if parent dies, the process gets adopted by init (pid 1).
This commit is contained in:
16
main.go
16
main.go
@@ -12,6 +12,7 @@ import (
|
||||
"os"
|
||||
"reflect"
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
var version = "development"
|
||||
@@ -99,6 +100,10 @@ func startServer() {
|
||||
runServer(listener)
|
||||
}
|
||||
|
||||
func isParentAlive() bool {
|
||||
return os.Getppid() != 1 // assume ppid 1 means process was adopted by init
|
||||
}
|
||||
|
||||
func main() {
|
||||
if *showVersion == true {
|
||||
printVersion()
|
||||
@@ -111,6 +116,17 @@ func main() {
|
||||
}
|
||||
|
||||
if socket != "" {
|
||||
go func() {
|
||||
for {
|
||||
if ! isParentAlive() {
|
||||
log.Printf("Kong exited; shutting down...")
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
time.Sleep(1 * time.Second)
|
||||
}
|
||||
}()
|
||||
|
||||
startServer()
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user