summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeorge Goldberg <george@gberg.me>2018-07-26 15:50:38 +0100
committerGitHub <noreply@github.com>2018-07-26 15:50:38 +0100
commit185ed89978e0d88d75b5c606104e78058753bd4d (patch)
treef7950dbbc6f429618f7bb0aa45ccdf613b8afc19
parent8948b91d7a80169b12907e16581cfdd53bbb73f1 (diff)
downloadchat-185ed89978e0d88d75b5c606104e78058753bd4d.tar.gz
chat-185ed89978e0d88d75b5c606104e78058753bd4d.tar.bz2
chat-185ed89978e0d88d75b5c606104e78058753bd4d.zip
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.
-rw-r--r--app/app.go51
-rw-r--r--cmd/mattermost/commands/server.go6
-rw-r--r--einterfaces/elasticsearch.go1
-rw-r--r--i18n/en.json8
4 files changed, 61 insertions, 5 deletions
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())
+ }
+ })
+ }
+ })
+}
diff --git a/cmd/mattermost/commands/server.go b/cmd/mattermost/commands/server.go
index 1fab5c83a..1c33505f5 100644
--- a/cmd/mattermost/commands/server.go
+++ b/cmd/mattermost/commands/server.go
@@ -176,11 +176,7 @@ func runServer(configFileLocation string, disableConfigWatch bool, usedPlatform
}
if a.Elasticsearch != nil {
- a.Go(func() {
- if err := a.Elasticsearch.Start(); err != nil {
- mlog.Error(err.Error())
- }
- })
+ a.StartElasticsearch()
}
if *a.Config().JobSettings.RunJobs {
diff --git a/einterfaces/elasticsearch.go b/einterfaces/elasticsearch.go
index 1b7444b2b..bf24dc577 100644
--- a/einterfaces/elasticsearch.go
+++ b/einterfaces/elasticsearch.go
@@ -11,6 +11,7 @@ import (
type ElasticsearchInterface interface {
Start() *model.AppError
+ Stop() *model.AppError
IndexPost(post *model.Post, teamId string) *model.AppError
SearchPosts(channels *model.ChannelList, searchParams []*model.SearchParams) ([]string, model.PostSearchMatches, *model.AppError)
DeletePost(post *model.Post) *model.AppError
diff --git a/i18n/en.json b/i18n/en.json
index 986dfc81b..9ed77b07d 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -168,6 +168,14 @@
"translation": "Channel is already deleted"
},
{
+ "id": "ent.elasticsearch.start.already_started.app_error",
+ "translation": "Elasticsearch is already started"
+ },
+ {
+ "id": "ent.elasticsearch.stop.already_stopped.app_error",
+ "translation": "Elasticsearch is already stopped"
+ },
+ {
"id": "api.channel.join_channel.permissions.app_error",
"translation": "You do not have the appropriate permissions"
},