Simplest Enterprise Continuous Integration Solutions

Monday, June 13, 2011

Enterprise Linux - SGE submit host automatic configuration

SGE automated (execution) installation updates <hostname> into @allhost and [<hostname>=<cpu_processor_count>] into all.q slots automatically, sometime automatic configure a host to be a dedicated submit host only will be required. Here is an example script (submit_host_only.sh) for this purpose:



#!/bin/sh


TMP_DIR="/tmp"
# retrieve SGE_ROOT from SGE startup script (i.e. /etc/init.d/sgemaster. or /etc/init.d/sgeexecd.)
SGE_SCRIPTUP_DIR="/etc/init.d"
SGE_STARTUP_SCRIPT=`ls ${SGE_SCRIPTUP_DIR} | /bin/grep "sgemaste.*"`
if [ "$SGE_STARTUP_SCRIPT" = "" ]; then
   SGE_STARTUP_SCRIPT=`ls ${SGE_SCRIPTUP_DIR} | /bin/grep "sgeexec.*"`
fi
if [ -e "${SGE_SCRIPTUP_DIR}/${SGE_STARTUP_SCRIPT}" ]; then
   SGE_ROOT=`cat ${SGE_SCRIPTUP_DIR}/${SGE_STARTUP_SCRIPT} | /bin/grep ^SGE_ROOT | cut -d";" -f1,1 | cut -d"=" -f2,2`
   CELL_NAME=`cat ${SGE_SCRIPTUP_DIR}/${SGE_STARTUP_SCRIPT} | /bin/grep ^SGE_CELL | cut -d";" -f1,1 | cut -d"=" -f2,2`
fi


# make sense only SGE_ROOT exists
if [ -d "${SGE_ROOT}" ]; then
   if [ -e "${SGE_ROOT}/${CELL_NAME}/common/settings.sh" ]; then
      . "${SGE_ROOT}/${CELL_NAME}/common/settings.sh"
      # get SGE hostname
      ARCH=`${SGE_ROOT}/util/arch`
      SGE_UTILBIN="${SGE_ROOT}/utilbin/${ARCH}"
      SGE_HOSTNAME=`${SGE_UTILBIN}/gethostname -aname`
      MY_HOSTNAME_SHORT=`${SGE_UTILBIN}/gethostname -aname | cut -f1 -d.`
      # get processor count
      SGE_PROCESSER_COUNT=`qhost | /bin/grep "${MY_HOSTNAME_SHORT} " | /bin/awk '{print $3}'`
      # remove SGE_HOSTNAME from @allhost
      qconf -shgrp @allhosts > ${TMP_DIR}/remove_from_host_grp
      /bin/sed -i "s/ ${SGE_HOSTNAME}//g" ${TMP_DIR}/remove_from_host_grp
      qconf -Mhgrp ${TMP_DIR}/remove_from_host_grp
      # remove SGE_HOSTNAME from slots of all.q
      qconf -sq all.q | /bin/sed "s/^ .*$//g" | /bin/sed "s/^slots.*$//g" > ${TMP_DIR}/remove_from_all_q_no_slots
      qconf -sq all.q | /bin/awk "/^ |^slots/" | /bin/sed -e :a -e N -e 's/\n/ /' -e ta | /bin/sed 's/\\//g' | /bin/sed 's/ //g' | /bin/sed 's/slots/slots /g' | /bin/sed "s/,\[${SGE_HOSTNAME}=${SGE_PROCESSER_COUNT}\]//g" >> ${TMP_DIR}/remove_from_all_q_no_slots
      qconf -Mq ${TMP_DIR}/remove_from_all_q_no_slots
   fi
fi

No comments:

Post a Comment