[Swift-commit] r7242 - trunk/bin
davidk at ci.uchicago.edu
davidk at ci.uchicago.edu
Tue Oct 29 13:35:49 CDT 2013
Author: davidk
Date: 2013-10-29 13:35:49 -0500 (Tue, 29 Oct 2013)
New Revision: 7242
Added:
trunk/bin/swift-service
Log:
Start of a new swift-service command
Added: trunk/bin/swift-service
===================================================================
--- trunk/bin/swift-service (rev 0)
+++ trunk/bin/swift-service 2013-10-29 18:35:49 UTC (rev 7242)
@@ -0,0 +1,157 @@
+#!/bin/bash
+
+# Report a problem and exit
+crash()
+{
+ MSG=$1
+ echo ${MSG} >&2
+ exit 1
+}
+
+# Wait for a file to be created, up to given amount of time
+wait_for_file()
+{
+ FILE=$1
+ TIME=$2
+ count=0
+ while [ ! -s "$FILE" ]; do
+ sleep 1
+ (( count += 1 ))
+ if [ $count -ge $TIME ]; then
+ crash "Timed out waiting for coaster port file $FILE"
+ fi
+ done
+}
+
+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
+}
+
+# Parse command line arguments
+while [ $# -gt 0 ]; do
+ case $1 in
+ -conf) CMDLN_CONF=$2; shift 2;;
+ -start) ;;
+ -stop) ;;
+ *) echo "Do not recognize command line option: $1" 1>&2; exit 1;;
+ esac
+done
+
+# Determine the location of needed files
+export SWIFT_BIN="$( cd "$( dirname "$0" )" && pwd )"
+export WORKER="$SWIFT_BIN/worker.pl"
+export PID_FILE="$HOME/.swift/.coaster-service-pids"
+export COASTER_SERVICE="$SWIFT_BIN/coaster-service"
+export LOG="start-coaster-service.log"
+mkdir -p "$HOME/.swift" || crash "Unable to create $HOME/.swift"
+
+# Import settings
+if [ -f "$CMDLN_CONF" ]; then
+ CONFIG_FILE=$CMDLN_CONF
+elif [ -f "coaster-service.conf" ]; then
+ CONFIG_FILE="coaster-service.conf"
+fi
+
+echo "Start-coaster-service..."
+if [ -f "$CONFIG_FILE" ]; then
+ echo "Configuration: $CONFIG_FILE"
+ source $CONFIG_FILE
+fi
+
+# Determine IP address to which workers should connect
+if [ -z "$IPADDR" ]; then
+ if [ "$SSH_TUNNELING" == "yes" ]; then
+ IPADDR=localhost
+ elif [ -n "$GLOBUS_HOSTNAME" ]; then
+ IPADDR=$GLOBUS_HOSTNAME
+ else
+ IPADDR="127.0.0.1"
+ fi
+fi
+
+# Verify we can find coaster service
+if [ ! -x "$COASTER_SERVICE" ]; then
+ crash "Unable to find $COASTER_SERVICE!"
+fi
+
+# Create files for storing port info, if needed
+if [ -z "$LOCAL_PORT" ]; then
+ LOCAL_PORT_FILE=$( mktemp $TMPDIR/XXXXXX )
+fi
+
+if [ -z "$SERVICE_PORT" ]; then
+ SERVICE_PORT_FILE=$( mktemp $TMPDIR/XXXXXX )
+fi
+
+# Check values in configuration file to determine how we should start coaster-service
+echo Starting coaster-service
+if [ -z "$SERVICE_PORT" ] && [ -z "$LOCAL_PORT" ]; then
+ run_command_bg $COASTER_SERVICE -nosec -portfile $SERVICE_PORT_FILE -localportfile $LOCAL_PORT_FILE -passive
+elif [ -n "$SERVICE_PORT" ] && [ -z "$LOCAL_PORT" ]; then
+ run_command_bg $COASTER_SERVICE -nosec -port $SERVICE_PORT -localportfile $LOCAL_PORT_FILE -passive
+elif [ -z "$SERVICE_PORT" ] && [ -n "$LOCAL_PORT" ]; then
+ run_command_bg $COASTER_SERVICE -nosec -portfile $SERVICE_PORT_FILE --localport $LOCAL_PORT -passive
+elif [ -n "$SERVICE_PORT" ] && [ -n "$LOCAL_PORT" ]; then
+ run_command_bg $COASTER_SERVICE -nosec -port $SERVICE_PORT -localport $LOCAL_PORT -passive
+fi
+
+# If waiting on port files to be created, wait for files to be created, but no longer
+if [ -z "$SERVICE_PORT" ]; then
+ wait_for_file $SERVICE_PORT_FILE 60
+fi
+
+if [ -z "$LOCAL_PORT" ]; then
+ wait_for_file $LOCAL_PORT_FILE 60
+fi
+
+# Determine SERVICE_PORT
+if [ -z "$SERVICE_PORT" ]; then
+ if [ ! -f "$SERVICE_PORT_FILE" ]; then
+ crash "Unable to determine SERVICE_PORT!"
+ fi
+ SERVICE_PORT=$( cat $SERVICE_PORT_FILE )
+ rm $SERVICE_PORT_FILE
+fi
+
+# Determine LOCAL_PORT
+if [ -z "$LOCAL_PORT" ]; then
+ if [ ! -f "$LOCAL_PORT_FILE" ]; then
+ crash "Unable to determine LOCAL_PORT!"
+ fi
+ LOCAL_PORT=$( cat $LOCAL_PORT_FILE )
+ rm $LOCAL_PORT_FILE
+fi
+
+echo Service port: $SERVICE_PORT
+echo Local port: $LOCAL_PORT
+
+# Generate sites.xml
+export EXECUTIONURL="http://$IPADDR:$SERVICE_PORT"
+export WORKERURL="http://$IPADDR:$LOCAL_PORT"
+
+echo Generating sites.xml
+
+GENSITES_ARGS=""
+
+if [ -f "$CONFIG_FILE" ]; then
+ GENSITES_ARGS=" -p $CONFIG_FILE "
+fi
+
+if [ -f "gensites.template" ]; then
+ GENSITES_ARGS=" $( cat gensites.template ) "
+else
+ GENSITES_ARGS=" persistent-coasters "
+fi
+
+gensites $GENSITES_ARGS > sites.xml
Property changes on: trunk/bin/swift-service
___________________________________________________________________
Added: svn:executable
+ *
More information about the Swift-commit
mailing list