From b044b6da7f584f3038ac995c4a53e44f1135d9d3 Mon Sep 17 00:00:00 2001 From: Malfurious Date: Tue, 31 Oct 2023 10:56:12 -0400 Subject: acid: Rework build log records Two new pieces of metadata are now included in a job record: the git commit hash, and an indicator of the job execution reason (aka: push event, or periodic maintenance). The job records themselves are converted into directories containing files which define these metadata. Previously, all metadata was packed (underscore-delimited) into the log filename. The indication of job PASS/FAIL is no longer given by a line of text appended to the log. Instead, a file named 'fail' will exist in the directories of failed jobs. The semantics of the status file are further defined by this patch as well. The file will contain: "": when the system is idle "maint": when maintenance is in progress (inbetween jobs) a job number: when a job is in progress and the file will _always_ exist. Signed-off-by: Malfurious --- acid/acid | 66 ++++++++++++++++++++++++++++++--------------------------------- 1 file changed, 31 insertions(+), 35 deletions(-) diff --git a/acid/acid b/acid/acid index d75e475..a22450c 100755 --- a/acid/acid +++ b/acid/acid @@ -7,6 +7,7 @@ CYCHE_SERVICE_DIR="/data/services" CYCHE_LOG_DIR="/data/logs" CYCHE_STATUS_FILE="/data/status" +CYCHE_TMP_LOG="/tmp/tmp.log" NULL_HASH="0000000000000000000000000000000000000000" source config.sh @@ -24,54 +25,48 @@ prune_logs() { ls -A "$CYCHE_LOG_DIR" \ | sort -n | head -n "$((CYCHE_LOG_SIZE*-1))" \ | sed "s?^?$CYCHE_LOG_DIR/?" \ - | xargs rm -f + | xargs rm -rf } -log_filename() { - latest=$(ls -A "$CYCHE_LOG_DIR" | sort -rn | sed 's/_.*$//;1q') - [ -z "$latest" ] && number="0" || number=$((latest+1)) - printf '%s/%s_%s_%s.log' "$CYCHE_LOG_DIR" "$number" "$(now)" "$1" -} - -do_job() { - hash=$(acid-source "$1" "$2" "$3") - res=$? - - if [ $res -eq 2 ]; then - echo -e "\n\nJOB FAILED" - return 1 - fi - - if [ $res -eq 1 ] || [ "$5" == "--force" ]; then - if ! acid-build "$1" "$4" "$hash" "$6"; then - echo -e "\n\nJOB FAILED" - fi - return 1 - fi - - return 0 +make_log() { + latest=$(ls -A "$CYCHE_LOG_DIR" | sort -rn | head -n1) + [ -z "$latest" ] && job="0" || job=$((latest+1)) + logdir="$CYCHE_LOG_DIR/$job" + mkdir -p "$logdir" + echo "$1" >"$logdir/hash" + echo "$2" >"$logdir/reason" + echo "$3" >"$logdir/service" + echo "$(now)" >"$logdir/time" + touch "$logdir/log" + echo "$job" } update() { forceopt="--force-self" selfopt="--self" + [ -z "$1" ] && reason="event" || reason="maint" + for line in "${CYCHE_SERVICES[@]}"; do read -r -a arr <<< "$line" + hash=$(acid-source ${arr[@]:0:3} 2>"$CYCHE_TMP_LOG") + res=$? - log=$(log_filename "${arr[0]}") - [ "$1" == "$forceopt" ] && f="--force" || f="" + if [ $res -ne 0 ] || [ "$1" == "$forceopt" ]; then + job=$(make_log "$hash" "$reason" "${arr[0]}") + logdir="$CYCHE_LOG_DIR/$job" + log="$logdir/log" - echo "$log" >"$CYCHE_STATUS_FILE" - do_job $line "$f" "$selfopt" >"$log" 2>&1 - res=$? - truncate -s 0 "$CYCHE_STATUS_FILE" + cp "$CYCHE_TMP_LOG" "$log" + echo "$job" >"$CYCHE_STATUS_FILE" + echo "Updating ${arr[0]}" + + [ $res -eq 2 ] \ + || ! acid-build "${arr[0]}" "${arr[3]}" "$hash" "$selfopt" >>"$log" 2>&1 \ + && touch "$logdir/fail" - if [ $res -ne 0 ]; then - echo "Updated ${arr[0]}" + echo "maint" >"$CYCHE_STATUS_FILE" sleep "$CYCHE_JOB_TIME" - else - rm -f "$log" fi forceopt="--force" @@ -97,7 +92,7 @@ remove() { # to die. echo "cychedelic ACID kicking in ..." mkdir -p "$CYCHE_SERVICE_DIR" "$CYCHE_LOG_DIR" -truncate -s 0 "$CYCHE_STATUS_FILE" +echo "maint" >"$CYCHE_STATUS_FILE" sleep "$CYCHE_STARTUP_TIME" @@ -109,6 +104,7 @@ starttime=$(now) # monitor source changes while ! should_restart; do + truncate -s 0 "$CYCHE_STATUS_FILE" sleep "$CYCHE_POLL_TIME" update done -- cgit v1.2.3