[Swift-commit] r7252 - trunk/bin

davidk at ci.uchicago.edu davidk at ci.uchicago.edu
Wed Oct 30 12:47:19 CDT 2013


Author: davidk
Date: 2013-10-30 12:47:19 -0500 (Wed, 30 Oct 2013)
New Revision: 7252

Modified:
   trunk/bin/swift-service
Log:
swift-service -start


Modified: trunk/bin/swift-service
===================================================================
--- trunk/bin/swift-service	2013-10-30 17:16:55 UTC (rev 7251)
+++ trunk/bin/swift-service	2013-10-30 17:47:19 UTC (rev 7252)
@@ -72,124 +72,140 @@
             PID_COMM="$pid"
          fi 
 
-         echo "Killing $PID_COMM ($pid)"
+         echo "Killing $PID_COMM ($PID)"
          run_command kill $pid
       done
    fi
    rm $PID_FILE
 }
 
-# Parse command line arguments
-while [ $# -gt 0 ]; do
-   case $1 in
-      -conf) CMDLN_CONF=$2; shift 2;;
-      -start) ;;
-      -stop) stop_service; exit 0;;
-      *) echo "Do not recognize command line option: $1" 1>&2; exit 1;;
-   esac
-done
+# Start coaster service
+start_service()
+{
+   # Import settings
+   if [ -f "$CMDLN_CONF" ]; then
+      CONFIG_FILE=$CMDLN_CONF
+   elif [ -f "coaster-service.conf" ]; then
+      CONFIG_FILE="coaster-service.conf"
+   fi
 
+   echo "Starting Swift service..."
+   if [ -f "$CONFIG_FILE" ]; then
+      echo "Configuration: $CONFIG_FILE"
+      source $CONFIG_FILE
+   fi
 
-# Import settings
-if [ -f "$CMDLN_CONF" ]; then
-   CONFIG_FILE=$CMDLN_CONF
-elif [ -f "coaster-service.conf" ]; then
-   CONFIG_FILE="coaster-service.conf"
-fi
+   # Determine IP address to which workers should connect, and address in sites.xml
+   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
 
-echo "Start-coaster-service..."
-if [ -f "$CONFIG_FILE" ]; then
-   echo "Configuration: $CONFIG_FILE"
-   source $CONFIG_FILE
-fi
+   # Verify we can find coaster service
+   if [ ! -x "$COASTER_SERVICE" ]; then
+      crash "Unable to find $COASTER_SERVICE!"
+   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"
+   if [ -z "$TMPDIR" ]; then
+      TMPDIR=$PWD
    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 "$TMPDIR" ]; then
-   TMPDIR=$PWD
-fi
+   if [ -z "$SERVICE_PORT" ]; then
+      SERVICE_PORT_FILE=$( mktemp $TMPDIR/XXXXXX )
+   fi
 
-# Create files for storing port info, if needed
-if [ -z "$LOCAL_PORT" ]; then
-   LOCAL_PORT_FILE=$( mktemp $TMPDIR/XXXXXX )
-fi
+   # Check values in configuration file to determine how we should start coaster-service
+   echo Launching 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 [ -z "$SERVICE_PORT" ]; then
-   SERVICE_PORT_FILE=$( mktemp $TMPDIR/XXXXXX )
-fi
+   # If waiting on port files to be created, wait for files to be created
+   if [ -z "$SERVICE_PORT" ]; then
+      wait_for_file $SERVICE_PORT_FILE 60
+   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 [ -z "$LOCAL_PORT" ]; then
+      wait_for_file $LOCAL_PORT_FILE 60
+   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!"
+   # 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
-   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!"
+   # 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
-   LOCAL_PORT=$( cat $LOCAL_PORT_FILE )
-   rm $LOCAL_PORT_FILE
-fi
 
-echo Service port: $SERVICE_PORT
-echo Local port: $LOCAL_PORT
+   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"
+   # Generate sites.xml
+   export EXECUTIONURL="http://$IPADDR:$SERVICE_PORT"
+   export WORKERURL="http://$IPADDR:$LOCAL_PORT"
+}
 
-echo Generating sites.xml
+# Create a pool entry for use in sites.xml
+create_pool_entry()
+{
+   echo Creating pool entry
 
-GENSITES_ARGS=""
+   GENSITES_ARGS=""
+   if [ -f "$CONFIG_FILE" ]; then
+      GENSITES_ARGS=" -p $CONFIG_FILE "
+   fi
 
-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
 
-if [ -f "gensites.template" ]; then
-   GENSITES_ARGS=" $( cat gensites.template ) "
-else
-   GENSITES_ARGS=" persistent-coasters "
-fi
+   gensites $GENSITES_ARGS > sites.xml
+}
 
-gensites $GENSITES_ARGS > sites.xml
+# Parse command line arguments
+while [ $# -gt 0 ]; do
+   case $1 in
+      -conf) 
+              CMDLN_CONF=$2
+              shift 2
+              ;;
+      -start)
+              start_service
+              create_pool_entry
+              exit 0
+              ;;
+      -stop) 
+              stop_service
+              exit 0
+              ;;
+      *) echo "Do not recognize command line option: $1" 1>&2; exit 1;;
+   esac
+done




More information about the Swift-commit mailing list