#!/bin/sh
if [ -n "$AWS_PORT" ]; then
echo "AWS_PORT already set to $AWS_PORT"
else
echo "AWS_PORT not set, put it to default : 5487"
export AWS_PORT=5487
fi
export SUB_SYSTEM=`narval_shell --end_point http://localhost:$AWS_PORT get sub_systems| grep $1`
if [ -n "$SUB_SYSTEM" ]; then
echo "system $1 present"
else
echo "system $1 not present"
exit 1
fi
export STATE=`narval_shell --end_point http://localhost:$AWS_PORT get state $1|grep ERROR`
if [ -n "$STATE" ]; then
echo "system $1 in error, going to clean"
narval_shell --end_point http://localhost:$AWS_PORT set action full_reset $1
narval_shell --end_point http://localhost:$AWS_PORT set action finish $1
else
echo "system $1 not in error state, doing nothing"
fi
