This commit is contained in:
2025-04-06 18:36:16 +02:00
parent eaa0c62892
commit 6749289255
7 changed files with 46 additions and 34 deletions

28
main.go
View File

@ -4,9 +4,7 @@ import (
"flag"
"log"
"os"
"os/signal"
"path/filepath"
"syscall"
)
func ParseFlags() (string, error) {
@ -44,7 +42,7 @@ func main() {
cfg := NewConfig(cfgPath)
log := NewLog()
log.Info("Running FlexDXCluster version 0.1")
log.Info("Running FlexDXCluster version 0.2")
log.Infof("Callsign: %s", cfg.SQLite.Callsign)
DeleteDatabase("./flex.sqlite", log)
@ -65,32 +63,10 @@ func main() {
FlexClient := NewFlexClient(*fRepo, TCPServer, TCPClient.SpotChanToFlex)
// HTTPServer := NewHTTPServer(*cRepo, *fRepo, TCPServer, TCPClient.SpotChanToHTTPServer)
sigCh := make(chan os.Signal, 1)
signal.Notify(sigCh, syscall.SIGHUP, syscall.SIGINT, syscall.SIGQUIT, syscall.SIGTERM)
go FlexClient.StartFlexClient()
go TCPClient.StartClient()
go TCPServer.StartServer()
// Gracely closing all connextions if signal is received
for sig := range sigCh {
log.Infof("received signal: %v, shutting down all connections.", sig)
TCPClient.Close()
TCPServer.Conn.Close()
FlexClient.Conn.Close()
if err := fRepo.db.Close(); err != nil {
log.Error("failed to close the database connection properly")
os.Exit(1)
}
if err := cRepo.db.Close(); err != nil {
log.Error("failed to close Log4OM database connection properly")
os.Exit(1)
}
os.Exit(0)
}
CheckSignal(TCPClient, TCPServer, FlexClient, fRepo, cRepo)
}