From dbd864b45e1ee7a92857348345c787820163eb05 Mon Sep 17 00:00:00 2001 From: "martin.fencl" Date: Sun, 21 Dec 2025 11:26:03 +0100 Subject: [PATCH] redo changes --- update_semaphore.yml | 61 +++++--------------------------------------- 1 file changed, 7 insertions(+), 54 deletions(-) diff --git a/update_semaphore.yml b/update_semaphore.yml index 1248608..2158231 100644 --- a/update_semaphore.yml +++ b/update_semaphore.yml @@ -29,7 +29,7 @@ state: present update_cache: yes - - name: Run Semaphore self-update on VM in background (nohup + log) + - name: Run Semaphore self-update on VM in background (nohup) ansible.builtin.command: argv: - sshpass @@ -43,66 +43,19 @@ - bash - -lc - | - set -euo pipefail - - # English comments: store state in user's home (more reliable than /tmp) - STATE_DIR="${XDG_CACHE_HOME:-$HOME/.cache}/semaphore-self-update" - mkdir -p "$STATE_DIR" - - RID="$(date +%s)" - LOG="$STATE_DIR/run-${RID}.log" - PIDF="$STATE_DIR/run-${RID}.pid" - RCF="$STATE_DIR/run-${RID}.rc" - SH="$STATE_DIR/run-${RID}.sh" - - # English comments: write worker script (no variable expansion while writing) - cat > "$SH" <<'EOS' - #!/usr/bin/env bash - set -euo pipefail + nohup bash -c ' unalias docker 2>/dev/null || true - export DOCKER_CLI_HINTS=0 - - echo "=== started: $(date -Is) ===" - echo "host: $(hostname)" - echo "compose: {{ semaphore_compose_file }}" - echo "project: {{ semaphore_project }} service: {{ semaphore_service }}" - echo "USE_SUDO=${USE_SUDO:-0}" - echo - - sleep 15 - - DOCKER="docker" - if [ "${USE_SUDO:-0}" = "1" ]; then - DOCKER="sudo -n docker" - fi - - # English comments: pull explicitly + recreate - $DOCKER compose -p {{ semaphore_project }} -f {{ semaphore_compose_file }} pull {{ semaphore_service }} - $DOCKER compose -p {{ semaphore_project }} -f {{ semaphore_compose_file }} up -d --no-deps --force-recreate {{ semaphore_service }} - - echo - echo "=== finished: $(date -Is) ===" - EOS - - chmod +x "$SH" - - # English comments: start in background, persist output, store pid + rc - nohup env USE_SUDO="{{ lookup('env', 'USE_SUDO') | default('0') }}" \ - bash "$SH" >"$LOG" 2>&1 "$PIDF" - - # English comments: best-effort rc tracking (will be overwritten at end if you add it later) - echo "running" >"$RCF" - - echo "scheduled: pid=$(cat "$PIDF"), log=$LOG, script=$SH, rcfile=$RCF" + DOCKER_CLI_HINTS=0 docker compose \ + -p {{ semaphore_project }} \ + -f {{ semaphore_compose_file }} \ + up -d --no-deps --force-recreate --pull always {{ semaphore_service }} + ' >/dev/null 2>&1 & environment: SSHPASS: "{{ vm_pass }}" register: semaphore_update changed_when: false no_log: "{{ DEBUG == 0 }}" - - name: Show result of Semaphore self-update (debug) ansible.builtin.debug: msg: |