feat: nas music transcode healtchecks

This commit is contained in:
auricom
2025-02-22 03:45:29 +01:00
parent eac0739447
commit e17247f143
4 changed files with 74 additions and 8 deletions

View File

@@ -0,0 +1,17 @@
# yaml-language-server: $schema=https://kubernetes-schemas.devbu.io/external-secrets.io/externalsecret_v1beta1.json
apiVersion: external-secrets.io/v1beta1
kind: ExternalSecret
metadata:
name: homelab-nas-music-transcode
namespace: default
spec:
secretStoreRef:
kind: ClusterSecretStore
name: onepassword-connect
target:
name: homelab-nas-music-transcode-secret
dataFrom:
- extract:
# HEALTHCHECKS_ID
key: homelab-nas

View File

@@ -37,7 +37,7 @@ spec:
app:
image:
repository: ghcr.io/auricom/freac
tag: 1.1.7@sha256:ed89c0d4476e7291caf271acfc54636b5649076478f86b05c1ab89eeea3873ee
tag: 1.1.7@sha256:d70f65290ffd63e10f7a864f397203510ccdf166208bbbab405a889adceaeecd
command:
- /bin/bash
- -c
@@ -55,6 +55,9 @@ spec:
TRANSCODE_INPUT_DIR: /mnt/music/
TRANSCODE_OUTPUT_DIR: /mnt/music_transcoded/
TRANSCODE_FREAC_BIN: /app/freaccmd
envFrom:
- secretRef:
name: homelab-nas-music-transcode-secret
service:
app:
controller: *app
@@ -62,7 +65,7 @@ spec:
persistence:
scripts:
type: configMap
name: music-transcode-configmap
name: homelab-music-transcode-configmap
defaultMode: 0775 # trunk-ignore(yamllint/octal-values)
globalMounts:
- path: /app/transcode.sh
@@ -70,7 +73,7 @@ spec:
readOnly: true
exclude:
type: configMap
name: music-transcode-configmap
name: homelab-music-transcode-configmap
defaultMode: 0644 # trunk-ignore(yamllint/octal-values)
globalMounts:
- path: /app/transcode_exclude.cfg

View File

@@ -4,9 +4,10 @@ apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: default
resources:
- ./externalsecret.yaml
- ./helmrelease.yaml
configMapGenerator:
- name: music-transcode-configmap
- name: homelab-music-transcode-configmap
files:
- ./scripts/transcode.sh
- ./scripts/transcode_exclude.cfg

View File

@@ -8,8 +8,14 @@ set -u
set -o pipefail
# Set locale to UTF-8
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
export LANG=C.UTF-8
export LC_ALL=C.UTF-8
# # Send start ping to healthchecks
# if [[ -n "${HEALTHCHECKS_ID:-}" ]]; then
# curl --silent --max-time 10 --retry 5 "https://hc-ping.com/${HEALTHCHECKS_ID}/start"
# fi
# Create a logging function
log() {
@@ -31,6 +37,27 @@ cleanup() {
exit $exit_code
}
manage_execution_time() {
local timestamp_file="$TRANSCODE_DB/last_execution"
if [[ "$1" == "read" ]]; then
if [[ -f "$timestamp_file" ]]; then
cat "$timestamp_file"
else
echo "@0" # Return epoch if no previous execution
fi
elif [[ "$1" == "write" ]]; then
date +%s | sed 's/^/@/' > "$timestamp_file" # Store as @timestamp format
fi
}
fd_safe() {
if ! "$TRANSCODE_FD_BIN" "$@"; then
log "ERROR: fd command failed"
exit 1
fi
}
trap cleanup EXIT
trap 'log "Script interrupted by user"; exit 1' INT TERM
@@ -49,7 +76,16 @@ export TRANSCODE_DB="${TRANSCODE_DB:-${TRANSCODE_OUTPUT_DIR}.transcode}"
export TRANSCODE_FREAC_BIN="${TRANSCODE_FREAC_BIN:-/app/freaccmd}"
export TRANSCODE_COVER_EXTENSIONS="${TRANSCODE_COVER_EXTENSIONS:-png jpg}"
export TRANSCODE_MUSIC_EXTENSIONS="${TRANSCODE_MUSIC_EXTENSIONS:-flac opus mp3 ogg wma m4a wav}"
export TRANSCODE_FD_FILTERS="${TRANSCODE_FD_FILTERS:---changed-within 1week}"
if [[ -n "${TRANSCODE_FD_FILTERS+x}" ]]; then
: # Keep existing value if explicitly set
else
if [[ "$*" == *"-f"* ]]; then
export TRANSCODE_FD_FILTERS=""
else
last_exec=$(manage_execution_time read)
export TRANSCODE_FD_FILTERS="--changed-after $last_exec"
fi
fi
# Validate directories and files
for dir in "$TRANSCODE_INPUT_DIR" "$TRANSCODE_OUTPUT_DIR"; do
@@ -254,7 +290,7 @@ convert_music() {
if [[ $process_file == true ]]; then
transcode "$val" "$filename" "$md5_filename"
fi
done < <("$TRANSCODE_FD_BIN" --extension "$ext" $TRANSCODE_FD_FILTERS --type f)
done < <(fd_safe --extension "$ext" $TRANSCODE_FD_FILTERS --type f)
done
}
@@ -340,3 +376,12 @@ if [[ $MODE_DELETE == false ]]; then
else
remove_absent_from_source
fi
if [[ $MODE_DRY_RUN == false ]]; then
manage_execution_time write
fi
# # Send completion ping to healthchecks
# if [[ -n "${HEALTHCHECKS_ID:-}" ]]; then
# curl --silent --max-time 10 --retry 5 "https://hc-ping.com/${HEALTHCHECKS_ID}"
# fi