mirror of
https://github.com/ansible/awx.git
synced 2026-03-21 19:07:39 -02:30
Move MongoDB control to tasks.
This commit is contained in:
@@ -46,6 +46,7 @@ import ansiconv
|
|||||||
|
|
||||||
# AWX
|
# AWX
|
||||||
from awx.main.task_engine import TaskSerializer, TASK_FILE
|
from awx.main.task_engine import TaskSerializer, TASK_FILE
|
||||||
|
from awx.main.tasks import mongodb_control
|
||||||
from awx.main.access import get_user_queryset
|
from awx.main.access import get_user_queryset
|
||||||
from awx.main.ha import is_ha_environment
|
from awx.main.ha import is_ha_environment
|
||||||
from awx.api.authentication import TaskAuthentication
|
from awx.api.authentication import TaskAuthentication
|
||||||
@@ -243,9 +244,9 @@ class ApiV1ConfigView(APIView):
|
|||||||
# Spawn a task to ensure that MongoDB is started (or stopped)
|
# Spawn a task to ensure that MongoDB is started (or stopped)
|
||||||
# as appropriate, based on whether the license uses it.
|
# as appropriate, based on whether the license uses it.
|
||||||
if license_data['features']['system_tracking']:
|
if license_data['features']['system_tracking']:
|
||||||
subprocess.call('sudo service mongod start', shell=True)
|
mongodb_control.delay('start')
|
||||||
else:
|
else:
|
||||||
subprocess.call('sudo service mongod stop', shell=True)
|
mongodb_control.delay('stop')
|
||||||
|
|
||||||
# Done; return the response.
|
# Done; return the response.
|
||||||
return Response(license_data)
|
return Response(license_data)
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import pipes
|
|||||||
import re
|
import re
|
||||||
import shutil
|
import shutil
|
||||||
import stat
|
import stat
|
||||||
|
import subprocess
|
||||||
import tempfile
|
import tempfile
|
||||||
import time
|
import time
|
||||||
import traceback
|
import traceback
|
||||||
@@ -119,6 +120,23 @@ def notify_task_runner(metadata_dict):
|
|||||||
queue = FifoQueue('tower_task_manager')
|
queue = FifoQueue('tower_task_manager')
|
||||||
queue.push(metadata_dict)
|
queue.push(metadata_dict)
|
||||||
|
|
||||||
|
|
||||||
|
@task()
|
||||||
|
def mongodb_control(cmd):
|
||||||
|
# Sanity check: Do not send arbitrary commands.
|
||||||
|
if cmd not in ('start', 'stop'):
|
||||||
|
raise ValueError('Only "start" and "stop" are allowed.')
|
||||||
|
|
||||||
|
# Either start or stop mongo, as requested.
|
||||||
|
p = subprocess.Popen('sudo service mongod %s' % cmd, shell=True,
|
||||||
|
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||||
|
out, err = p.communicate()
|
||||||
|
|
||||||
|
# If there was an error, log it.
|
||||||
|
if err:
|
||||||
|
logger.error(err)
|
||||||
|
|
||||||
|
|
||||||
@task(bind=True)
|
@task(bind=True)
|
||||||
def handle_work_error(self, task_id, subtasks=None):
|
def handle_work_error(self, task_id, subtasks=None):
|
||||||
print('Executing error task id %s, subtasks: %s' %
|
print('Executing error task id %s, subtasks: %s' %
|
||||||
|
|||||||
Reference in New Issue
Block a user