__init__.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. sys.dont_write_bytecode = True
  19. logger = logging.getLogger(__name__)
  20. try:
  21. python_dependencies.check_requirements()
  22. except python_dependencies.DependencyException as e:
  23. sys.stderr.writelines(e.message)
  24. sys.exit(1)
  25. def check_bind_error(e, address, bind_addresses):
  26. """
  27. This method checks an exception occurred while binding on 0.0.0.0.
  28. If :: is specified in the bind addresses a warning is shown.
  29. The exception is still raised otherwise.
  30. Binding on both 0.0.0.0 and :: causes an exception on Linux and macOS
  31. because :: binds on both IPv4 and IPv6 (as per RFC 3493).
  32. When binding on 0.0.0.0 after :: this can safely be ignored.
  33. Args:
  34. e (Exception): Exception that was caught.
  35. address (str): Address on which binding was attempted.
  36. bind_addresses (list): Addresses on which the service listens.
  37. """
  38. if address == "0.0.0.0" and "::" in bind_addresses:
  39. logger.warn("Failed to listen on 0.0.0.0, continuing because listening on [::]")
  40. else:
  41. raise e