diff options
author | Paul Sokolovsky <paul.sokolovsky@linaro.org> | 2011-06-15 20:25:22 +0300 |
---|---|---|
committer | Paul Sokolovsky <paul.sokolovsky@linaro.org> | 2011-06-15 20:25:22 +0300 |
commit | c56f0415a14f6d1013468dd29f337969df4c106d (patch) | |
tree | 6f81129e8d7d54784fb94a5fb8fb8edc9be81356 /control/start-instance | |
parent | 94003df449a395e89dd342fd7d15caab2add3e2e (diff) |
Add scripts to automate cloud-buildd install.
* start-instance - reliably start EC2 instance
* install-control-via-ssh - install cloud-buildd over SSH
* sandbox-create - combines two above into magic sandbox create script
Diffstat (limited to 'control/start-instance')
-rwxr-xr-x | control/start-instance | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/control/start-instance b/control/start-instance new file mode 100755 index 0000000..a6be823 --- /dev/null +++ b/control/start-instance @@ -0,0 +1,86 @@ +#!/bin/bash +############################################################################### +# Copyright (c) 2011 Linaro +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v1.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/epl-v10.html +############################################################################### +# +# Script/functions to create EC2 instance and make sure it's running +# + +AMI=ami-e2af508b +TYPE="-t m1.small" +SEC_GROUPS="-g git-mirror -g jenkins-master" + +function ec2_create_instance() { + local keypair=$1 + echo "Creating instance..." + local cmd="ec2-run-instances $AMI -k $keypair $TYPE $SEC_GROUPS" +# echo $cmd + instance_id=`$cmd | grep ^INSTANCE | cut -f2` + if [ -z "$instance_id" ]; then + echo "Error executing: $cmd" + exit 1 + fi +} + +function ec2_wait_till_running() { + local instance=$1 + echo -n "Waiting for instance to start..." + while true; do + instance_hostname=`ec2-describe-instances $instance | grep ^INSTANCE | cut -f4` + if [ -n "$instance_hostname" ]; then + break + fi + sleep 1 + echo -n . + done + echo +} + +function ec2_wait_till_booted() { + local hostname=$1 + echo -n "Waiting for instance to boot..." +# echo ssh -o StrictHostKeyChecking=no ubuntu@$hostname true + cnt=0 + while true; do + cnt=$(($cnt + 1)) + ssh -q -o StrictHostKeyChecking=no ubuntu@$hostname true + rc=$? +# echo "try$cnt: rc=$rc" + echo -n . + if [ $rc -eq 0 ]; then + break + fi + if [ $cnt -gt 20 ]; then + break + fi + sleep 1 + done + echo + [ $rc -eq 0 ] +} + +function ec2_start_instance() { + ec2_create_instance $* + ec2_wait_till_running $instance_id + if ! ec2_wait_till_booted $instance_hostname; then + echo "Error starting instance" + fi +} + + +if [ "$1" != "--include" ]; then + + if [ "$1" == "" ]; then + echo "Usage: $0 <ec2 keypair name>" + exit + fi + + ec2_start_instance $1 + echo "Instance ID: $instance_id" + echo "Hostname: $instance_hostname" + +fi |