diff --git a/systemd/send_credentials.sh b/systemd/send_credentials.sh index 851389f0..3549b57a 100644 --- a/systemd/send_credentials.sh +++ b/systemd/send_credentials.sh @@ -4,24 +4,48 @@ set -e trap "sleep 1; continue" ERR +counter=0 while true; do + set +e - echo "copy git credential" - docker cp websoft9-git:/var/websoft9/credential /data/websoft9/credential_git - docker cp /data/websoft9/credential_git websoft9-apphub:/websoft9/credentials - - echo "copy deployment credential" - docker cp websoft9-deployment:/var/websoft9/credential /data/websoft9/credential_deployment - content=$(cat /data/websoft9/credential_deployment) - username="admin" - json="{\"username\":\"$username\",\"password\":\"$content\"}" - echo "$json" > /data/websoft9/credential_deployment - docker cp /data/websoft9/credential_deployment websoft9-apphub:/websoft9/credentials - - echo "wait nginx..." - docker cp websoft9-proxy:/var/websoft9/credential /data/websoft9/credential_proxy - docker cp /data/websoft9/credential_proxy websoft9-apphub:/websoft9/credentials + if [ -f "/data/websoft9/credential_git" ]; then + echo "/data/websoft9/credential_git is exist" + else + echo "copy git credential" + docker cp websoft9-git:/var/websoft9/credential /data/websoft9/credential_git + docker cp /data/websoft9/credential_git websoft9-apphub:/websoft9/credentials + fi + + if [ -f "/data/websoft9/credential_deployment" ]; then + echo "/data/websoft9/credential_deployment is exist" + else + echo "copy deployment credential" + docker cp websoft9-deployment:/var/websoft9/credential /data/websoft9/credential_deployment + content=$(cat /data/websoft9/credential_deployment) + username="admin" + json="{\"username\":\"$username\",\"password\":\"$content\"}" + echo "$json" > /data/websoft9/credential_deployment + docker cp /data/websoft9/credential_deployment websoft9-apphub:/websoft9/credentials + fi + + if [ -f "/data/websoft9/credential_proxy" ]; then + echo "/data/websoft9/credential_proxy is exist" + else + echo "copy nginx credential ..." + docker cp websoft9-proxy:/var/websoft9/credential /data/websoft9/credential_proxy + docker cp /data/websoft9/credential_proxy websoft9-apphub:/websoft9/credentials + fi + + if [ -f "/data/websoft9/credential_git" ] && [ -f "/data/websoft9/credential_deployment" ] && [ -f "/data/websoft9/credential_proxy" ]; then + exit 0 + else + if [ $counter -gt 30 ]; then + echo "Systemd can not get all credentials by excuting 30 times" + exit 1 + fi + fi + set -e sleep 3 done \ No newline at end of file