From 185ed89978e0d88d75b5c606104e78058753bd4d Mon Sep 17 00:00:00 2001 From: George Goldberg Date: Thu, 26 Jul 2018 15:50:38 +0100 Subject: MM-11243: Make Elasticsearch work after enabling without restart. (#9146) * MM-11243: Make Elasticsearch work after enabling without restart. * Also cope with config vars changing whilst enabled. --- app/app.go | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) (limited to 'app/app.go') diff --git a/app/app.go b/app/app.go index fb1fc725b..6da16c28c 100644 --- a/app/app.go +++ b/app/app.go @@ -680,3 +680,54 @@ func (a *App) DoEmojisPermissionsMigration() { mlog.Critical(fmt.Sprint(result.Err)) } } + +func (a *App) StartElasticsearch() { + a.Go(func() { + if err := a.Elasticsearch.Start(); err != nil { + mlog.Error(err.Error()) + } + }) + + a.AddConfigListener(func(oldConfig *model.Config, newConfig *model.Config) { + if *oldConfig.ElasticsearchSettings.EnableIndexing == false && *newConfig.ElasticsearchSettings.EnableIndexing == true { + a.Go(func() { + if err := a.Elasticsearch.Start(); err != nil { + mlog.Error(err.Error()) + } + }) + } else if *oldConfig.ElasticsearchSettings.EnableIndexing == true && *newConfig.ElasticsearchSettings.EnableIndexing == false { + a.Go(func() { + if err := a.Elasticsearch.Stop(); err != nil { + mlog.Error(err.Error()) + } + }) + } else if *oldConfig.ElasticsearchSettings.Password != *newConfig.ElasticsearchSettings.Password || *oldConfig.ElasticsearchSettings.Username != *newConfig.ElasticsearchSettings.Username || *oldConfig.ElasticsearchSettings.ConnectionUrl != *newConfig.ElasticsearchSettings.ConnectionUrl || *oldConfig.ElasticsearchSettings.Sniff != *newConfig.ElasticsearchSettings.Sniff { + a.Go(func() { + if *oldConfig.ElasticsearchSettings.EnableIndexing == true { + if err := a.Elasticsearch.Stop(); err != nil { + mlog.Error(err.Error()) + } + if err := a.Elasticsearch.Start(); err != nil { + mlog.Error(err.Error()) + } + } + }) + } + }) + + a.AddLicenseListener(func() { + if a.License() != nil { + a.Go(func() { + if err := a.Elasticsearch.Start(); err != nil { + mlog.Error(err.Error()) + } + }) + } else { + a.Go(func() { + if err := a.Elasticsearch.Stop(); err != nil { + mlog.Error(err.Error()) + } + }) + } + }) +} -- cgit v1.2.3-1-g7c22