diff --git a/go.mod b/go.mod index 5db8c00..0cf9e48 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,6 @@ module github.com/xeptore/wireuse go 1.20 require ( - github.com/fsnotify/fsnotify v1.6.0 github.com/golang/mock v1.6.0 github.com/joho/godotenv v1.5.1 github.com/rs/zerolog v1.29.0 diff --git a/go.sum b/go.sum index 3e72ae4..9fbc0f8 100644 --- a/go.sum +++ b/go.sum @@ -2,8 +2,6 @@ github.com/coreos/go-systemd/v22 v22.3.3-0.20220203105225-a9a7ef127534/go.mod h1 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY= -github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc= github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs= @@ -108,7 +106,6 @@ golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= diff --git a/ingest/cmd/main.go b/ingest/cmd/main.go index e4149cf..52cb2fa 100644 --- a/ingest/cmd/main.go +++ b/ingest/cmd/main.go @@ -11,7 +11,6 @@ import ( "syscall" "time" - "github.com/fsnotify/fsnotify" "github.com/joho/godotenv" "github.com/rs/zerolog" "go.mongodb.org/mongo-driver/bson" @@ -28,9 +27,8 @@ import ( ) var ( - restartMarkFileName string - wgDeviceName string - wgPreDownDumpFileName string + restartMarkFileName string + wgDeviceName string ) func main() { @@ -53,7 +51,6 @@ func main() { flag.StringVar(&restartMarkFileName, "r", "", "restart-mark file name") flag.StringVar(&wgDeviceName, "i", "", "wireguard interface") - flag.StringVar(&wgPreDownDumpFileName, "d", "", "wireguard pre-down dumped output file") flag.Parse() if nonFlagArgs := flag.Args(); len(nonFlagArgs) > 0 { @@ -79,7 +76,9 @@ func main() { log.Fatal().Err(err).Msg("failed to verify database connectivity") } defer func() { - if err := client.Disconnect(ctx); err != nil { + disconnectCtx, cancel := context.WithTimeout(context.Background(), 4*time.Second) + defer cancel() + if err := client.Disconnect(disconnectCtx); err != nil { log.Err(err).Msg("failed to disconnect from database") return } @@ -95,24 +94,11 @@ func main() { signals := make(chan os.Signal, 1) signal.Notify(signals, syscall.SIGINT) - ctx, cancel := context.WithCancelCause(ctx) + runCtx, cancelEngineRun := context.WithCancelCause(ctx) stopSignalErr := errors.New("stop signal received") go func() { <-signals - cancel(stopSignalErr) - }() - - go func() { - if wgPreDownDumpFileName == "" { - return - } - - watcher, err := fsnotify.NewWatcher() - if err != nil { - log.Fatal().Err(err).Msg("failed to initialize wireguard pre-down dump file watcher") - } - defer watcher.Close() - watcher.Add("") + cancelEngineRun(stopSignalErr) }() timeTicker := time.NewTicker(5 * time.Second) @@ -127,10 +113,10 @@ func main() { wp := wgPeers{wg} store := storeMongo{collection} engine := ingest.NewEngine(&rmf, &wp, &store, log) - if err := engine.Run(ctx, engineTicker, restartMarkFileName); nil != err { - if err := ctx.Err(); nil != err { + if err := engine.Run(runCtx, engineTicker, restartMarkFileName); nil != err { + if err := runCtx.Err(); nil != err { if errors.Is(err, context.Canceled) { - if errors.Is(context.Cause(ctx), stopSignalErr) { + if errors.Is(context.Cause(runCtx), stopSignalErr) { log.Info().Msg("root context was canceled due to receiving a interrupt signal") return }