Skip to content

Commit 400cd00

Browse files
Josh GachnangJosh Gachnang
authored andcommitted
Addingin in the initial sweet ec2 testing scripts.
1 parent 9dd1232 commit 400cd00

File tree

3 files changed

+93
-0
lines changed

3 files changed

+93
-0
lines changed

ec2-kill-test

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#Check if variables set. If not, exit with herror.
2+
#Check if file exists first. If not, exit with error.
3+
ec2-terminate-instances $(cat ~/Dropbox/config/ec2/.current_test_instance_id)
4+
5+
echo -n 'Killed test instance with id '
6+
echo $(cat .current_test_instance_id)
7+
8+
rm ~/Dropbox/config/ec2/.current_test_instance_id
9+
rm ~/Dropbox/config/ec2/.current_test_instance_dns

ec2-start-test

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#Check if required variables are non null. If not, exit with error.
2+
instance_id=$($EC2_HOME/bin/ec2-run-instances ami-7000f019 -k Default | awk '/INSTANCE/{print $2}')
3+
4+
#Check if file exists. Figure out something.
5+
echo $instance_id > .current_test_instance_id
6+
echo -n 'Started new instance with id: '
7+
echo $instance_id
8+
9+
public_dns=$(ec2-describe-instances $instance_id | awk '/INSTANCE/{print $4}')
10+
11+
echo 'Waiting for instance to finish starting'
12+
13+
while [[ $public_dns == 'pending' ]]; do
14+
echo -n .
15+
public_dns=$(ec2-describe-instances $instance_id | awk '/INSTANCE/{print $4}')
16+
done
17+
18+
#Again, check if file exists. If it does, who knows?
19+
echo $public_dns > .current_test_instance_dns
20+
echo $public_dns
21+
22+
echo -n 'Instance now running. Attempting autoconnect or connect to: '
23+
echo $public_dns
24+
25+
echo - 'Waiting on ssh..'
26+
while ssh -o StrictHostKeyChecking=no -i Default.pem ubuntu@$public_dns true && test;
27+
do echo -n .; sleep .5; done
28+
echo ''
29+
30+
echo 'sleeping for 3s before accessing server..'
31+
sleep 3
32+
33+
echo "Connecting to $public_dns"
34+
ssh -o StrictHostKeyChecking=no -i Default.pem ubuntu@$public_dns

install_ec2_tools.sh

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#Installs all the necessary tools to use the ec2-start-test and ec2-kill-test scripts.
2+
#Doesn't install the actual tools. Should probably add that as an option.
3+
#Oh, and this wouldn't even work for anyone but me. Should probably fix that too..
4+
#Modify path names?
5+
6+
sudo add-apt-repository "deb http://archive.canonical.com/ lucid partner"
7+
sudo apt-get -y update
8+
9+
sudo apt-get -y install unzip sun-java6-jre
10+
11+
#Export variables to ~/.bashrc
12+
#Need to check for each variable in ~/.bashrc. Grep?
13+
RES=$(grep "EC2_HOME" ~/.bashrc)
14+
if [ $? -ne 0 ]; then
15+
echo export EC2_HOME=$HOME/Dropbox/config/ec2/ec2-api-tools-1.4.2.4/ >> ~/.bashrc
16+
else
17+
echo "EC2_HOME exists"
18+
fi
19+
RES=$(grep "EC2_CERT" ~/.bashrc)
20+
if [ $? -ne 0 ]; then
21+
echo export EC2_CERT=$HOME/Dropbox/config/ec2/cert-3VJG2ORMUEMUWE2IZNQNZNH2IWS5HYEM.pem >> ~/.bashrc
22+
else
23+
echo "EC2_CERT exists"
24+
fi
25+
RES=$(grep "EC2_PRIVATE_KEY" ~/.bashrc)
26+
if [ $? -ne 0 ]; then
27+
echo export EC2_PRIVATE_KEY=$HOME/Dropbox/config/ec2/pk-3VJG2ORMUEMUWE2IZNQNZNH2IWS5HYEM.pem >> ~/.bashrc
28+
else
29+
echo "EC2_PRIVATE_KEY exists"
30+
fi
31+
RES=$(grep "PATH" ~/.bashrc)
32+
if [ $? -ne 0 ]; then
33+
echo export PATH=$PATH:$EC2_HOME/bin >> ~/.bashrc
34+
else
35+
echo "PATH exists"
36+
fi
37+
RES=$(grep "JAVA_HOME" ~/.bashrc)
38+
if [ $? -ne 0 ]; then
39+
echo export JAVA_HOME=/usr/lib/jvm/java-6-sun/jre >> ~/.bashrc
40+
else
41+
echo "JAVA_HOME exists"
42+
fi
43+
RES=$(grep "EC2_DEFAULT_KEY" ~/.bashrc)
44+
if [ $? -ne 0 ]; then
45+
echo export EC2_DEFAULT_KEY=$HOME/Dropbox/config/ec2/Default.pem >> ~/.bashrc
46+
else
47+
echo "EC2_DEFAULT_KEY exists"
48+
fi
49+
50+
echo "Installed environmental variables into ~/.bashrc. Please restart the terminal"

0 commit comments

Comments
 (0)