start.sh 4.2 KB

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