aboutsummaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'main.go')
-rw-r--r--main.go22
1 files changed, 20 insertions, 2 deletions
diff --git a/main.go b/main.go
index d6597a2..a5b4394 100644
--- a/main.go
+++ b/main.go
@@ -1,6 +1,7 @@
package main
import (
+ "context"
"crypto/rand"
"encoding/hex"
"encoding/json"
@@ -9,6 +10,7 @@ import (
"os"
"os/signal"
"syscall"
+ "time"
log "github.com/sirupsen/logrus"
"gopkg.in/yaml.v2"
@@ -179,12 +181,12 @@ func main() {
sigch := make(chan os.Signal)
signal.Notify(sigch, os.Interrupt, syscall.SIGTERM)
- err = StartAppService(errch)
+ as_server, err := StartAppService(errch)
if err != nil {
log.Fatal(err)
}
- StartWeb(errch)
+ web_server := StartWeb(errch)
// Wait for an error somewhere or interrupt signal
select {
@@ -196,6 +198,22 @@ func main() {
log.Warnf("Got signal %s", sig.String())
}
+ // Shut down, hopefully this is not a too bad way to do it
log.Warn("Shuttind down")
+ delay := 2 * time.Second
+
+ ctx1, _ := context.WithTimeout(context.TODO(), delay)
+ go as_server.Shutdown(ctx1)
+
+ ctx2, _ := context.WithTimeout(context.TODO(), delay)
+ go web_server.Shutdown(ctx2)
+
+ time.Sleep(delay)
CloseAllAcountsForShutdown()
+
+ if err != nil {
+ os.Exit(1)
+ } else {
+ os.Exit(0)
+ }
}