mirror of
https://github.com/ansible/awx.git
synced 2026-03-28 06:15:04 -02:30
MongoDB installation as part of Tower.
This commit is contained in:
0
awx/api/management/__init__.py
Normal file
0
awx/api/management/__init__.py
Normal file
0
awx/api/management/commands/__init__.py
Normal file
0
awx/api/management/commands/__init__.py
Normal file
40
awx/api/management/commands/uses_mongo.py
Normal file
40
awx/api/management/commands/uses_mongo.py
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
# Copyright (c) 2015 Ansible, Inc.
|
||||||
|
# All Rights Reserved
|
||||||
|
|
||||||
|
import sys
|
||||||
|
|
||||||
|
from django.core.management.base import BaseCommand
|
||||||
|
|
||||||
|
from awx.main.task_engine import TaskSerializer
|
||||||
|
|
||||||
|
|
||||||
|
class Command(BaseCommand):
|
||||||
|
"""Return a exit status of 0 if MongoDB should be active, and an
|
||||||
|
exit status of 1 otherwise.
|
||||||
|
|
||||||
|
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):
|
||||||
|
# Get the license data.
|
||||||
|
license_reader = TaskSerializer()
|
||||||
|
license_data = license_reader.from_file()
|
||||||
|
|
||||||
|
# Does the license contain the system tracking feature?
|
||||||
|
# If and only if it does, MongoDB should run.
|
||||||
|
system_tracking = license_data['features']['system_tracking']
|
||||||
|
|
||||||
|
# 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
|
||||||
|
|
||||||
|
# If we do not need Mongo, return a non-zero exit status.
|
||||||
|
print('MongoDB NOT required')
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
# We do need Mongo, return zero.
|
||||||
|
print('MongoDB required')
|
||||||
|
sys.exit(0)
|
||||||
@@ -8,6 +8,7 @@ import datetime
|
|||||||
import dateutil
|
import dateutil
|
||||||
import time
|
import time
|
||||||
import socket
|
import socket
|
||||||
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
# Django
|
# Django
|
||||||
@@ -228,10 +229,21 @@ class ApiV1ConfigView(APIView):
|
|||||||
except Exception:
|
except Exception:
|
||||||
# FIX: Log
|
# FIX: Log
|
||||||
return Response({"error": "Invalid License"}, status=status.HTTP_400_BAD_REQUEST)
|
return Response({"error": "Invalid License"}, status=status.HTTP_400_BAD_REQUEST)
|
||||||
|
|
||||||
|
# If the license is valid, write it to disk.
|
||||||
if license_data['valid_key']:
|
if license_data['valid_key']:
|
||||||
fh = open(TASK_FILE, "w")
|
fh = open(TASK_FILE, "w")
|
||||||
fh.write(data_actual)
|
fh.write(data_actual)
|
||||||
fh.close()
|
fh.close()
|
||||||
|
|
||||||
|
# Spawn a task to ensure that MongoDB is started (or stopped)
|
||||||
|
# as appropriate, based on whether the license uses it.
|
||||||
|
if license_data['features']['system_tracking']:
|
||||||
|
subprocess.call('sudo service mongod start', shell=True)
|
||||||
|
else:
|
||||||
|
subprocess.call('sudo service mongod stop', shell=True)
|
||||||
|
|
||||||
|
# Done; return the response.
|
||||||
return Response(license_data)
|
return Response(license_data)
|
||||||
return Response({"error": "Invalid license"}, status=status.HTTP_400_BAD_REQUEST)
|
return Response({"error": "Invalid license"}, status=status.HTTP_400_BAD_REQUEST)
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,16 @@ fi
|
|||||||
[ -e "${TOWER_CONFIG}" ] && . "${TOWER_CONFIG}"
|
[ -e "${TOWER_CONFIG}" ] && . "${TOWER_CONFIG}"
|
||||||
|
|
||||||
service_action() {
|
service_action() {
|
||||||
for svc in ${TOWER_SERVICES}; do
|
SERVICES=$TOWER_SERVICES
|
||||||
|
|
||||||
|
# Should MongoDB be managed by this script?
|
||||||
|
# We only manage MongoDB if the license uses it.
|
||||||
|
tower-manage uses_mongo > /dev/null 2> /dev/null
|
||||||
|
if [ $? == 0 ]; then
|
||||||
|
SERVICES="$SERVICES mongod"
|
||||||
|
fi
|
||||||
|
|
||||||
|
for svc in ${SERVICES}; do
|
||||||
service ${svc} $1
|
service ${svc} $1
|
||||||
this_return=$?
|
this_return=$?
|
||||||
if [ $this_return -gt $worst_return ]; then
|
if [ $this_return -gt $worst_return ]; then
|
||||||
|
|||||||
Reference in New Issue
Block a user