From cf0c0f8e7c74119e5115e8d75c1cf0ed9fb60842 Mon Sep 17 00:00:00 2001 From: Igor Yanchenko <1504692+yanchenko-igor@users.noreply.github.com> Date: Mon, 2 Dec 2019 12:15:45 +0100 Subject: [PATCH] Make the error more helpful if restapi cannot bind (#1300) Giving the user a hint if we couldn't start the restapi service. --- patroni/api.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/patroni/api.py b/patroni/api.py index 86e46d4e..bd331d2e 100644 --- a/patroni/api.py +++ b/patroni/api.py @@ -10,8 +10,8 @@ import os import six import socket -from patroni.postgresql import PostgresConnectionException -from patroni.postgresql.misc import postgres_version_to_int, PostgresException +from patroni.exceptions import PostgresConnectionException, PostgresException +from patroni.postgresql.misc import postgres_version_to_int from patroni.utils import deep_compare, parse_bool, patch_config, Retry, \ RetryFailedError, parse_int, split_host_port, tzutc, uri, cluster_as_json from six.moves.BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer @@ -556,7 +556,12 @@ class RestApiServer(ThreadingMixIn, HTTPServer, Thread): info.sort(key=lambda x: x[0] == socket.AF_INET, reverse=not dual_stack) self.address_family = info[0][0] - HTTPServer.__init__(self, info[0][-1][:2], RestApiHandler) + try: + HTTPServer.__init__(self, info[0][-1][:2], RestApiHandler) + except socket.error: + logger.error( + "Couldn't start a service on '%s:%s', please check your `restapi.listen` configuration", host, port) + raise def __initialize(self, listen, ssl_options): try: