diff --git a/docker/managementconsole/managementconsole_configure.sh b/docker/managementconsole/managementconsole_configure.sh index 4638e58..287fcc2 100644 --- a/docker/managementconsole/managementconsole_configure.sh +++ b/docker/managementconsole/managementconsole_configure.sh @@ -10,32 +10,42 @@ MC_Wait() { while : do - echo Ping Management Console... - MC_Ping - if test $? = 0 ; then - break - fi + echo Check if Management Console has fully started by getting all users + curl -s -u ${USERNAME}:${PASSWORD} http://localhost:8080/api/mc/user/page && break echo sleeping... sleep 2 done - echo Management Console is ready. + echo ; echo Management Console is ready. } -# See if Management Console is alive +# See if Management Console is alive. This works before database connectivity is there MC_Ping() { - curl -s --fail ${MC}/Ping | grep "application<\/string>" || return 1 + curl -s ${MC}/Ping | grep "application<\/string>" || return 1 } +# This only works when MC is completely loaded and configured. + +MC_User_Exists() +{ + echo Check User ${USER_NAME} exists + echo curl -s -u ${USERNAME}:${PASSWORD} "${MC}/api/mc/user/page" grep "${USERNAME}" return 1 + curl -s -u ${USERNAME}:${PASSWORD} "${MC}/api/mc/user/page" | grep '"${USERNAME}" || return' 1 +} + # Call a POST/GET/PUT REST Webservice on Management Console MC_REST() { + echo $@ type=$1; path=$2; shift; shift ; data=$@ - curl -u ${USERNAME}:${PASSWORD} ${data} -X ${type} "${MC}${path}" 1>/dev/null 2>&1 + test -f .json && cat .json + echo curl -i -S -u ${USERNAME}:${PASSWORD} ${data} -X ${type} "${MC}${path}" + curl -i -S -u ${USERNAME}:${PASSWORD} ${data} -X ${type} "${MC}${path}" rc=$? rm -rf .json || true if [ $rc != 0 ]; then - echo "${path} failed with code: ${rc}" + echo "${path} CURL failed with code: ${rc}" return 1 fi + echo CURL succeeded } MC_Change_Password() { @@ -47,9 +57,9 @@ MC_Change_Password() MC_Add_User() { eval un="$1"; eval pw="$2"; eval fullName="$3"; eval email="$4"; groupNames="$5" + echo add user ${un} echo \{\"emailAddress\":\"${email}\",\"fullName\":\"${fullName}\",\"password\":\"${pw}\",\"userName\":\"${un}\",\"groupNames\":\[${groupNames}\]\} > .json - cat .json - MC_REST POST "/api/mc/user/add" "-H Content-Type:application/json" "--data @.json" + MC_REST POST "/api/mc/user/add" "-H Content-Type:application/json" "--data @.json" } MC_Add_Group() { @@ -63,8 +73,7 @@ MC_Restore() #curl -u ${USERNAME}:${PASSWORD} -F fileField=@${FILEPATH}${FILENAME} -F restoreMode=Reset Backupfile=$1; echo MC Restore from Backupfile=${Backupfile} - MC_REST POST "/secure/Restore" "-F fileField=@${Backupfile} -F restoreMode=Reset" - echo MC Restore complete + MC_REST POST "/secure/Restore" "-F fileField=@${Backupfile} -F restoreMode=Reset" || return 1 } MC_Cluster_GetId() { @@ -90,6 +99,7 @@ MC_Roboserver_Delete() server=$1; # 125 MC_REST PUT "/api/mc/cluster/deleteServer/${server}" "" } + MC_Add_Robot() { projectID=$1;FILEPATH=$2; FILENAME=$3; folderName=$4 @@ -104,31 +114,50 @@ if test -f /usr/local/tomcat/bin/configured ; then echo Management Console already configured exit 0 fi -MC_Wait + + +#MC_Wait + +# Wait until the Management console has logged "Server startup in" +while : + RPA_LOG=/usr/local/tomcat/logs/catalina* + do + test -f ${RPA_LOG} || cat ${RPA_LOG} | grep 'Server startup in' && break + echo MC still loading... + sleep 2 + done + # MC_Change_Password ${USERNAME} admin ${PASSWORD} -# echo Add Groups -# MC_Add_Group Developers "build robots" "" -# echo add developers -# MC_Add_Group Roboservers "run the robots" "" -# MC_Add_Group Synchronizers "upload and download robots to a Git Repository" "" -# MC_Add_Group KappletAdmins "create and edit Kapplets" "" -# echo add kappletusers -# MC_Add_Group KappletUsers "run Kapplets" "" -# echo Add Users --- -#MC_Add_User synch £tUw_T3 Synch synch@kofax.com '"Synchronizers"' - -#clusterid=$(MC_Cluster_GetId "Non Production" ) -#MC_Roboserver_Add ${clusterid} "roboserver-service" "50000" +# The following are in the Backup package + # echo Add Groups + # MC_Add_Group Developers "build robots" "" + # MC_Add_Group Roboservers "run the robots" "" + # MC_Add_Group Synchronizers "upload and download robots to a Git Repository" "" + # MC_Add_Group KappletAdmins "create and edit Kapplets" "" + # MC_Add_Group KappletUsers "run Kapplets" "" #Create the roboserver user account so that the roboserver can actually get in and auto-register after the MC restore has completed +echo Zipping Backup package + cd ${KAPOW_HOME}/backup zip -r backup.zip * -MC_Restore ${KAPOW_HOME}/backup/backup.zip +echo Backup package zipped +while : + do + MC_Restore ${KAPOW_HOME}/backup/backup.zip && break + echo Failed to restore. sleep and try again ... + sleep 2 + done +echo Backup restored to MC + +echo Adding Users +echo Adding user ${DEV_NAME} +MC_Add_User "\"${DEV_NAME}\"" "\"${DEV_PASSWORD}\"" "\"${DEV_FULLNAME}\"" "\"${DEV_EMAIL}"\" '"RPA Administrators","Developers","RPA Administrators","KappletAdmins","KappletUsers"' && break -# MC_Add_User "\"${DEV_NAME}\"" "abc123" "\"${DEV_FULLNAME}\"" "\"${DEV_EMAIL}"\" '"RPA Administrators","Developers","RPA Administrators","KappletAdmins","KappletUsers"' -MC_Add_User "\"${DEV_NAME}\"" "\"${DEV_PASSWORD}\"" "\"${DEV_FULLNAME}\"" "\"${DEV_EMAIL}"\" '"RPA Administrators","Developers","RPA Administrators","KappletAdmins","KappletUsers"' +echo Adding roboserver MC_Add_User "\"${ROBOSERVER_MC_USERNAME}\"" "\"${ROBOSERVER_MC_PASSWORD}\"" "'Roboserver'" "roboserver@rpa.com" '"Roboservers"' +echo adding synch MC_Add_User "\"${SYNCH_MC_USERNAME}\"" "\"${SYNCH_MC_PASSWORD}\"" "'Synchronizer'" "synch@rpa.com" '"Synchronizers"' @@ -141,4 +170,7 @@ MC_Add_User "\"${SYNCH_MC_USERNAME}\"" "\"${SYNCH_MC_PASSWORD}\"" "'Synchronizer # MC_Add_Project ... touch /usr/local/tomcat/bin/configured -echo Management Console configured with users, groups and roles \ No newline at end of file +echo Management Console configured with users, groups and roles + + +# unused functions \ No newline at end of file