diff --git a/awx/api/management/commands/uses_mongo.py b/awx/api/management/commands/uses_mongo.py index fae7a77c34..ab61e7cae4 100644 --- a/awx/api/management/commands/uses_mongo.py +++ b/awx/api/management/commands/uses_mongo.py @@ -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')