Browse Source

improved user-data script

master
Sebastian Rieger 7 years ago
parent
commit
5e19bc50fe
  1. 22
      VerteilteSysteme-Examples/src/verteiltesysteme/aws/user-data.txt

22
VerteilteSysteme-Examples/src/verteiltesysteme/aws/user-data.txt

@ -1,19 +1,28 @@
#!/bin/bash
# this script will be run during the boot process by each VertSys instance created
# in AWS currently this is a plain bash script that requires a RedHat based image
# (AMI) could be ported to cloud-init for better compatibility with other Linux
# distros
#
# see https://docs.aws.amazon.com/de_de/AWSEC2/latest/UserGuide/user-data.html
# 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"
#JARS = "TCPServer.jar TCPServerMulti.jar UDPServer.jar UDPServerMulti.jar UDPTimeCounterServer.jar TCPTimeCounterServer.jar TCPPerfServer.jar"
JARS="TCPServer.jar TCPPerfServer.jar UDPServer.jar UDPTimeCounterServer.jar TCPTimeCounterServer.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
# Create path to run the script
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
# fetch user-data (should be the content of this script itself ;)) to be able check it later and run it 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
@ -24,6 +33,7 @@ while ! ping -c 1 -W 1 8.8.8.8; do
sleep 1
done
# installation of required packages
echo "Installing packages..."
sudo yum update -y
sudo yum install -y java git
@ -33,7 +43,7 @@ if [ ! -d $VERTSYS_PATH ]; then
git clone $REPO
fi
# killall running screens if script is run again
# killall running screens, .e.g to cleanup if script is run again after boot
killall screen
# start all jars
echo "Starting JARS: ${JARS}..."
@ -42,8 +52,10 @@ for JAR in $JARS; do
sudo screen -dmS $JAR -L java -jar $VERTSYS_PATH/$JAR
done
# wait a second, to allow java services to start
sleep 1
# output status of ports 36000-36199 and all running processes
echo "Status:"
sudo netstat -taupen | grep 36[0,1][0-9][0-9]
sudo ps aux | grep java

Loading…
Cancel
Save