Added signal handling for hkexshd to respond as well-behaved daemon

Signed-off-by: Russ Magee <rmagee@gmail.com>
This commit is contained in:
Russ Magee 2018-11-15 22:57:21 -08:00
parent ee52959fab
commit 03eff74d8b
1 changed files with 24 additions and 0 deletions

View File

@ -20,6 +20,7 @@ import (
"log"
"os"
"os/exec"
"os/signal"
"os/user"
"path"
"sync"
@ -395,6 +396,29 @@ func main() {
log.SetOutput(ioutil.Discard)
}
// Set up handler for daemon signalling
exitCh := make(chan os.Signal, 1)
signal.Notify(exitCh, os.Signal(syscall.SIGTERM), os.Signal(syscall.SIGINT), os.Signal(syscall.SIGHUP), os.Signal(syscall.SIGUSR1), os.Signal(syscall.SIGUSR2))
go func() {
for {
sig := <-exitCh
switch sig.String() {
case "terminated":
logger.LogNotice(fmt.Sprintf("[Got signal: %s]", sig))
signal.Reset()
syscall.Kill(0, syscall.SIGTERM)
case "interrupt":
logger.LogNotice(fmt.Sprintf("[Got signal: %s]", sig))
signal.Reset()
syscall.Kill(0, syscall.SIGINT)
case "hangup":
logger.LogNotice(fmt.Sprintf("[Got signal: %s - nop]", sig))
default:
logger.LogNotice(fmt.Sprintf("[Got signal: %s - ignored]", sig))
}
}
}()
// Listen on TCP port 2000 on all available unicast and
// anycast IP addresses of the local system.
l, err := hkexnet.Listen("tcp", laddr)