diff --git a/docker/proxy/Dockerfile b/docker/proxy/Dockerfile index f90a8600..5ce2a0d1 100644 --- a/docker/proxy/Dockerfile +++ b/docker/proxy/Dockerfile @@ -10,7 +10,6 @@ COPY ./config/initproxy.conf /data/nginx/proxy_host/ #RUN touch /etc/s6-overlay/s6-rc.d/user/contents.d/init_user #RUN chmod -R 755 /etc/s6-overlay/s6-rc.d/init_user - COPY ./s6/init_user/init_user.sh /app/init_user.sh RUN chmod +x /app/init_user.sh CMD ["/bin/sh", "-c", "/app/init_user.sh && tail -f /dev/null"] \ No newline at end of file diff --git a/docker/proxy/s6/init_user/init_user.sh b/docker/proxy/s6/init_user/init_user.sh index 7f816d9c..6d24dd91 100644 --- a/docker/proxy/s6/init_user/init_user.sh +++ b/docker/proxy/s6/init_user/init_user.sh @@ -22,10 +22,28 @@ while [ -z "$token" ]; do done echo "Change username(email)" >> /tmp/userlog -curl -X PUT -H "Content-Type: application/json" -H "Authorization: Bearer $token" -d '{"email": "'$username'", "nickname": "admin", "is_disabled": false, "roles": ["admin"]}' http://localhost:81/api/users/1 +while true; do + response=$(curl -X PUT -H "Content-Type: application/json" -H "Authorization: Bearer $token" -d '{"email": "'$username'", "nickname": "admin", "is_disabled": false, "roles": ["admin"]}' http://localhost:81/api/users/1) + if [ $? -eq 0 ]; then + echo "HTTP call successful" + break + else + echo "HTTP call Change username failed, retrying..." >> /tmp/userlog + sleep 5 + fi +done echo "Update password" >> /tmp/userlog -curl -X PUT -H "Content-Type: application/json" -H "Authorization: Bearer $token" -d '{"type":"password","current":"changeme","secret":"'$password'"}' http://localhost:81/api/users/1/auth +while true; do + response=$(curl -X PUT -H "Content-Type: application/json" -H "Authorization: Bearer $token" -d '{"type":"password","current":"changeme","secret":"'$password'"}' http://localhost:81/api/users/1/auth) + if [ $? -eq 0 ]; then + echo "HTTP call successful" + break + else + echo "HTTP call Update password failed, retrying..." >> /tmp/userlog + sleep 5 + fi +done echo "Save to credential" json="{\"username\":\"$username\",\"password\":\"$password\"}" diff --git a/systemd/send_credentials.sh b/systemd/send_credentials.sh index 6e150e88..5652f329 100644 --- a/systemd/send_credentials.sh +++ b/systemd/send_credentials.sh @@ -4,7 +4,7 @@ set -e trap "sleep 1; continue" ERR -try_times=30 +try_times=100 counter=1 portainer_username="admin" @@ -38,7 +38,8 @@ copy_credential() { while true; do set +e - + + sleep 3 printf "Try to get credentials for %d times\n" "$counter" copy_credential "websoft9-git" "/var/websoft9/credential" "websoft9-apphub" "/websoft9/credentials/credential_git" @@ -56,7 +57,6 @@ while true; do fi fi - sleep 3 set -e counter=$((counter + 1))