From 6055544313c8ecfd3e73168d2507e4a0a3b8e32a Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Sun, 1 Mar 2020 14:14:18 +0100 Subject: Now receiving messages from messenger as well (rudimentary) --- main.go | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'main.go') diff --git a/main.go b/main.go index 514bd4c..d6597a2 100644 --- a/main.go +++ b/main.go @@ -7,6 +7,8 @@ import ( "flag" "io/ioutil" "os" + "os/signal" + "syscall" log "github.com/sirupsen/logrus" "gopkg.in/yaml.v2" @@ -174,6 +176,9 @@ func main() { // Start appservice and web management interface errch := make(chan error) + sigch := make(chan os.Signal) + signal.Notify(sigch, os.Interrupt, syscall.SIGTERM) + err = StartAppService(errch) if err != nil { log.Fatal(err) @@ -181,9 +186,16 @@ func main() { StartWeb(errch) - // Wait for an error somewhere - err = <-errch - if err != nil { - log.Fatal(err) + // Wait for an error somewhere or interrupt signal + select { + case err = <-errch: + if err != nil { + log.Error(err) + } + case sig := <-sigch: + log.Warnf("Got signal %s", sig.String()) } + + log.Warn("Shuttind down") + CloseAllAcountsForShutdown() } -- cgit v1.2.3