Stricter control of mongo in setup playbook

Detect if this is an HA setup and if so we won't attempt to start mongo
during the setup process
This commit is contained in:
Matthew Jones 2015-07-08 13:45:59 -04:00
parent 1368403309
commit d5e948890c

View File

@ -3,8 +3,9 @@
import sys
from optparse import make_option
from django.core.management.base import BaseCommand
from awx.main.models import Instance
from awx.main.task_engine import TaskSerializer
@ -15,7 +16,16 @@ class Command(BaseCommand):
This script is intended to be used by bash and init scripts to
conditionally start MongoDB, so its focus is on being bash-friendly.
"""
def handle(self, **kwargs):
def __init__(self):
super(Command, self).__init__()
BaseCommand.option_list += (make_option('--local',
dest='local',
default=False,
action="store_true",
help="Only check if mongo should be running locally"),)
def handle(self, *args, **kwargs):
# Get the license data.
license_reader = TaskSerializer()
license_data = license_reader.from_file()
@ -33,10 +43,12 @@ class Command(BaseCommand):
# Okay, do we need MongoDB to be turned on?
# This is a silly variable assignment right now, but I expect the
# rules here will grow more complicated over time.
# FIXME: Most likely this should be False if HA is active
# (not just enabled by license, but actually in use).
uses_mongo = system_tracking # noqa
if Instance.objects.count() > 1 and kwargs['local'] and uses_mongo:
print("HA Configuration detected. Database should be remote")
uses_mongo = False
# If we do not need Mongo, return a non-zero exit status.
if not uses_mongo:
print('MongoDB NOT required')