You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
2.6 KiB

  1. #!/bin/bash
  2. # this script will be run during the boot process by each VertSys instance created
  3. # in AWS currently this is a plain bash script that requires a RedHat based image
  4. # (AMI) could be ported to cloud-init for better compatibility with other Linux
  5. # distros
  6. #
  7. # see https://docs.aws.amazon.com/de_de/AWSEC2/latest/UserGuide/user-data.html
  8. # Config
  9. SCRIPT_ROOT_PATH="/tmp/init-script"
  10. VERTSYS_PATH="$SCRIPT_ROOT_PATH/verteilte-systeme-bsc-ai-examples/VerteilteSysteme-Examples/build/"
  11. #JARS = "TCPServer.jar TCPServerMulti.jar UDPServer.jar UDPServerMulti.jar UDPTimeCounterServer.jar TCPTimeCounterServer.jar TCPPerfServer.jar"
  12. JARS="TCPServer.jar TCPPerfServer.jar UDPServer.jar UDPTimeCounterServer.jar TCPTimeCounterServer.jar"
  13. REPO="https://gogs.informatik.hs-fulda.de/srieger/verteilte-systeme-bsc-ai-examples.git"
  14. # Create path to run the script
  15. mkdir $SCRIPT_ROOT_PATH
  16. cd $SCRIPT_ROOT_PATH
  17. # fetch user-data (should be the content of this script itself ;)) to be able check it later and run it again
  18. wget http://169.254.169.254/latest/user-data
  19. chmod +x user-data
  20. wget http://169.254.169.254/latest/meta-data/placement/availability-zone
  21. # setting console prompt to include location (availability zone and region in AWS)
  22. echo "PS1='[\u@\h@\e[32m`cat /tmp/init-script/availability-zone`\e[32m \W]$ '" >>/root/.bashrc
  23. echo "PS1='[\u@\h@\e[32m`cat /tmp/init-script/availability-zone`\e[39m \W]$ '" >>/home/ec2-user/.bashrc
  24. # wait for internet connection, should not be necessary, but just in case ;)
  25. while ! ping -c 1 -W 1 8.8.8.8; do
  26. echo "Waiting for 8.8.8.8 - network interface might be down..."
  27. sleep 1
  28. done
  29. # installation of required packages
  30. echo "Installing packages..."
  31. sudo yum update -y
  32. sudo yum install -y java git
  33. #rm -rf verteilte-systeme-bsc-ai-examples
  34. if [ ! -d $VERTSYS_PATH ]; then
  35. echo "Cloning repo..."
  36. git clone $REPO
  37. fi
  38. # killall running screens, .e.g to cleanup if script is run again after boot
  39. killall screen
  40. # start all jars
  41. echo "Starting JARS: ${JARS}..."
  42. for JAR in $JARS; do
  43. echo "Starting ${JAR}..."
  44. sudo screen -dmS $JAR -L java -jar $VERTSYS_PATH/$JAR
  45. done
  46. # wait a second, to allow java services to start
  47. sleep 1
  48. # output status of ports 36000-36199 and all running processes
  49. echo "Status:"
  50. sudo netstat -taupen | grep 36[0,1][0-9][0-9]
  51. sudo ps aux | grep java
  52. # Example for path and contents:
  53. #
  54. # ./verteilte-systeme-bsc-ai-examples/VerteilteSysteme-Examples/build/
  55. #
  56. #build-server-jars.xml TCPServerMulti.jar
  57. #RMIEchoServer.jar UDPServer.jar
  58. #RMIMandelbrotCalculationsServer.jar UDPServerMulti.jar
  59. #TCPPerfServer.jar UDPTimeCounterServer.jar
  60. #TCPServer.jar