diff options
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/redq/main.go | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/cmd/redq/main.go b/cmd/redq/main.go index 8807105..df275d6 100644 --- a/cmd/redq/main.go +++ b/cmd/redq/main.go @@ -4,10 +4,13 @@ import ( "context" "log" "net" + "os" + "os/signal" + "syscall" "github.com/jackc/pgx/v5" - "sinanmohd.com/redq/usage" "sinanmohd.com/redq/db" + "sinanmohd.com/redq/usage" ) func main() { @@ -15,6 +18,7 @@ func main() { Data : make(usage.UsageMap), } + iface, err := net.InterfaceByName("wlan0") if err != nil { log.Fatalf("lookup network: %s", err) @@ -28,5 +32,16 @@ func main() { defer conn.Close(ctx) queries := db.New(conn) + sigs := make(chan os.Signal, 1) + signal.Notify(sigs, os.Interrupt, os.Kill, syscall.SIGTERM) + go func () { + <- sigs + err := u.UpdateDb(queries, ctx, false) + if err != nil { + log.Printf("updating Database: %s", err) + } + os.Exit(0) + }() + u.Run(iface, queries, ctx) } |