added handling for sighup (issues reload command to server)
This commit is contained in:
parent
f559a6f990
commit
090e35e46c
1 changed files with 23 additions and 9 deletions
|
@ -57,19 +57,33 @@ func RunService() {
|
|||
}
|
||||
}()
|
||||
|
||||
// Separate Channel for handling SIGHUP
|
||||
hupCh := make(chan os.Signal, 1)
|
||||
signal.Notify(hupCh, syscall.SIGHUP)
|
||||
|
||||
ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
|
||||
defer stop()
|
||||
<- ctx.Done()
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-hupCh:
|
||||
log.Println("Sending reload signal to Server Process")
|
||||
if _, err := stdin.Write([]byte("reload\n")); err != nil {
|
||||
log.Printf("write error: %v", err)
|
||||
}
|
||||
case <-ctx.Done():
|
||||
log.Println("Sending stop signal to Server Process")
|
||||
if _, err := stdin.Write([]byte("stop\n")); err != nil {
|
||||
log.Printf("write error: %v", err)
|
||||
}
|
||||
//stdin.Close()
|
||||
|
||||
if err := cmd.Wait(); err != nil {
|
||||
log.Printf("child exit: %v", err)
|
||||
}
|
||||
|
||||
log.Println("Shutdown completed")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue