up
This commit is contained in:
30
utils.go
30
utils.go
@ -2,7 +2,10 @@ package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
"os/signal"
|
||||
"strconv"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
func FreqMhztoHz(freq string) string {
|
||||
@ -26,3 +29,30 @@ func FreqHztoMhz(freq string) string {
|
||||
|
||||
return strconv.FormatFloat(frequency, 'f', 6, 64)
|
||||
}
|
||||
|
||||
func CheckSignal(TCPClient *TCPClient, TCPServer *TCPServer, FlexClient *FlexClient, fRepo *FlexDXClusterRepository, cRepo *Log4OMContactsRepository) {
|
||||
|
||||
sigCh := make(chan os.Signal, 1)
|
||||
signal.Notify(sigCh, syscall.SIGHUP, syscall.SIGINT, syscall.SIGQUIT, syscall.SIGTERM)
|
||||
|
||||
// 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)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user