[Swift-commit] r7632 - SwiftApps/cloud
ketan at ci.uchicago.edu
ketan at ci.uchicago.edu
Tue Mar 4 16:20:06 CST 2014
Author: ketan
Date: 2014-03-04 16:20:06 -0600 (Tue, 04 Mar 2014)
New Revision: 7632
Modified:
SwiftApps/cloud/addnodes
Log:
_
Modified: SwiftApps/cloud/addnodes
===================================================================
--- SwiftApps/cloud/addnodes 2014-03-04 16:52:56 UTC (rev 7631)
+++ SwiftApps/cloud/addnodes 2014-03-04 22:20:06 UTC (rev 7632)
@@ -1,8 +1,101 @@
-#!/usr/bin/env python
+#!/bin/bash
-# Add cloud resources to existing pool
+#set -x
-#1. Start the number of instances requested by user
+#env vars needed from start-coaster-service
+WORKER_USERNAME="root" #FIXME
+LOCALPORT="50001"
+WORKERURL="http://140.221.8.75:50001"
+SSH_TUNNELING="yes"
+WORKER_LOCATION="/root"
+WORKER_LOGGING_LEVEL="NONE"
+WORKER_LOG_DIR="/root/workerlog"
+LOG="/tmp/worker.log"
+PID_FILE="/tmp/worker.pid"
-#2. Send and start worker manually on those instances
+# Import settings
+if [ -f "coaster-service.conf" ]; then
+ CONFIG_FILE="coaster-service.conf"
+else
+ echo "Cannot find coaster-service.conf!"
+fi
+echo "Configuration: $CONFIG_FILE"
+sleep 1
+source $CONFIG_FILE
+
+WORKER=$(\which worker.pl)
+KEYPAIR="ketan"
+AMI="ami-cf0953a6"
+
+usage (){
+ printf "Usage: %s -a \"<space separated ip addresses in quotes>\" | -n <nodecount> \n" "${0}"
+}
+
+run_command() {
+ command="$@"
+ echo "Running $command" >> $LOG
+ $command >> $LOG 2>&1
+}
+
+run_command_bg() {
+ command="$@"
+ echo "Running $command" >> $LOG
+ $command >> $LOG 2>&1 &
+ echo $! >> $PID_FILE
+}
+
+start-worker-ssh() {
+ MACHINE=$1
+ # Enable ssh tunneling if needed
+ if [ "$SSH_TUNNELING" == "yes" ]; then
+ run_command_bg ssh -N -T -R *:$LOCAL_PORT:localhost:$LOCAL_PORT "$WORKER_USERNAME@$MACHINE"
+ fi
+ # Connect directly
+ run_command ssh $WORKER_USERNAME@$MACHINE mkdir -p $WORKER_LOCATION
+ run_command scp $WORKER $WORKER_USERNAME@$MACHINE:$WORKER_LOCATION
+ echo "Starting worker on $MACHINE"
+ run_command_bg ssh $WORKER_USERNAME@$MACHINE "WORKER_LOGGING_LEVEL=$WORKER_LOGGING_LEVEL $WORKER_LOCATION/worker.pl $WORKERURL $MACHINE $WORKER_LOG_DIR"
+ return 0
+}
+
+addbyip (){
+ echo "$@"
+ #nodeid="stomp"
+}
+
+addbynum (){
+ echo "$1"
+ #ec2-run-instance -k <key-name> -n 1 <ami-id>
+ runinst=$(ec2-run-instance -k "$KEYPAIR" -g all -n "$1" "$AMI")
+ echo "Waiting for instances to start"
+ sleep 45
+ for i in $(echo $runinst | grep -o '\bi-........\b'); do
+ ip=$(ec2din $i | grep 'running' | awk '{print $15}')
+ start-worker-ssh $ip
+ done
+}
+
+#use getopts to check user options
+while getopts ":a:n:" o ; do
+ case $o in
+ a)
+ addbyip ${OPTARG}
+ ;;
+
+ n)
+ addbynum ${OPTARG}
+ ;;
+
+ *)
+ usage
+ ;;
+ esac
+done
+
+# Add cloud resources to existing pool
+#1. Start the number of instances requested by user
+#2. scp worker to remote host
+#scp worker.pl username@${nodeid}:~/
+#3. Start worker manually
+# WORKER_LOGGING_LEVEL=$WORKER_LOGGING_LEVEL $WORKER_LOCATION/worker.pl http://$IPADDR:$LOCAL_PORT $MACHINE $WORKER_LOG_DIR
More information about the Swift-commit
mailing list