diff --git a/plugins/analysis/plugin.go b/plugins/analysis/plugin.go index f7ffdbc3d92124766afabe84db64a0b7938ba685..0208ca1d915ff881849159c7402d4103dd3350e3 100644 --- a/plugins/analysis/plugin.go +++ b/plugins/analysis/plugin.go @@ -5,8 +5,6 @@ import ( "github.com/iotaledger/goshimmer/plugins/analysis/client" "github.com/iotaledger/goshimmer/plugins/analysis/server" "github.com/iotaledger/goshimmer/plugins/analysis/webinterface" - "github.com/iotaledger/hive.go/daemon" - "github.com/iotaledger/hive.go/events" "github.com/iotaledger/hive.go/logger" "github.com/iotaledger/hive.go/node" ) @@ -18,10 +16,6 @@ func configure(plugin *node.Plugin) { if parameter.NodeConfig.GetInt(server.CFG_SERVER_PORT) != 0 { webinterface.Configure(plugin) server.Configure(plugin) - - daemon.Events.Shutdown.Attach(events.NewClosure(func() { - server.Shutdown(plugin) - })) } } @@ -35,7 +29,6 @@ func run(plugin *node.Plugin) { if parameter.NodeConfig.GetString(client.CFG_SERVER_ADDRESS) != "" { client.Run(plugin) - log.Info("Stopping Analysis-Client ... done") } else { log.Info("Starting Plugin: Analysis ... client is disabled (server-address is empty)") } diff --git a/plugins/analysis/server/plugin.go b/plugins/analysis/server/plugin.go index 4f67de7d0ea6aa94bf0edfaee92fbe4302433b4b..40fabc28ac500b4d1203f3d0aa5e0232b10b5c08 100644 --- a/plugins/analysis/server/plugin.go +++ b/plugins/analysis/server/plugin.go @@ -41,14 +41,16 @@ func Configure(plugin *node.Plugin) { func Run(plugin *node.Plugin) { daemon.BackgroundWorker("Analysis Server", func(shutdownSignal <-chan struct{}) { log.Infof("Starting Server (port %d) ... done", parameter.NodeConfig.GetInt(CFG_SERVER_PORT)) - server.Listen(parameter.NodeConfig.GetInt(CFG_SERVER_PORT)) + go server.Listen(parameter.NodeConfig.GetInt(CFG_SERVER_PORT)) + <-shutdownSignal + Shutdown() }) } -func Shutdown(plugin *node.Plugin) { +func Shutdown() { log.Info("Stopping Server ...") - server.Shutdown() + log.Info("Stopping Server ... done") } func HandleConnection(conn *network.ManagedConnection) { diff --git a/plugins/analysis/webinterface/httpserver/plugin.go b/plugins/analysis/webinterface/httpserver/plugin.go index 20051f0f1aadd4ee31821880c94afe4ac6654103..0299e173ed36d9e4ec983781e96a1a9a6e8bb3ac 100644 --- a/plugins/analysis/webinterface/httpserver/plugin.go +++ b/plugins/analysis/webinterface/httpserver/plugin.go @@ -5,7 +5,6 @@ import ( "time" "github.com/iotaledger/hive.go/daemon" - "github.com/iotaledger/hive.go/events" "github.com/iotaledger/hive.go/node" "golang.org/x/net/context" "golang.org/x/net/websocket" @@ -22,17 +21,14 @@ func Configure(plugin *node.Plugin) { router.Handle("/datastream", websocket.Handler(dataStream)) router.HandleFunc("/", index) - - daemon.Events.Shutdown.Attach(events.NewClosure(func() { - ctx, cancel := context.WithTimeout(context.Background(), 0*time.Second) - defer cancel() - - httpServer.Shutdown(ctx) - })) } func Run(plugin *node.Plugin) { daemon.BackgroundWorker("Analysis HTTP Server", func(shutdownSignal <-chan struct{}) { - httpServer.ListenAndServe() + go httpServer.ListenAndServe() + <-shutdownSignal + ctx, cancel := context.WithTimeout(context.Background(), 0*time.Second) + defer cancel() + httpServer.Shutdown(ctx) }) } diff --git a/plugins/bundleprocessor/plugin.go b/plugins/bundleprocessor/plugin.go index d7f6dbb7bd9f2c0b9cd1d4e5f230ed3746151375..c95eeeed59c95ed7cd85cb82dc72f1278cf994c6 100644 --- a/plugins/bundleprocessor/plugin.go +++ b/plugins/bundleprocessor/plugin.go @@ -23,16 +23,6 @@ func configure(plugin *node.Plugin) { Events.Error.Attach(events.NewClosure(func(err errors.IdentifiableError) { log.Error(err.Error()) })) - - daemon.Events.Shutdown.Attach(events.NewClosure(func() { - log.Info("Stopping Bundle Processor ...") - - workerPool.Stop() - - log.Info("Stopping Value Bundle Processor ...") - - valueBundleProcessorWorkerPool.Stop() - })) } func run(plugin *node.Plugin) { @@ -40,7 +30,10 @@ func run(plugin *node.Plugin) { daemon.BackgroundWorker("Bundle Processor", func(shutdownSignal <-chan struct{}) { log.Info("Starting Bundle Processor ... done") - workerPool.Run() + workerPool.Start() + <-shutdownSignal + log.Info("Stopping Bundle Processor ...") + workerPool.Stop() log.Info("Stopping Bundle Processor ... done") }) @@ -48,7 +41,10 @@ func run(plugin *node.Plugin) { daemon.BackgroundWorker("Value Bundle Processor", func(shutdownSignal <-chan struct{}) { log.Info("Starting Value Bundle Processor ... done") - valueBundleProcessorWorkerPool.Run() + valueBundleProcessorWorkerPool.Start() + <-shutdownSignal + log.Info("Stopping Value Bundle Processor ...") + valueBundleProcessorWorkerPool.Stop() log.Info("Stopping Value Bundle Processor ... done") }) } diff --git a/plugins/dashboard/plugin.go b/plugins/dashboard/plugin.go index 708a801e35f959508b21c3239c4465d9b86c1ef5..f263b4b88a1daae71811f16fa8c92c85e52e665e 100644 --- a/plugins/dashboard/plugin.go +++ b/plugins/dashboard/plugin.go @@ -33,13 +33,6 @@ func configure(plugin *node.Plugin) { TPSQ = TPSQ[1:] } })) - - daemon.Events.Shutdown.Attach(events.NewClosure(func() { - ctx, cancel := context.WithTimeout(context.Background(), 0*time.Second) - defer cancel() - - _ = server.Shutdown(ctx) - })) } func run(plugin *node.Plugin) { @@ -49,5 +42,10 @@ func run(plugin *node.Plugin) { log.Error(err.Error()) } }() + + <-shutdownSignal + ctx, cancel := context.WithTimeout(context.Background(), 0*time.Second) + defer cancel() + _ = server.Shutdown(ctx) }) } diff --git a/plugins/statusscreen/statusscreen.go b/plugins/statusscreen/statusscreen.go index 06057fd4a6f4c6d0b095b1352b4b58153d13f446..e488b59ac4510acd94cc3fce2e54597aaec62a0d 100644 --- a/plugins/statusscreen/statusscreen.go +++ b/plugins/statusscreen/statusscreen.go @@ -36,14 +36,14 @@ func configure(plugin *node.Plugin) { }) logger.Events.AnyMsg.Attach(anyLogMsgClosure) - daemon.Events.Shutdown.Attach(events.NewClosure(func() { + daemon.BackgroundWorker("UI-Detach", func(shutdownSignal <-chan struct{}) { + <-shutdownSignal logger.InjectWriters(os.Stdout) logger.Events.AnyMsg.Detach(anyLogMsgClosure) - if app != nil { app.Stop() } - })) + }, 1) } func run(plugin *node.Plugin) { diff --git a/plugins/tangle/solidifier.go b/plugins/tangle/solidifier.go index de2526d6cebd4556cd2da861e4b588fb17bdb8ac..af7b07c525bde46ee7cf1b047aa300b129b09ac6 100644 --- a/plugins/tangle/solidifier.go +++ b/plugins/tangle/solidifier.go @@ -44,11 +44,6 @@ func configureSolidifier(plugin *node.Plugin) { workerPool.Submit(metaTx) })) - - daemon.Events.Shutdown.Attach(events.NewClosure(func() { - log.Info("Stopping Solidifier ...") - workerPool.Stop() - })) } func runSolidifier(plugin *node.Plugin) { @@ -56,7 +51,10 @@ func runSolidifier(plugin *node.Plugin) { daemon.BackgroundWorker("Tangle Solidifier", func(shutdownSignal <-chan struct{}) { log.Info("Starting Solidifier ... done") - workerPool.Run() + workerPool.Start() + <-shutdownSignal + log.Info("Stopping Solidifier ...") + workerPool.Stop() log.Info("Stopping Solidifier ... done") }) } diff --git a/plugins/webapi/plugin.go b/plugins/webapi/plugin.go index 4d3177ee78215f457cc29793926d637ba2eb9ed8..e7d7c5a32fc1478c5fa59d25cd1251dc9c16bfb3 100644 --- a/plugins/webapi/plugin.go +++ b/plugins/webapi/plugin.go @@ -5,7 +5,6 @@ import ( "time" "github.com/iotaledger/hive.go/daemon" - "github.com/iotaledger/hive.go/events" "github.com/iotaledger/hive.go/logger" "github.com/iotaledger/hive.go/node" "github.com/labstack/echo" @@ -20,17 +19,6 @@ func configure(plugin *node.Plugin) { Server.HideBanner = true Server.HidePort = true Server.GET("/", IndexRequest) - - daemon.Events.Shutdown.Attach(events.NewClosure(func() { - log.Info("Stopping Web Server ...") - - ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second) - defer cancel() - - if err := Server.Shutdown(ctx); err != nil { - log.Errorf("Couldn't stop server cleanly: %s", err.Error()) - } - })) } func run(plugin *node.Plugin) { @@ -39,8 +27,20 @@ func run(plugin *node.Plugin) { daemon.BackgroundWorker("WebAPI Server", func(shutdownSignal <-chan struct{}) { log.Info("Starting Web Server ... done") - if err := Server.Start(":8080"); err != nil { - log.Info("Stopping Web Server ... done") + go func() { + if err := Server.Start(":8080"); err != nil { + log.Info("Stopping Web Server ... done") + } + }() + + <-shutdownSignal + + log.Info("Stopping Web Server ...") + ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second) + defer cancel() + + if err := Server.Shutdown(ctx); err != nil { + log.Errorf("Couldn't stop server cleanly: %s", err.Error()) } }) } diff --git a/plugins/zeromq/plugin.go b/plugins/zeromq/plugin.go index aa547901ae53806938b8fcf805744aaa70138a47..c9d469a85a6df97ec4b38379062a90447e1f58f6 100644 --- a/plugins/zeromq/plugin.go +++ b/plugins/zeromq/plugin.go @@ -22,17 +22,6 @@ var emptyTag = strings.Repeat("9", 27) // Configure the zeromq plugin func configure(plugin *node.Plugin) { - - daemon.Events.Shutdown.Attach(events.NewClosure(func() { - log.Info("Stopping ZeroMQ Publisher ...") - - if err := publisher.Shutdown(); err != nil { - log.Errorf("Stopping ZeroMQ Publisher: %s", err.Error()) - } else { - log.Info("Stopping ZeroMQ Publisher ... done") - } - })) - tangle.Events.TransactionStored.Attach(events.NewClosure(func(tx *value_transaction.ValueTransaction) { // create goroutine for every event go func() { @@ -54,6 +43,15 @@ func run(plugin *node.Plugin) { } else { log.Infof("Starting ZeroMQ Publisher (port %d) ... done", zeromqPort) } + + <-shutdownSignal + + log.Info("Stopping ZeroMQ Publisher ...") + if err := publisher.Shutdown(); err != nil { + log.Errorf("Stopping ZeroMQ Publisher: %s", err.Error()) + } else { + log.Info("Stopping ZeroMQ Publisher ... done") + } }) }