diff --git a/seafile-caddy/scripts/start.sh b/seafile-caddy/scripts/start.sh index 409a8dc..ae2c6b2 100644 --- a/seafile-caddy/scripts/start.sh +++ b/seafile-caddy/scripts/start.sh @@ -1,5 +1,11 @@ #!/bin/bash -/scripts/swarm-dns.sh & +if [ "$SWARM_DNS" = true ]; then + /scripts/swarm-dns.sh & +fi -caddy run --config /etc/caddy/Caddyfile --adapter caddyfile +caddy run --config /etc/caddy/Caddyfile --adapter caddyfile & + +wait -n + +exit $? \ No newline at end of file diff --git a/seafile-caddy/scripts/swarm-dns.sh b/seafile-caddy/scripts/swarm-dns.sh index 7ba1361..e36608c 100644 --- a/seafile-caddy/scripts/swarm-dns.sh +++ b/seafile-caddy/scripts/swarm-dns.sh @@ -1,28 +1,25 @@ #!/bin/bash -if [ "$SWARM_DNS" = true ]; then - - cp /etc/caddy/Caddyfile /etc/caddy/Caddyfile.default - - while true; do +cp /etc/caddy/Caddyfile /etc/caddy/Caddyfile.default - SEAHUB_IPS=$(dig +short $SEAHUB_HOSTNAME | sed -e 's/$/:8000/' | tr ' ' '\n' | sort | tr '\n' ' ') - SEAHUB_MEDIA_IPS=$(dig +short $SEAHUB_MEDIA_HOSTNAME | sed -e 's/$/:80/' | tr ' ' '\n' | sort | tr '\n' ' ') +while true; do - cp /etc/caddy/Caddyfile.default /etc/caddy/Caddyfile.tmp + SEAHUB_IPS=$(dig +short $SEAHUB_HOSTNAME | sed -e 's/$/:8000/' | tr ' ' '\n' | sort | tr '\n' ' ') + SEAHUB_MEDIA_IPS=$(dig +short $SEAHUB_MEDIA_HOSTNAME | sed -e 's/$/:80/' | tr ' ' '\n' | sort | tr '\n' ' ') - sed -i "s/$SEAHUB_HOSTNAME:8000/$(echo $SEAHUB_IPS)/g" /etc/caddy/Caddyfile.tmp - sed -i "s/$SEAHUB_MEDIA_HOSTNAME:80/$(echo $SEAHUB_MEDIA_IPS)/g" /etc/caddy/Caddyfile.tmp + cp /etc/caddy/Caddyfile.default /etc/caddy/Caddyfile.tmp - if ! diff -q "/etc/caddy/Caddyfile" "/etc/caddy/Caddyfile.tmp"; then - rm -f /etc/caddy/Caddyfile - mv /etc/caddy/Caddyfile.tmp /etc/caddy/Caddyfile - echo "Applying new Caddyfile:" - cat /etc/caddy/Caddyfile - caddy reload --config /etc/caddy/Caddyfile - fi + sed -i "s/$SEAHUB_HOSTNAME:8000/$(echo $SEAHUB_IPS)/g" /etc/caddy/Caddyfile.tmp + sed -i "s/$SEAHUB_MEDIA_HOSTNAME:80/$(echo $SEAHUB_MEDIA_IPS)/g" /etc/caddy/Caddyfile.tmp - sleep 10 + if ! diff -q "/etc/caddy/Caddyfile" "/etc/caddy/Caddyfile.tmp"; then + rm -f /etc/caddy/Caddyfile + mv /etc/caddy/Caddyfile.tmp /etc/caddy/Caddyfile + echo "Applying new Caddyfile:" + cat /etc/caddy/Caddyfile + caddy reload --config /etc/caddy/Caddyfile + fi - done -fi + sleep 10 + +done \ No newline at end of file