mirror of https://gogs.blitter.com/RLabs/xs
Added signal handling for hkexshd to respond as well-behaved daemon
Signed-off-by: Russ Magee <rmagee@gmail.com>
This commit is contained in:
parent
ee52959fab
commit
03eff74d8b
|
@ -20,6 +20,7 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"os/signal"
|
||||||
"os/user"
|
"os/user"
|
||||||
"path"
|
"path"
|
||||||
"sync"
|
"sync"
|
||||||
|
@ -395,6 +396,29 @@ func main() {
|
||||||
log.SetOutput(ioutil.Discard)
|
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
|
// Listen on TCP port 2000 on all available unicast and
|
||||||
// anycast IP addresses of the local system.
|
// anycast IP addresses of the local system.
|
||||||
l, err := hkexnet.Listen("tcp", laddr)
|
l, err := hkexnet.Listen("tcp", laddr)
|
||||||
|
|
Loading…
Reference in New Issue