-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Elasticsearch stop/start/restart #1990
Merged
Changes from 21 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
b923dd9
Add action tags
pr33thi 54ddeac
Create framework for new elasticsearch commands
pr33thi d8ef759
Move everything into plays, call the play instead of the module directly
pr33thi c02a114
Call es_rolling_restart when elasticsearch service command is called
pr33thi 5cd16e9
[pv-deploy] Created new encrypted secrets file
pr33thi aeb21b2
Stop and start pillows along with es
pr33thi 5a25dc6
Exit if error in stopping/starting pillows
pr33thi 7ec1c42
Cleanup
pr33thi 80d21be
Remove debug statement
pr33thi 9fa7e23
Rename es_instances to es_pids
pr33thi bed0323
Use the cli ask function
pr33thi e9e1724
Change indentation level of ask prompt
pr33thi db13c7e
Merge branch 'master' into pv/es-2
pr33thi 786e839
Change elif to if so that both get hit for restarts
pr33thi 9328828
Fix process killing
pr33thi 4de9d7b
Remove .travis/secrets.tar.enc
pr33thi 2222719
Remove restart-elasticsearch
pr33thi ecdfce5
Update docs
pr33thi 6fe068b
Add back the origin secrets.tar.enc file
pr33thi 9a8c2ae
Start es before pillows, and consolidate pillow code
pr33thi 26605f1
Use stop and start strings instead of the action variable, for restart
pr33thi beb719c
Merge branch 'master' into pv/es-2
pr33thi ba1d401
Specify the Pillow service directly
pr33thi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,7 +78,7 @@ [email protected]:~$ commcare-cloud -h | |
usage: commcare-cloud [-h] [--control] | ||
|
||
{64-test,development,echis,icds,icds-new,pna,production,softlayer,staging,swiss} | ||
{bootstrap-users,ansible-playbook,django-manage,aps,tmux,ap,validate-environment-settings,restart-elasticsearch,deploy-stack,service,update-supervisor-confs,update-users,ping,migrate_couchdb,lookup,run-module,update-config,mosh,after-reboot,ssh,downtime,fab,update-local-known-hosts,migrate-couchdb,run-shell-command} | ||
{bootstrap-users,ansible-playbook,django-manage,aps,tmux,ap,validate-environment-settings,deploy-stack,service,update-supervisor-confs,update-users,ping,migrate_couchdb,lookup,run-module,update-config,mosh,after-reboot,ssh,downtime,fab,update-local-known-hosts,migrate-couchdb,run-shell-command} | ||
... | ||
|
||
``` | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
from abc import ABCMeta, abstractmethod, abstractproperty | ||
from collections import defaultdict, OrderedDict | ||
from itertools import groupby | ||
import sys | ||
|
||
import attr | ||
import six | ||
|
@@ -14,6 +15,7 @@ | |
get_celery_workers, | ||
get_pillowtop_processes | ||
) | ||
from commcare_cloud.cli_utils import ask | ||
from commcare_cloud.commands.ansible.run_module import run_ansible_module | ||
from commcare_cloud.commands.command_base import CommandBase, Argument | ||
from commcare_cloud.environment.main import get_environment | ||
|
@@ -274,10 +276,54 @@ class Nginx(AnsibleService): | |
inventory_groups = ['proxy'] | ||
|
||
|
||
class Elasticsearch(AnsibleService): | ||
class ElasticsearchClassic(AnsibleService): | ||
name = 'elasticsearch-classic' | ||
service_name = 'elasticsearch' | ||
inventory_groups = ['elasticsearch'] | ||
|
||
|
||
class Elasticsearch(ServiceBase): | ||
name = 'elasticsearch' | ||
service_name = 'elasticsearch' | ||
inventory_groups = ['elasticsearch'] | ||
|
||
def execute_action(self, action, host_pattern=None, process_pattern=None): | ||
if action == 'status': | ||
return ElasticsearchClassic(self.environment, self.ansible_context).execute_action(action, host_pattern, process_pattern) | ||
else: | ||
if not ask( | ||
"This function does more than stop and start the elasticsearch service. " | ||
"For that, use elasticsearch-classic." | ||
"\nStop will: stop pillows, stop es, and kill -9 if any processes still exist " | ||
"after a period of time. " | ||
"\nStart will start pillows and start elasticsearch " | ||
"\nRestart is a stop followed by a start.\n Continue?", strict=False): | ||
return 0 # exit code | ||
if action == 'stop' or action == 'restart': | ||
self._act_on_pillows(action='stop') | ||
self._run_rolling_restart_yml(tags='action_stop') | ||
|
||
if action == 'start' or action == 'restart': | ||
self._run_rolling_restart_yml(tags='action_start') | ||
self._act_on_pillows(action='start') | ||
|
||
def _act_on_pillows(self, action): | ||
# Used to stop or start pillows | ||
ansible_context = AnsibleContext(None) | ||
service = SERVICES_BY_NAME['pillowtop'](self.environment, ansible_context) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any reason not to reference it directly rather than looking it up in the dict? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good idea, ba1d401 |
||
exit_code = service.run(action=action) | ||
if not exit_code == 0: | ||
print("ERROR while trying to {} pillows. Exiting.".format(action)) | ||
sys.exit(1) | ||
|
||
def _run_rolling_restart_yml(self, tags): | ||
from commcare_cloud.commands.ansible.ansible_playbook import run_ansible_playbook | ||
run_ansible_playbook(environment=self.environment, | ||
playbook='es_rolling_restart.yml', | ||
ansible_context=AnsibleContext(args=None), | ||
unknown_args=['--tags={}'.format(tags)], | ||
skip_check=True) | ||
|
||
|
||
class Couchdb(AnsibleService): | ||
name = 'couchdb' | ||
|
@@ -491,6 +537,7 @@ def get_processes_by_host(all_hosts, process_descriptors, process_pattern=None): | |
Couchdb2, | ||
RabbitMq, | ||
Elasticsearch, | ||
ElasticsearchClassic, | ||
Redis, | ||
Riakcs, | ||
Kafka, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it looks like elasticsearch is being started after pillows are started if i'm reading this correctly. we probably want to start elasticsearch first, and then start pillows
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How come we want to do it in that order?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
most pillows populate data into elasticsearch, so for the time between the pillows starting and es starting, the pillows will just be creating errors. they will retry eventually but there's no point to starting a service if the service it depends on is down
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense, done here: 9a8c2ae
(also refactored the pillow start/stop code in there)