diff --git a/awx/main/tasks.py b/awx/main/tasks.py index 7edfcc7246..0538e7b0c4 100644 --- a/awx/main/tasks.py +++ b/awx/main/tasks.py @@ -230,12 +230,31 @@ def handle_ha_toplogy_worker_ready(sender, **kwargs): @celeryd_after_setup.connect -def handle_update_celery_hostname(sender, instance, **kwargs): +def auto_register_ha_instance(sender, instance, **kwargs): + # + # When celeryd starts, if the instance cannot be found in the database, + # automatically register it. This is mostly useful for openshift-based + # deployments where: + # + # 2 Instances come online + # Instance B encounters a network blip, Instance A notices, and + # deprovisions it + # Instance B's connectivity is restored, celeryd starts, and it + # re-registers itself + # + # In traditional container-less deployments, instances don't get + # deprovisioned when they miss their heartbeat, so this code is mostly a + # no-op. + # + if instance.hostname != 'celery@{}'.format(settings.CLUSTER_HOST_ID): + error = six.text_type('celery -n {} does not match settings.CLUSTER_HOST_ID={}').format( + instance.hostname, settings.CLUSTER_HOST_ID + ) + logger.error(error) + raise RuntimeError(error) (changed, tower_instance) = Instance.objects.get_or_register() if changed: logger.info(six.text_type("Registered tower node '{}'").format(tower_instance.hostname)) - instance.hostname = 'celery@{}'.format(tower_instance.hostname) - logger.warn(six.text_type("Set hostname to {}").format(instance.hostname)) @shared_task(queue=settings.CELERY_DEFAULT_QUEUE) diff --git a/installer/roles/image_build/files/supervisor_task.conf b/installer/roles/image_build/files/supervisor_task.conf index c90c6336f0..44e1ffcb8a 100644 --- a/installer/roles/image_build/files/supervisor_task.conf +++ b/installer/roles/image_build/files/supervisor_task.conf @@ -16,7 +16,7 @@ stderr_logfile=/dev/stderr stderr_logfile_maxbytes=0 [program:celery-watcher] -command = /usr/bin/awx-manage celery_watcher +command = /usr/bin/awx-manage watch_celery directory = /var/lib/awx environment = LANGUAGE="en_US.UTF-8",LANG="en_US.UTF-8",LC_ALL="en_US.UTF-8",LC_CTYPE="en_US.UTF-8" autostart = true