#!/bin/sh # put the node back online PBS_MOM=pbs_mom PBSNODES=/usr/bin/pbsnodes WHEN_IDLE_FLAG=${WHEN_IDLE_FLAG:-"when_idle"} VERBOSE=${VERBOSE:-0} CLEAR_DELAY=${CLEAR_DELAY:-600} # health check if [ ! -x $PBSNODES ]; then echo "Cannot execute $PBSNODES: $!" >&2 exit 1 fi mom_pid=$(pgrep -u root "$PBS_MOM") if [ -z "$mom_pid" ]; then echo "Could not find a running pbs_mom process, will not put node back online" >&2 exit 2 fi # Here we know that pbs_mom is running # Check that the node is offline AND has the idle flag set host=`hostname -f` node_info=`$PBSNODES -a $host` # Is the node currently offline? echo $node_info | grep -q -e "state =.*offline" if [ $? -eq 0 ]; then [ $VERBOSE -gt 0 ] && echo "Node is offline" else [ $VERBOSE -gt 0 ] && echo "Node is not offline" exit 2 fi # Is the node offline with the "when_idle" flag? echo $node_info | grep -q -e "note =.*$WHEN_IDLE_FLAG" if [ $? -eq 0 ]; then [ $VERBOSE -gt 0 ] && echo "Node has flag set" else [ $VERBOSE -gt 0 ] && echo "Node does not have flag set" exit 2 fi # sleep in background until reconfiguration etc have finished # and only then put the node back online ( sleep $CLEAR_DELAY ; logger -p user.notice "Putting node $host back online" ; $PBSNODES -c $host -N "" ) & exit 0