smartgears get-scopes: try to manage all the scenarios correctly.

This commit is contained in:
Andrea Dell'Amico 2017-09-22 19:23:20 +02:00
parent 72c260b3b4
commit 2d909ff031
2 changed files with 21 additions and 27 deletions

View File

@ -119,7 +119,6 @@
become_user: '{{ smartgears_user }}' become_user: '{{ smartgears_user }}'
shell: /usr/local/bin/get-scopes {{ gcube_admin_token | default('') }} shell: /usr/local/bin/get-scopes {{ gcube_admin_token | default('') }}
when: gcube_admin_token is defined or smartgears_upgrade when: gcube_admin_token is defined or smartgears_upgrade
ignore_errors: True
notify: Restart smartgears notify: Restart smartgears
tags: [ 'smartgears', 'smartgears_conf', 'tomcat' ] tags: [ 'smartgears', 'smartgears_conf', 'tomcat' ]

View File

@ -8,33 +8,39 @@ LOCAL_ETC=/usr/local/etc
LOG_PREFIX="get-scopes: " LOG_PREFIX="get-scopes: "
GHN_ENV_FILE=/etc/default/tomcat-instance-{{ item.http_port }}.local GHN_ENV_FILE=/etc/default/tomcat-instance-{{ item.http_port }}.local
SMARTGEARS_VO_AUTH={{ smartgears_authorized_on_all_scopes }} SMARTGEARS_VO_AUTH={{ smartgears_authorized_on_all_scopes }}
SMARTGEARS_UPGRADE={{ smartgears_upgrade }}
SMARTGEARS_SAVED_STATE_F=saved_scopes_list.xml SMARTGEARS_SAVED_STATE_F=saved_scopes_list.xml
SMARTGEARS_SAVED_STATE_PATH={{ smartgears_user_home }}/SmartGears/$SMARTGEARS_SAVED_STATE_F SMARTGEARS_SAVED_STATE_PATH={{ smartgears_user_home }}/SmartGears/$SMARTGEARS_SAVED_STATE_F
SMARTGEARS_SCRIPTS_DIR={{ smartgears_user_home }}/SmartGears/scripts SMARTGEARS_SCRIPTS_DIR={{ smartgears_user_home }}/SmartGears/scripts
SMARTGEARS_RUNNING_STATE_FILE={{ smartgears_user_home }}/state/ghn.xml
CONTAINER_XML_FILE={{ smartgears_install_path }}/container.xml CONTAINER_XML_FILE={{ smartgears_install_path }}/container.xml
# 0: True, 1: False # 0: True, 1: False
USE_SAVED_STATE=1 USE_SAVED_STATE=1
TOKEN=
RETVAL= RETVAL=
# Scenario: if [ $# -eq 0 ] ; then
# - First installation, no upgrade. if [ -f $SMARTGEARS_RUNNING_STATE_FILE ] ; then
# - The node must run on all VOs if [ "$SMARTGEARS_VO_AUTH" == 'true' ] ; then
# In these cases we use our scopes list # - The node must run on all VOs
logger "$LOG_PREFIX When the node must run on all the VOs a valid token is mandatory, aborting"
if [ "$SMARTGEARS_VO_AUTH" == 'false' ] ; then exit 1
if [ "$SMARTGEARS_UPGRADE" == 'True' ] ; then fi
USE_SAVED_STATE=0 USE_SAVED_STATE=0
logger "$LOG_PREFIX setting the correct variables so that we are going to use the local scopes" echo "No token, assuming that we can use the local state"
logger "$LOG_PREFIX No token, assuming that we can use the local state"
else else
logger "$LOG_PREFIX We are going to use our scopes list. A valid token is mandatory" # - First installation, no upgrade.
logger "$LOG_PREFIX No token was passed and not working state available, aborting"
exit 1
fi fi
elif [ $# -eq 1 ] ; then
logger "$LOG_PREFIX We have an authorization token"
TOKEN=$1
else else
logger "$LOG_PREFIX We are going to use our scopes list. A valid token is mandatory" logger "$LOG_PREFIX More than one parameter was passed, aborting"
exit 1
fi fi
SCOPES_LIST="" SCOPES_LIST=""
@ -45,16 +51,6 @@ else
exit 1 exit 1
fi fi
if [ $# -ne 1 -a $USE_SAVED_STATE -ne 0 ] ; then
echo "The token must be passed as the sole argument when we are not using the local state"
logger "$LOG_PREFIX The token must be passed as the sole argument when we are not using the local state"
exit 1
elif [ $# -eq 1 ] ; then
logger "$LOG_PREFIX We have an authorization token"
TOKEN=$1
fi
{%if setup_nginx %} {%if setup_nginx %}
HTTP_PORT={{ http_port }} HTTP_PORT={{ http_port }}
{% else %} {% else %}
@ -94,13 +90,12 @@ cd $SMARTGEARS_SCRIPTS_DIR
./clean-container-state -s $SMARTGEARS_SAVED_STATE_F ./clean-container-state -s $SMARTGEARS_SAVED_STATE_F
RETVAL=$? RETVAL=$?
if [ $RETVAL -ne 0 ] ; then if [ $RETVAL -ne 0 ] ; then
# We were not able to get the running state from the IS. We get new ones # We were not able to get the running state from the IS. Try to get new scope tokens
logger "$LOG_PREFIX We were not able to get the running state from the IS. We get new ones from the authorization service" logger "$LOG_PREFIX We were not able to get the running state from the IS. Try to get new scope tokens from the authorization service"
SCOPES_FILE={{ smartgears_user_home }}/.containerxml/2-container.xml SCOPES_FILE={{ smartgears_user_home }}/.containerxml/2-container.xml
get_scopes_from_auth get_scopes_from_auth
fi fi
# Now that we have the tokens, we can assemble the container.xml file # Now that we have the tokens, we can assemble the container.xml file
chmod 640 $CONTAINER_XML_FILE chmod 640 $CONTAINER_XML_FILE
CREATE_CONTAINER_XML_RES=0 CREATE_CONTAINER_XML_RES=0