From c209e4457457edc042f063390c9a222a694f3a6d Mon Sep 17 00:00:00 2001 From: Derrick Anderson Date: Mon, 12 Feb 2018 16:01:02 -0500 Subject: revert master changes --- cmd/platform/server.go | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) (limited to 'cmd/platform/server.go') diff --git a/cmd/platform/server.go b/cmd/platform/server.go index 1b411cf20..e3742cef6 100644 --- a/cmd/platform/server.go +++ b/cmd/platform/server.go @@ -42,11 +42,10 @@ func runServerCmd(cmd *cobra.Command, args []string) error { disableConfigWatch, _ := cmd.Flags().GetBool("disableconfigwatch") - interruptChan := make(chan os.Signal, 1) - return runServer(config, disableConfigWatch, interruptChan) + return runServer(config, disableConfigWatch) } -func runServer(configFileLocation string, disableConfigWatch bool, interruptChan chan os.Signal) error { +func runServer(configFileLocation string, disableConfigWatch bool) error { options := []app.Option{app.ConfigFile(configFileLocation)} if disableConfigWatch { options = append(options, app.DisableConfigWatch) @@ -54,7 +53,7 @@ func runServer(configFileLocation string, disableConfigWatch bool, interruptChan a, err := app.New(options...) if err != nil { - l4g.Critical(err.Error()) + l4g.Error(err.Error()) return err } defer a.Shutdown() @@ -88,12 +87,7 @@ func runServer(configFileLocation string, disableConfigWatch bool, interruptChan } }) - serverErr := a.StartServer() - if serverErr != nil { - l4g.Critical(serverErr.Error()) - return serverErr - } - + a.StartServer() api4.Init(a, a.Srv.Router, false) api3 := api.Init(a, a.Srv.Router) wsapi.Init(a, a.Srv.WebSocketRouter) @@ -166,8 +160,9 @@ func runServer(configFileLocation string, disableConfigWatch bool, interruptChan // wait for kill signal before attempting to gracefully shutdown // the running service - signal.Notify(interruptChan, os.Interrupt, syscall.SIGINT, syscall.SIGTERM) - <-interruptChan + c := make(chan os.Signal, 1) + signal.Notify(c, os.Interrupt, syscall.SIGINT, syscall.SIGTERM) + <-c if a.Cluster != nil { a.Cluster.StopInterNodeCommunication() -- cgit v1.2.3-1-g7c22 From e43f381764bdf29117760b26c88fd37b716e67b2 Mon Sep 17 00:00:00 2001 From: Derrick Anderson Date: Tue, 13 Feb 2018 23:46:49 -0500 Subject: gofmt --- cmd/platform/server.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cmd/platform/server.go') diff --git a/cmd/platform/server.go b/cmd/platform/server.go index 0421fcc05..1b411cf20 100644 --- a/cmd/platform/server.go +++ b/cmd/platform/server.go @@ -93,7 +93,7 @@ func runServer(configFileLocation string, disableConfigWatch bool, interruptChan l4g.Critical(serverErr.Error()) return serverErr } - + api4.Init(a, a.Srv.Router, false) api3 := api.Init(a, a.Srv.Router) wsapi.Init(a, a.Srv.WebSocketRouter) -- cgit v1.2.3-1-g7c22 From 44a27125de1b4658f1149f5bc459468a056b4d7d Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Wed, 14 Feb 2018 23:48:06 +0530 Subject: Wait for goroutines to finish before shuting down server (#8259) When running server tests, the server will exit while some jobs spawned through a goroutine are still running. This may crash the test harness, as the jobs try to access a shut down app instance. Fortunately the fix is easy: we just have to use the same App goroutine-counting facility than the rest of the method's goroutines. --- cmd/platform/server.go | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'cmd/platform/server.go') diff --git a/cmd/platform/server.go b/cmd/platform/server.go index 1b411cf20..80b38401e 100644 --- a/cmd/platform/server.go +++ b/cmd/platform/server.go @@ -130,11 +130,21 @@ func runServer(configFileLocation string, disableConfigWatch bool, interruptChan a.EnsureDiagnosticId() - go runSecurityJob(a) - go runDiagnosticsJob(a) - go runSessionCleanupJob(a) - go runTokenCleanupJob(a) - go runCommandWebhookCleanupJob(a) + a.Go(func() { + runSecurityJob(a) + }) + a.Go(func() { + runDiagnosticsJob(a) + }) + a.Go(func() { + runSessionCleanupJob(a) + }) + a.Go(func() { + runTokenCleanupJob(a) + }) + a.Go(func() { + runCommandWebhookCleanupJob(a) + }) if complianceI := a.Compliance; complianceI != nil { complianceI.StartComplianceDailyJob() -- cgit v1.2.3-1-g7c22 From b112747de76f9c11c4d8083207049fac6e435019 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Fri, 16 Feb 2018 06:17:03 +0530 Subject: Send systemd READY notification (#8296) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently, when starting Mattermost programmatically, it's hard to tell when the server is actually ready to receive network connections. This isn't convenient for monitoring (the systemd service status is "running" although the server is still booting), nor for programatic use (where a script would need to know when the server is ready to perform further actions). To improve this, systemd allow processes to tell when they started successfully. The launcher waits for this notification before reporting the service as successfully launched. The way processes notify systemd is by sending a `READY=1` string over a standard unix socket, whose path is provided in an environment var. The systemd service is then told to expect this notification: ```diff [Service] -Type=simple +Type=notify ExecStart=/home/vagrant/go/bin/platform ``` Now, when starting the server, systemd will actually wait for the server to be ready before returning the control to the shell. Additionally, during this time, querying the server status with `service mattermost status` will report the service as "activating" – before transitioning to "running" when the server is ready. --- cmd/platform/server.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'cmd/platform/server.go') diff --git a/cmd/platform/server.go b/cmd/platform/server.go index 80b38401e..31606e6eb 100644 --- a/cmd/platform/server.go +++ b/cmd/platform/server.go @@ -4,6 +4,7 @@ package main import ( + "net" "os" "os/signal" "syscall" @@ -174,6 +175,8 @@ func runServer(configFileLocation string, disableConfigWatch bool, interruptChan a.Jobs.StartSchedulers() } + notifyReady() + // wait for kill signal before attempting to gracefully shutdown // the running service signal.Notify(interruptChan, os.Interrupt, syscall.SIGINT, syscall.SIGTERM) @@ -244,6 +247,35 @@ func doDiagnostics(a *app.App) { } } +func notifyReady() { + // If the environment vars provide a systemd notification socket, + // notify systemd that the server is ready. + systemdSocket := os.Getenv("NOTIFY_SOCKET") + if systemdSocket != "" { + l4g.Info("Sending systemd READY notification.") + + err := sendSystemdReadyNotification(systemdSocket) + if err != nil { + l4g.Error(err.Error()) + } + } +} + +func sendSystemdReadyNotification(socketPath string) error { + msg := "READY=1" + addr := &net.UnixAddr{ + Name: socketPath, + Net: "unixgram", + } + conn, err := net.DialUnix(addr.Net, nil, addr) + if err != nil { + return err + } + defer conn.Close() + _, err = conn.Write([]byte(msg)) + return err +} + func doTokenCleanup(a *app.App) { a.Srv.Store.Token().Cleanup() } -- cgit v1.2.3-1-g7c22