__init__.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. # -*- coding: utf-8 -*-
  2. # Copyright 2014-2016 OpenMarket Ltd
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. import logging
  16. import sys
  17. from synapse import python_dependencies # noqa: E402
  18. logger = logging.getLogger(__name__)
  19. try:
  20. python_dependencies.check_requirements()
  21. except python_dependencies.DependencyException as e:
  22. sys.stderr.writelines(
  23. e.message # noqa: B306, DependencyException.message is a property
  24. )
  25. sys.exit(1)
  26. def check_bind_error(e, address, bind_addresses):
  27. """
  28. This method checks an exception occurred while binding on 0.0.0.0.
  29. If :: is specified in the bind addresses a warning is shown.
  30. The exception is still raised otherwise.
  31. Binding on both 0.0.0.0 and :: causes an exception on Linux and macOS
  32. because :: binds on both IPv4 and IPv6 (as per RFC 3493).
  33. When binding on 0.0.0.0 after :: this can safely be ignored.
  34. Args:
  35. e (Exception): Exception that was caught.
  36. address (str): Address on which binding was attempted.
  37. bind_addresses (list): Addresses on which the service listens.
  38. """
  39. if address == "0.0.0.0" and "::" in bind_addresses:
  40. logger.warning(
  41. "Failed to listen on 0.0.0.0, continuing because listening on [::]"
  42. )
  43. else:
  44. raise e