Improved error handling and messages.

This commit is contained in:
Louwrentius 2009-08-09 16:12:23 +00:00
parent 04847e14db
commit ebd7ca55b7

32
ppss.sh
View File

@ -302,7 +302,7 @@ is_running () {
if [ -e "$RUNNING_SIGNAL" ] && [ ! "$MODE" == "kill" ] if [ -e "$RUNNING_SIGNAL" ] && [ ! "$MODE" == "kill" ]
then then
echo echo
log INFO "$0 is already running (lock file exists)." log ERROR "$0 is already running (lock file exists)."
echo echo
exit 1 exit 1
fi fi
@ -649,6 +649,9 @@ expand_str () {
} }
log () { log () {
# Type 'INFO' is logged to the screen
# Any other log-type is only logged to the logfile.
TYPE="$1" TYPE="$1"
MESG="$2" MESG="$2"
@ -663,7 +666,7 @@ log () {
echo -e "$LOG_MSG" >> "$LOGFILE" echo -e "$LOG_MSG" >> "$LOGFILE"
if [ "$TYPE" == "INFO" ] if [ "$TYPE" == "INFO" ] || [ "$TYPE" == "ERROR" ]
then then
echo -e "$LOG_MSG" echo -e "$LOG_MSG"
fi fi
@ -728,7 +731,7 @@ deploy () {
set_error "$?" set_error "$?"
if [ ! "$ERROR" == "0" ] if [ ! "$ERROR" == "0" ]
then then
log INFO "Cannot connect to node $NODE." log ERROR "Cannot connect to node $NODE."
return return
fi fi
@ -783,7 +786,7 @@ deploy_ppss () {
KEY=`echo $SSH_KEY | cut -d " " -f 2` KEY=`echo $SSH_KEY | cut -d " " -f 2`
if [ -z "$KEY" ] || [ ! -e "$KEY" ] if [ -z "$KEY" ] || [ ! -e "$KEY" ]
then then
log INFO "ERROR - nodes require a key file." log ERROR "Nodes require a key file."
cleanup cleanup
set_status "ERROR" set_status "ERROR"
exit 1 exit 1
@ -791,7 +794,7 @@ deploy_ppss () {
if [ ! -e "$SCRIPT" ] && [ ! -z "$SCRIPT" ] if [ ! -e "$SCRIPT" ] && [ ! -z "$SCRIPT" ]
then then
log INFO "ERROR - script $SCRIPT not found." log ERROR "Script $SCRIPT not found."
set_status "ERROR" set_status "ERROR"
cleanup cleanup
exit 1 exit 1
@ -799,7 +802,7 @@ deploy_ppss () {
if [ ! -e "$NODES_FILE" ] if [ ! -e "$NODES_FILE" ]
then then
log INFO "ERROR file $NODES with list of nodes does not exist." log ERROR "File $NODES with list of nodes does not exist."
cleanup cleanup
exit 1 exit 1
else else
@ -1064,7 +1067,7 @@ upload_item () {
ERROR="$?" ERROR="$?"
if [ ! "$ERROR" == "0" ] if [ ! "$ERROR" == "0" ]
then then
log INFO "ERROR - uploading of $ITEM via SCP failed." log ERROR "Uploading of $ITEM via SCP failed."
else else
log DEBUG "Upload of item $ITEM success" log DEBUG "Upload of item $ITEM success"
rm -rf ./"$ITEM" rm -rf ./"$ITEM"
@ -1122,7 +1125,12 @@ get_all_items () {
ITEMS=`exec_cmd "ls -1 $SRC_DIR"` ITEMS=`exec_cmd "ls -1 $SRC_DIR"`
check_status "$?" "$FUNCNAME" "Could not list files within remote source directory." check_status "$?" "$FUNCNAME" "Could not list files within remote source directory."
else else
ITEMS=`ls -1 $SRC_DIR` if [ -e "$SRC_DIR" ]
then
ITEMS=`ls -1 $SRC_DIR`
else
ITEMS=""
fi
fi fi
IFS=$'\n' IFS=$'\n'
@ -1138,7 +1146,7 @@ get_all_items () {
log DEBUG "Running as slave, input file has been pushed (hopefully)." log DEBUG "Running as slave, input file has been pushed (hopefully)."
if [ ! -e "$INPUT_FILE" ] if [ ! -e "$INPUT_FILE" ]
then then
log INFO "ERROR - input file $INPUT_FILE does not exist." log ERROR "Input file $INPUT_FILE does not exist."
set_status "ERROR" set_status "ERROR"
cleanup cleanup
exit 1 exit 1
@ -1159,7 +1167,7 @@ get_all_items () {
SIZE_OF_ARRAY="${#ARRAY[@]}" SIZE_OF_ARRAY="${#ARRAY[@]}"
if [ "$SIZE_OF_ARRAY" -le "0" ] if [ "$SIZE_OF_ARRAY" -le "0" ]
then then
log INFO "ERROR: source file/dir seems to be empty." log ERROR "Source file/dir seems to be empty."
cleanup cleanup
exit 1 exit 1
fi fi
@ -1361,7 +1369,7 @@ commando () {
scp -q $SSH_OPTS $SSH_KEY "$ITEM_LOG_FILE" $USER@$SSH_SERVER:~/$JOB_LOG_DIR/ scp -q $SSH_OPTS $SSH_KEY "$ITEM_LOG_FILE" $USER@$SSH_SERVER:~/$JOB_LOG_DIR/
if [ ! "$?" == "0" ] if [ ! "$?" == "0" ]
then then
log INFO "ERROR - uploading of item log file failed." log ERROR "Uploading of item log file failed."
fi fi
fi fi
fi fi
@ -1481,7 +1489,7 @@ main () {
display_header display_header
if [ ! -e "$NODES_FILE" ] if [ ! -e "$NODES_FILE" ]
then then
log INFO "ERROR file $NODES with list of nodes does not exist." log ERROR "File $NODES with list of nodes does not exist."
cleanup cleanup
exit 1 exit 1
else else