Check if documents indexer port is available before starting process to avoid zombies
--- a/src/pyams_content_es/include.py Fri Nov 09 12:10:35 2018 +0100
+++ b/src/pyams_content_es/include.py Fri Nov 09 12:13:05 2018 +0100
@@ -27,6 +27,7 @@
# import packages
from pyams_content_es.process import ContentIndexerProcess, ContentIndexerMessageHandler
+from pyams_utils.protocol.tcp import is_port_in_use
from pyams_utils.registry import get_global_registry
from pyams_zmq.process import process_exit_func
from pyramid.events import subscriber
@@ -61,10 +62,16 @@
settings = registry.settings
start_handler = asbool(settings.get(INDEXER_STARTER_KEY, False))
if start_handler:
- process = None
+ # check if port is available
+ handler_address = settings.get(INDEXER_HANDLER_KEY, '127.0.0.1:5557')
+ hostname, port = handler_address.split(':')
+ if is_port_in_use(int(port), hostname):
+ logger.info("Elasticsearch content indexer port already used, aborting...")
+ return
# create content indexer process
+ process = None
try:
- process = ContentIndexerProcess(settings.get(INDEXER_HANDLER_KEY, '127.0.0.1:5557'),
+ process = ContentIndexerProcess(handler_address,
ContentIndexerMessageHandler,
settings.get(INDEXER_AUTH_KEY),
settings.get(INDEXER_CLIENTS_KEY),