mirror of
https://github.com/ansible/awx.git
synced 2026-04-05 01:59:25 -02:30
move service definition into settings
This commit is contained in:
@@ -98,11 +98,7 @@ def _uwsgi_reload():
|
|||||||
# http://uwsgi-docs.readthedocs.io/en/latest/MasterFIFO.html#available-commands
|
# http://uwsgi-docs.readthedocs.io/en/latest/MasterFIFO.html#available-commands
|
||||||
logger.warn('Initiating uWSGI chain reload of server')
|
logger.warn('Initiating uWSGI chain reload of server')
|
||||||
TRIGGER_CHAIN_RELOAD = 'c'
|
TRIGGER_CHAIN_RELOAD = 'c'
|
||||||
if settings.DEBUG:
|
with open(settings.uWSGI_FIFO_LOCATION, 'w') as awxfifo:
|
||||||
uWSGI_FIFO_LOCATION = '/awxfifo'
|
|
||||||
else:
|
|
||||||
uWSGI_FIFO_LOCATION = '/var/lib/awx/awxfifo'
|
|
||||||
with open(uWSGI_FIFO_LOCATION, 'w') as awxfifo:
|
|
||||||
awxfifo.write(TRIGGER_CHAIN_RELOAD)
|
awxfifo.write(TRIGGER_CHAIN_RELOAD)
|
||||||
|
|
||||||
|
|
||||||
@@ -113,29 +109,42 @@ def _reset_celery_thread_pool():
|
|||||||
destination=['celery@{}'.format(settings.CLUSTER_HOST_ID)], reply=False)
|
destination=['celery@{}'.format(settings.CLUSTER_HOST_ID)], reply=False)
|
||||||
|
|
||||||
|
|
||||||
def _supervisor_service_restart():
|
def _supervisor_service_restart(service_internal_names):
|
||||||
'''
|
'''
|
||||||
|
Service internal name options:
|
||||||
|
- beat - celery - callback - channels - uwsgi - daphne
|
||||||
|
- fact - nginx
|
||||||
example use pattern of supervisorctl:
|
example use pattern of supervisorctl:
|
||||||
# supervisorctl restart tower-processes:receiver tower-processes:factcacher
|
# supervisorctl restart tower-processes:receiver tower-processes:factcacher
|
||||||
'''
|
'''
|
||||||
group_name = 'tower-processes'
|
group_name = 'tower-processes'
|
||||||
args = ['supervisorctl']
|
args = ['supervisorctl']
|
||||||
if settings.DEBUG is True:
|
if settings.DEBUG:
|
||||||
args.extend(['-c', '/supervisor.conf'])
|
args.extend(['-c', '/supervisor.conf'])
|
||||||
programs = "receiver,factcacher".split(",")
|
programs = []
|
||||||
else:
|
name_translation_dict = settings.SERVICE_NAME_DICT
|
||||||
programs = "awx-celeryd-beat,awx-callback-receiver,awx-fact-cache-receiver".split(",")
|
for n in service_internal_names:
|
||||||
|
if n in name_translation_dict:
|
||||||
|
programs.append('{}:{}'.format(group_name, name_translation_dict[n]))
|
||||||
args.extend(['restart'])
|
args.extend(['restart'])
|
||||||
args.extend(['{}:{}'.format(group_name, p) for p in programs])
|
args.extend(programs)
|
||||||
logger.debug('Issuing command to restart services, args={}'.format(args))
|
logger.debug('Issuing command to restart services, args={}'.format(args))
|
||||||
subprocess.Popen(args)
|
subprocess.Popen(args)
|
||||||
|
|
||||||
|
|
||||||
def restart_local_services():
|
def restart_local_services(service_internal_names):
|
||||||
logger.warn('Restarting services on this node in response to user action')
|
logger.warn('Restarting services {} on this node in response to user action'.format(service_internal_names))
|
||||||
_uwsgi_reload()
|
if 'uwsgi' in service_internal_names:
|
||||||
_supervisor_service_restart()
|
_uwsgi_reload()
|
||||||
_reset_celery_thread_pool()
|
service_internal_names.pop('uwsgi')
|
||||||
|
restart_celery = False
|
||||||
|
if 'celery' in service_internal_names:
|
||||||
|
restart_celery = True
|
||||||
|
service_internal_names.pop('celery')
|
||||||
|
_supervisor_service_restart(service_internal_names)
|
||||||
|
if restart_celery:
|
||||||
|
# Celery restarted last because this probably includes current process
|
||||||
|
_reset_celery_thread_pool()
|
||||||
|
|
||||||
|
|
||||||
def _clear_cache_keys(set_of_keys):
|
def _clear_cache_keys(set_of_keys):
|
||||||
@@ -151,7 +160,7 @@ def process_cache_changes(cache_keys):
|
|||||||
_clear_cache_keys(set_of_keys)
|
_clear_cache_keys(set_of_keys)
|
||||||
for setting_key in set_of_keys:
|
for setting_key in set_of_keys:
|
||||||
if setting_key.startswith('LOG_AGGREGATOR_'):
|
if setting_key.startswith('LOG_AGGREGATOR_'):
|
||||||
restart_local_services()
|
restart_local_services(['uwsgi', 'celery', 'beat', 'callback', 'fact'])
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
13
awx/main/tests/unit/utils/test_reload.py
Normal file
13
awx/main/tests/unit/utils/test_reload.py
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
# from django.conf import LazySettings
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
# awx.main.utils.reload
|
||||||
|
from awx.main.main.tasks import _supervisor_service_restart, subprocess
|
||||||
|
|
||||||
|
|
||||||
|
def test_produce_supervisor_command(mocker):
|
||||||
|
with mocker.patch.object(subprocess, 'Popen'):
|
||||||
|
_supervisor_service_restart(['beat', 'callback', 'fact'])
|
||||||
|
subprocess.Popen.assert_called_once_with(
|
||||||
|
['supervisorctl', 'restart', 'tower-processes:receiver', 'tower-processes:factcacher'])
|
||||||
|
|
||||||
@@ -112,3 +112,15 @@ except ImportError:
|
|||||||
CLUSTER_HOST_ID = socket.gethostname()
|
CLUSTER_HOST_ID = socket.gethostname()
|
||||||
CELERY_ROUTES['awx.main.tasks.cluster_node_heartbeat'] = {'queue': CLUSTER_HOST_ID, 'routing_key': CLUSTER_HOST_ID}
|
CELERY_ROUTES['awx.main.tasks.cluster_node_heartbeat'] = {'queue': CLUSTER_HOST_ID, 'routing_key': CLUSTER_HOST_ID}
|
||||||
|
|
||||||
|
# Supervisor service name dictionary used for programatic restart
|
||||||
|
SERVICE_NAME_DICT = {
|
||||||
|
"celery": "celeryd",
|
||||||
|
"callback": "receiver",
|
||||||
|
"runworker": "channels",
|
||||||
|
"uwsgi": "uwsgi",
|
||||||
|
"daphne": "daphne",
|
||||||
|
"fact": "factcacher",
|
||||||
|
"nginx": "nginx"}
|
||||||
|
# Used for sending commands in automatic restart
|
||||||
|
uWSGI_FIFO_LOCATION = '/awxfifo'
|
||||||
|
|
||||||
|
|||||||
@@ -57,6 +57,18 @@ LOGGING['handlers']['fact_receiver']['filename'] = '/var/log/tower/fact_receiver
|
|||||||
LOGGING['handlers']['system_tracking_migrations']['filename'] = '/var/log/tower/tower_system_tracking_migrations.log'
|
LOGGING['handlers']['system_tracking_migrations']['filename'] = '/var/log/tower/tower_system_tracking_migrations.log'
|
||||||
LOGGING['handlers']['rbac_migrations']['filename'] = '/var/log/tower/tower_rbac_migrations.log'
|
LOGGING['handlers']['rbac_migrations']['filename'] = '/var/log/tower/tower_rbac_migrations.log'
|
||||||
|
|
||||||
|
# Supervisor service name dictionary used for programatic restart
|
||||||
|
SERVICE_NAME_DICT = {
|
||||||
|
"beat": "awx-celeryd-beat",
|
||||||
|
"celery": "awx-celeryd",
|
||||||
|
"callback": "awx-callback-receiver",
|
||||||
|
"channels": "awx-channels-worker",
|
||||||
|
"uwsgi": "awx-uwsgi",
|
||||||
|
"daphne": "awx-daphne",
|
||||||
|
"fact": "awx-fact-cache-receiver"}
|
||||||
|
# Used for sending commands in automatic restart
|
||||||
|
uWSGI_FIFO_LOCATION = '/var/lib/awx/awxfifo'
|
||||||
|
|
||||||
# Store a snapshot of default settings at this point before loading any
|
# Store a snapshot of default settings at this point before loading any
|
||||||
# customizable config files.
|
# customizable config files.
|
||||||
DEFAULTS_SNAPSHOT = {}
|
DEFAULTS_SNAPSHOT = {}
|
||||||
|
|||||||
Reference in New Issue
Block a user