diff --git a/cookcli/rootfs/etc/cont-init.d/99-nginx-config.sh b/cookcli/rootfs/etc/cont-init.d/99-nginx-config.sh index baf940a..6bce255 100644 --- a/cookcli/rootfs/etc/cont-init.d/99-nginx-config.sh +++ b/cookcli/rootfs/etc/cont-init.d/99-nginx-config.sh @@ -55,6 +55,12 @@ http { proxy_redirect http://127.0.0.1:9081/ \$scheme://\$host${INGRESS_PATH}/; proxy_redirect http://127.0.0.1:9081 \$scheme://\$host${INGRESS_PATH}; } + + location = /api/reload { + limit_except POST { deny all; } + proxy_pass http://127.0.0.1:8098; + proxy_read_timeout 120s; + } } } diff --git a/cookcli/rootfs/etc/services.d/git-sync/run b/cookcli/rootfs/etc/services.d/git-sync/run index e6429c5..809bb08 100644 --- a/cookcli/rootfs/etc/services.d/git-sync/run +++ b/cookcli/rootfs/etc/services.d/git-sync/run @@ -1,70 +1,8 @@ #!/usr/bin/with-contenv bashio -set -e +INTERVAL=$(bashio::config 'git_sync_interval') +[ -z "$INTERVAL" ] || [ "$INTERVAL" -eq 0 ] && INTERVAL=3600 -# --- Fonction de synchronisation Git --- -sync_git() { - local REPO=$(bashio::config 'git_repository') - local BRANCH=$(bashio::config 'git_branch') - local USERNAME=$(bashio::config 'git_username') - local PASSWORD=$(bashio::config 'git_password') - local RECIPES_PATH=/config/recipes - - if [ -z "$REPO" ]; then - bashio::log.info "Aucun dépôt Git configuré. Attente..." - sleep infinity - return - fi - - bashio::log.info "Synchronisation avec ${REPO} (branche: ${BRANCH})" - - # Construction de l'URL avec authentification si nécessaire - local AUTH_URL="$REPO" - if [ -n "$USERNAME" ] && [ -n "$PASSWORD" ]; then - # Supposons que l'URL est de type https://github.com/user/repo.git - local PROTOCOL="https://" - local REPO_WITHOUT_PROTOCOL="${REPO#https://}" - REPO_WITHOUT_PROTOCOL="${REPO_WITHOUT_PROTOCOL#http://}" - AUTH_URL="${PROTOCOL}${USERNAME}:${PASSWORD}@${REPO_WITHOUT_PROTOCOL}" - bashio::log.info "Authentification configurée pour ${USERNAME}" - fi - - # Clone ou pull - if [ ! -d "$RECIPES_PATH/.git" ]; then - bashio::log.info "Premier clone du dépôt..." - git clone --branch "$BRANCH" "$AUTH_URL" "$RECIPES_PATH" 2>&1 | bashio::log.info - else - bashio::log.info "Mise à jour du dépôt existant..." - cd "$RECIPES_PATH" - # Réinitialisation pour éviter les conflits - git fetch origin "$BRANCH" 2>&1 | bashio::log.info - git reset --hard "origin/$BRANCH" 2>&1 | bashio::log.info - cd - > /dev/null - fi - - bashio::log.info "Synchronisation Git terminée." -} - -# --- Fonction de synchronisation périodique --- -periodic_sync() { - local INTERVAL=$(bashio::config 'git_sync_interval') - if [ -z "$INTERVAL" ] || [ "$INTERVAL" -eq 0 ]; then - INTERVAL=3600 - fi - - bashio::log.info "Synchronisation périodique configurée toutes les ${INTERVAL}s" - - while true; do - sleep "$INTERVAL" - bashio::log.info "=== Synchronisation Git périodique ===" - sync_git - done -} - -# --- Exécution --- -bashio::log.info "=== Service de synchronisation Git ===" - -# Premier sync au démarrage -sync_git - -# Lancement du sync périodique en arrière-plan -periodic_sync \ No newline at end of file +while true; do + /usr/local/bin/git-sync-now.sh || bashio::log.warning "Échec de la synchro Git" + sleep "$INTERVAL" +done \ No newline at end of file diff --git a/cookcli/rootfs/etc/services.d/reload-listener/run b/cookcli/rootfs/etc/services.d/reload-listener/run new file mode 100644 index 0000000..c3dfa39 --- /dev/null +++ b/cookcli/rootfs/etc/services.d/reload-listener/run @@ -0,0 +1,2 @@ +#!/usr/bin/with-contenv bashio +exec socat TCP-LISTEN:8098,bind=127.0.0.1,fork,reuseaddr EXEC:/usr/local/bin/reload-http.sh \ No newline at end of file diff --git a/cookcli/rootfs/usr/local/bin/git-sync-now.sh b/cookcli/rootfs/usr/local/bin/git-sync-now.sh new file mode 100644 index 0000000..0dc6654 --- /dev/null +++ b/cookcli/rootfs/usr/local/bin/git-sync-now.sh @@ -0,0 +1,31 @@ +#!/usr/bin/with-contenv bashio +RECIPES_PATH=/config/recipes + +exec 9>/tmp/git-sync.lock +flock -n 9 || { bashio::log.info "Synchro déjà en cours"; exit 0; } + +REPO=$(bashio::config 'git_repository') +BRANCH=$(bashio::config 'git_branch') +USERNAME=$(bashio::config 'git_username') +PASSWORD=$(bashio::config 'git_password') + +if [ -z "$REPO" ]; then + bashio::log.info "Aucun dépôt Git configuré." + exit 0 +fi + +AUTH_URL="$REPO" +if [ -n "$USERNAME" ] && [ -n "$PASSWORD" ]; then + STRIPPED="${REPO#https://}"; STRIPPED="${STRIPPED#http://}" + AUTH_URL="https://${USERNAME}:${PASSWORD}@${STRIPPED}" +fi + +if [ ! -d "$RECIPES_PATH/.git" ]; then + bashio::log.info "Premier clone du dépôt..." + git clone --branch "$BRANCH" "$AUTH_URL" "$RECIPES_PATH" +else + bashio::log.info "Mise à jour du dépôt existant..." + git -C "$RECIPES_PATH" fetch origin "$BRANCH" + git -C "$RECIPES_PATH" reset --hard "origin/$BRANCH" +fi +bashio::log.info "Synchronisation Git terminée." \ No newline at end of file diff --git a/cookcli/rootfs/usr/local/bin/reload-http.sh b/cookcli/rootfs/usr/local/bin/reload-http.sh new file mode 100644 index 0000000..9d6fe98 --- /dev/null +++ b/cookcli/rootfs/usr/local/bin/reload-http.sh @@ -0,0 +1,11 @@ +#!/usr/bin/with-contenv bashio +# Consomme la requête jusqu'à la ligne vide +while IFS= read -r line; do line="${line%$'\r'}"; [ -z "$line" ] && break; done + +if /usr/local/bin/git-sync-now.sh >/dev/null 2>&1; then + status="200 OK"; body='{"status":"ok"}' +else + status="500 Internal Server Error"; body='{"status":"error"}' +fi +printf 'HTTP/1.1 %s\r\nContent-Type: application/json\r\nContent-Length: %d\r\nConnection: close\r\n\r\n%s' \ + "$status" "${#body}" "$body" \ No newline at end of file