start.sh 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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, ::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. - 'fe80::/64'
  69. - 'fc00::/7'
  70. BLACK
  71. )
  72. echo "${blacklist}" >> $DIR/etc/$port.config
  73. fi
  74. # Check script parameters
  75. if [ $# -eq 1 ]; then
  76. if [ $1 = "--no-rate-limit" ]; then
  77. # messages rate limit
  78. echo 'rc_messages_per_second: 1000' >> $DIR/etc/$port.config
  79. echo 'rc_message_burst_count: 1000' >> $DIR/etc/$port.config
  80. # registration rate limit
  81. printf 'rc_registration:\n per_second: 1000\n burst_count: 1000\n' >> $DIR/etc/$port.config
  82. # login rate limit
  83. echo 'rc_login:' >> $DIR/etc/$port.config
  84. printf ' address:\n per_second: 1000\n burst_count: 1000\n' >> $DIR/etc/$port.config
  85. printf ' account:\n per_second: 1000\n burst_count: 1000\n' >> $DIR/etc/$port.config
  86. printf ' failed_attempts:\n per_second: 1000\n burst_count: 1000\n' >> $DIR/etc/$port.config
  87. fi
  88. fi
  89. if ! grep -F "full_twisted_stacktraces" -q $DIR/etc/$port.config; then
  90. echo "full_twisted_stacktraces: true" >> $DIR/etc/$port.config
  91. fi
  92. if ! grep -F "report_stats" -q $DIR/etc/$port.config ; then
  93. echo "report_stats: false" >> $DIR/etc/$port.config
  94. fi
  95. python3 -m synapse.app.homeserver \
  96. --config-path "$DIR/etc/$port.config" \
  97. -D \
  98. popd
  99. done
  100. cd "$CWD"