start.sh 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. #!/usr/bin/env bash
  2. DIR="$( cd "$( dirname "$0" )" && pwd )"
  3. CWD=$(pwd)
  4. cd "$DIR/.." || exit
  5. PYTHONPATH=$(readlink -f "$(pwd)")
  6. export PYTHONPATH
  7. echo "$PYTHONPATH"
  8. # Create servers which listen on HTTP at 808x and HTTPS at 848x.
  9. for port in 8080 8081 8082; do
  10. echo "Starting server on port $port... "
  11. https_port=$((port + 400))
  12. mkdir -p demo/$port
  13. pushd demo/$port || exit
  14. # Generate the configuration for the homeserver at localhost:848x, note that
  15. # the homeserver name needs to match the HTTPS listening port for federation
  16. # to properly work..
  17. python3 -m synapse.app.homeserver \
  18. --generate-config \
  19. --server-name "localhost:$https_port" \
  20. --config-path "$port.config" \
  21. --report-stats no
  22. if ! grep -F "Customisation made by demo/start.sh" -q "$port.config"; then
  23. # Generate TLS keys.
  24. openssl req -x509 -newkey rsa:4096 \
  25. -keyout "localhost:$port.tls.key" \
  26. -out "localhost:$port.tls.crt" \
  27. -days 365 -nodes -subj "/O=matrix"
  28. # Add customisations to the configuration.
  29. {
  30. printf '\n\n# Customisation made by demo/start.sh\n\n'
  31. echo "public_baseurl: http://localhost:$port/"
  32. echo 'enable_registration: true'
  33. echo 'enable_registration_without_verification: true'
  34. echo ''
  35. # Warning, this heredoc depends on the interaction of tabs and spaces.
  36. # Please don't accidentaly bork me with your fancy settings.
  37. listeners=$(cat <<-PORTLISTENERS
  38. # Configure server to listen on both $https_port and $port
  39. # This overides some of the default settings above
  40. listeners:
  41. - port: $https_port
  42. type: http
  43. tls: true
  44. resources:
  45. - names: [client, federation]
  46. - port: $port
  47. tls: false
  48. bind_addresses: ['::1', '127.0.0.1']
  49. type: http
  50. x_forwarded: true
  51. resources:
  52. - names: [client, federation]
  53. compress: false
  54. PORTLISTENERS
  55. )
  56. echo "${listeners}"
  57. # Disable TLS for the servers
  58. printf '\n\n# Disable TLS for the servers.'
  59. echo '# DO NOT USE IN PRODUCTION'
  60. echo 'use_insecure_ssl_client_just_for_testing_do_not_use: true'
  61. echo 'federation_verify_certificates: false'
  62. # Set paths for the TLS certificates.
  63. echo "tls_certificate_path: \"$DIR/$port/localhost:$port.tls.crt\""
  64. echo "tls_private_key_path: \"$DIR/$port/localhost:$port.tls.key\""
  65. # Ignore keys from the trusted keys server
  66. echo '# Ignore keys from the trusted keys server'
  67. echo 'trusted_key_servers:'
  68. echo ' - server_name: "matrix.org"'
  69. echo ' accept_keys_insecurely: true'
  70. echo ''
  71. # Allow the servers to communicate over localhost.
  72. allow_list=$(cat <<-ALLOW_LIST
  73. # Allow the servers to communicate over localhost.
  74. ip_range_whitelist:
  75. - '127.0.0.1/8'
  76. - '::1/128'
  77. ALLOW_LIST
  78. )
  79. echo "${allow_list}"
  80. } >> "$port.config"
  81. fi
  82. # Check script parameters
  83. if [ $# -eq 1 ]; then
  84. if [ "$1" = "--no-rate-limit" ]; then
  85. # Disable any rate limiting
  86. ratelimiting=$(cat <<-RC
  87. rc_message:
  88. per_second: 1000
  89. burst_count: 1000
  90. rc_registration:
  91. per_second: 1000
  92. burst_count: 1000
  93. rc_login:
  94. address:
  95. per_second: 1000
  96. burst_count: 1000
  97. account:
  98. per_second: 1000
  99. burst_count: 1000
  100. failed_attempts:
  101. per_second: 1000
  102. burst_count: 1000
  103. rc_admin_redaction:
  104. per_second: 1000
  105. burst_count: 1000
  106. rc_joins:
  107. local:
  108. per_second: 1000
  109. burst_count: 1000
  110. remote:
  111. per_second: 1000
  112. burst_count: 1000
  113. rc_3pid_validation:
  114. per_second: 1000
  115. burst_count: 1000
  116. rc_invites:
  117. per_room:
  118. per_second: 1000
  119. burst_count: 1000
  120. per_user:
  121. per_second: 1000
  122. burst_count: 1000
  123. RC
  124. )
  125. echo "${ratelimiting}" >> "$port.config"
  126. fi
  127. fi
  128. # Always disable reporting of stats if the option is not there.
  129. if ! grep -F "report_stats" -q "$port.config" ; then
  130. echo "report_stats: false" >> "$port.config"
  131. fi
  132. # Run the homeserver in the background.
  133. python3 -m synapse.app.homeserver \
  134. --config-path "$port.config" \
  135. -D \
  136. popd || exit
  137. done
  138. cd "$CWD" || exit