start.sh 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. #!/bin/bash
  2. DIR="$( cd "$( dirname "$0" )" && pwd )"
  3. CWD=$(pwd)
  4. cd "$DIR/.."
  5. mkdir -p demo/etc
  6. export PYTHONPATH=$(readlink -f $(pwd))
  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
  13. #rm $DIR/etc/$port.config
  14. python3 -m synapse.app.homeserver \
  15. --generate-config \
  16. -H "localhost:$https_port" \
  17. --config-path "$DIR/etc/$port.config" \
  18. --report-stats no
  19. if ! grep -F "Customisation made by demo/start.sh" -q $DIR/etc/$port.config; then
  20. printf '\n\n# Customisation made by demo/start.sh\n' >> $DIR/etc/$port.config
  21. echo 'enable_registration: true' >> $DIR/etc/$port.config
  22. # Warning, this heredoc depends on the interaction of tabs and spaces. Please don't
  23. # accidentaly bork me with your fancy settings.
  24. listeners=$(cat <<-PORTLISTENERS
  25. # Configure server to listen on both $https_port and $port
  26. # This overides some of the default settings above
  27. listeners:
  28. - port: $https_port
  29. type: http
  30. tls: true
  31. resources:
  32. - names: [client, federation]
  33. - port: $port
  34. tls: false
  35. bind_addresses: ['::1', '127.0.0.1']
  36. type: http
  37. x_forwarded: true
  38. resources:
  39. - names: [client, federation]
  40. compress: false
  41. PORTLISTENERS
  42. )
  43. echo "${listeners}" >> $DIR/etc/$port.config
  44. # Disable tls for the servers
  45. printf '\n\n# Disable tls on the servers.' >> $DIR/etc/$port.config
  46. echo '# DO NOT USE IN PRODUCTION' >> $DIR/etc/$port.config
  47. echo 'use_insecure_ssl_client_just_for_testing_do_not_use: true' >> $DIR/etc/$port.config
  48. echo 'federation_verify_certificates: false' >> $DIR/etc/$port.config
  49. # Set tls paths
  50. echo "tls_certificate_path: \"$DIR/etc/localhost:$https_port.tls.crt\"" >> $DIR/etc/$port.config
  51. echo "tls_private_key_path: \"$DIR/etc/localhost:$https_port.tls.key\"" >> $DIR/etc/$port.config
  52. # Generate tls keys
  53. openssl req -x509 -newkey rsa:4096 -keyout $DIR/etc/localhost\:$https_port.tls.key -out $DIR/etc/localhost\:$https_port.tls.crt -days 365 -nodes -subj "/O=matrix"
  54. # Ignore keys from the trusted keys server
  55. echo '# Ignore keys from the trusted keys server' >> $DIR/etc/$port.config
  56. echo 'trusted_key_servers:' >> $DIR/etc/$port.config
  57. echo ' - server_name: "matrix.org"' >> $DIR/etc/$port.config
  58. echo ' accept_keys_insecurely: true' >> $DIR/etc/$port.config
  59. # Reduce the blacklist
  60. blacklist=$(cat <<-BLACK
  61. # Set the blacklist so that it doesn't include 127.0.0.1
  62. federation_ip_range_blacklist:
  63. - '10.0.0.0/8'
  64. - '172.16.0.0/12'
  65. - '192.168.0.0/16'
  66. - '100.64.0.0/10'
  67. - '169.254.0.0/16'
  68. - '::1/128'
  69. - 'fe80::/64'
  70. - 'fc00::/7'
  71. BLACK
  72. )
  73. echo "${blacklist}" >> $DIR/etc/$port.config
  74. fi
  75. # Check script parameters
  76. if [ $# -eq 1 ]; then
  77. if [ $1 = "--no-rate-limit" ]; then
  78. # messages rate limit
  79. echo 'rc_messages_per_second: 1000' >> $DIR/etc/$port.config
  80. echo 'rc_message_burst_count: 1000' >> $DIR/etc/$port.config
  81. # registration rate limit
  82. printf 'rc_registration:\n per_second: 1000\n burst_count: 1000\n' >> $DIR/etc/$port.config
  83. # login rate limit
  84. echo 'rc_login:' >> $DIR/etc/$port.config
  85. printf ' address:\n per_second: 1000\n burst_count: 1000\n' >> $DIR/etc/$port.config
  86. printf ' account:\n per_second: 1000\n burst_count: 1000\n' >> $DIR/etc/$port.config
  87. printf ' failed_attempts:\n per_second: 1000\n burst_count: 1000\n' >> $DIR/etc/$port.config
  88. fi
  89. fi
  90. if ! grep -F "full_twisted_stacktraces" -q $DIR/etc/$port.config; then
  91. echo "full_twisted_stacktraces: true" >> $DIR/etc/$port.config
  92. fi
  93. if ! grep -F "report_stats" -q $DIR/etc/$port.config ; then
  94. echo "report_stats: false" >> $DIR/etc/$port.config
  95. fi
  96. python3 -m synapse.app.homeserver \
  97. --config-path "$DIR/etc/$port.config" \
  98. -D \
  99. -vv \
  100. popd
  101. done
  102. cd "$CWD"