redo changes

This commit is contained in:
martin.fencl
2025-12-21 11:26:03 +01:00
parent 8d1b2cd065
commit dbd864b45e

View File

@@ -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 </dev/null &
echo $! >"$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: |