#!/bin/bash # Config SCRIPT_ROOT_PATH="/tmp/init-script" VERTSYS_PATH="$SCRIPT_ROOT_PATH/verteilte-systeme-bsc-ai-examples/VerteilteSysteme-Examples/build/" #JARS = "TCPServer.jar TCPServerMulti.jar UDPServer.jar UDPServerMulti.jar UDPTimeCounterServer.jar TCPPerfServer.jar" JARS="TCPServer.jar TCPPerfServer.jar UDPServer.jar UDPTimeCounterServer.jar" REPO="https://gogs.informatik.hs-fulda.de/srieger/verteilte-systeme-bsc-ai-examples.git" # Create path to run the script and store the output mkdir $SCRIPT_ROOT_PATH cd $SCRIPT_ROOT_PATH # fetch user-data (should be the content of this script itself ;)) to check and run it later again wget http://169.254.169.254/latest/user-data chmod +x user-data wget http://169.254.169.254/latest/meta-data/placement/availability-zone # setting console prompt to include location (availability zone and region in AWS) echo "PS1='[\u@\h@\e[32m`cat /tmp/init-script/availability-zone`\e[32m \W]$ '" >>/root/.bashrc echo "PS1='[\u@\h@\e[32m`cat /tmp/init-script/availability-zone`\e[39m \W]$ '" >>/home/ec2-user/.bashrc # wait for internet connection, should not be necessary, but just in case ;) while ! ping -c 1 -W 1 8.8.8.8; do echo "Waiting for 8.8.8.8 - network interface might be down..." sleep 1 done echo "Installing packages..." sudo yum update -y sudo yum install -y java git #rm -rf verteilte-systeme-bsc-ai-examples if [ ! -d $VERTSYS_PATH ]; then echo "Cloning repo..." git clone $REPO fi # killall running screens if script is run again killall screen # start all jars echo "Starting JARS: ${JARS}..." for JAR in $JARS; do echo "Starting ${JAR}..." sudo screen -dmS $JAR -L java -jar $VERTSYS_PATH/$JAR done sleep 1 echo "Status:" sudo netstat -taupen | grep 36[0,1][0-9][0-9] sudo ps aux | grep java # Example for path and contents: # # ./verteilte-systeme-bsc-ai-examples/VerteilteSysteme-Examples/build/ # #build-server-jars.xml TCPServerMulti.jar #RMIEchoServer.jar UDPServer.jar #RMIMandelbrotCalculationsServer.jar UDPServerMulti.jar #TCPPerfServer.jar UDPTimeCounterServer.jar #TCPServer.jar