From 76f678bb3446abfa479a03a7ef6f5c71c22edcaf Mon Sep 17 00:00:00 2001
From: Jono Wenger <jono@elixxir.io>
Date: Wed, 6 Jul 2022 12:19:13 -0700
Subject: [PATCH] Add graceful termination

---
 connectServer/main.go | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/connectServer/main.go b/connectServer/main.go
index 7a29d85..9b46cf6 100644
--- a/connectServer/main.go
+++ b/connectServer/main.go
@@ -9,6 +9,8 @@ import (
 	"io/fs"
 	"io/ioutil"
 	"os"
+	"os/signal"
+	"syscall"
 	"time"
 
 	"gitlab.com/elixxir/client/connect"
@@ -161,5 +163,17 @@ func main() {
 
 	// Keep app running to receive messages-----------------------------------------------
 
-	select {}
+	// Wait until the user terminates the program
+	c := make(chan os.Signal)
+	signal.Notify(c, os.Interrupt, syscall.SIGTERM)
+	<-c
+
+	err = e2eClient.StopNetworkFollower()
+	if err != nil {
+		jww.ERROR.Printf("Failed to stop network follower: %+v", err)
+	} else {
+		jww.INFO.Printf("Stopped network follower.")
+	}
+
+	os.Exit(0)
 }
-- 
GitLab