mirror of
https://github.com/Kong/go-pluginserver.git
synced 2025-10-10 18:40:11 +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"
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
var version = "development"
|
var version = "development"
|
||||||
@@ -99,6 +100,10 @@ func startServer() {
|
|||||||
runServer(listener)
|
runServer(listener)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func isParentAlive() bool {
|
||||||
|
return os.Getppid() != 1 // assume ppid 1 means process was adopted by init
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
if *showVersion == true {
|
if *showVersion == true {
|
||||||
printVersion()
|
printVersion()
|
||||||
@@ -111,6 +116,17 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if socket != "" {
|
if socket != "" {
|
||||||
|
go func() {
|
||||||
|
for {
|
||||||
|
if ! isParentAlive() {
|
||||||
|
log.Printf("Kong exited; shutting down...")
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
time.Sleep(1 * time.Second)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
startServer()
|
startServer()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user