Files
hw-fbbot/closehandle.go
Josef Fröhle 41861da83e add systemd service files
collect configiguration together
update README
2020-01-15 15:37:02 +01:00

24 lines
570 B
Go

package main
import (
"fmt"
"os"
"os/signal"
"syscall"
)
// SetupCloseHandler creates a 'listener' on a new goroutine which will notify the
// program if it receives an interrupt from the OS. We then handle this by calling
// our clean up procedure and exiting the program.
func SetupCloseHandler() {
c := make(chan os.Signal, 2)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
signal.Notify(c, os.Interrupt, syscall.SIGHUP)
signal.Notify(c, os.Interrupt, syscall.SIGKILL)
go func() {
<-c
fmt.Println("\r- Ctrl+C pressed in Terminal")
os.Exit(0)
}()
}