diff options
Diffstat (limited to 'main.go')
-rw-r--r-- | main.go | 20 |
1 files changed, 16 insertions, 4 deletions
@@ -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() } |