mirror of
https://github.com/auricom/home-cluster.git
synced 2025-09-17 18:24:14 +02:00
feat: nas music transcode healtchecks
This commit is contained in:
@@ -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
|
@@ -37,7 +37,7 @@ spec:
|
|||||||
app:
|
app:
|
||||||
image:
|
image:
|
||||||
repository: ghcr.io/auricom/freac
|
repository: ghcr.io/auricom/freac
|
||||||
tag: 1.1.7@sha256:ed89c0d4476e7291caf271acfc54636b5649076478f86b05c1ab89eeea3873ee
|
tag: 1.1.7@sha256:d70f65290ffd63e10f7a864f397203510ccdf166208bbbab405a889adceaeecd
|
||||||
command:
|
command:
|
||||||
- /bin/bash
|
- /bin/bash
|
||||||
- -c
|
- -c
|
||||||
@@ -55,6 +55,9 @@ spec:
|
|||||||
TRANSCODE_INPUT_DIR: /mnt/music/
|
TRANSCODE_INPUT_DIR: /mnt/music/
|
||||||
TRANSCODE_OUTPUT_DIR: /mnt/music_transcoded/
|
TRANSCODE_OUTPUT_DIR: /mnt/music_transcoded/
|
||||||
TRANSCODE_FREAC_BIN: /app/freaccmd
|
TRANSCODE_FREAC_BIN: /app/freaccmd
|
||||||
|
envFrom:
|
||||||
|
- secretRef:
|
||||||
|
name: homelab-nas-music-transcode-secret
|
||||||
service:
|
service:
|
||||||
app:
|
app:
|
||||||
controller: *app
|
controller: *app
|
||||||
@@ -62,7 +65,7 @@ spec:
|
|||||||
persistence:
|
persistence:
|
||||||
scripts:
|
scripts:
|
||||||
type: configMap
|
type: configMap
|
||||||
name: music-transcode-configmap
|
name: homelab-music-transcode-configmap
|
||||||
defaultMode: 0775 # trunk-ignore(yamllint/octal-values)
|
defaultMode: 0775 # trunk-ignore(yamllint/octal-values)
|
||||||
globalMounts:
|
globalMounts:
|
||||||
- path: /app/transcode.sh
|
- path: /app/transcode.sh
|
||||||
@@ -70,7 +73,7 @@ spec:
|
|||||||
readOnly: true
|
readOnly: true
|
||||||
exclude:
|
exclude:
|
||||||
type: configMap
|
type: configMap
|
||||||
name: music-transcode-configmap
|
name: homelab-music-transcode-configmap
|
||||||
defaultMode: 0644 # trunk-ignore(yamllint/octal-values)
|
defaultMode: 0644 # trunk-ignore(yamllint/octal-values)
|
||||||
globalMounts:
|
globalMounts:
|
||||||
- path: /app/transcode_exclude.cfg
|
- path: /app/transcode_exclude.cfg
|
||||||
|
@@ -4,9 +4,10 @@ apiVersion: kustomize.config.k8s.io/v1beta1
|
|||||||
kind: Kustomization
|
kind: Kustomization
|
||||||
namespace: default
|
namespace: default
|
||||||
resources:
|
resources:
|
||||||
|
- ./externalsecret.yaml
|
||||||
- ./helmrelease.yaml
|
- ./helmrelease.yaml
|
||||||
configMapGenerator:
|
configMapGenerator:
|
||||||
- name: music-transcode-configmap
|
- name: homelab-music-transcode-configmap
|
||||||
files:
|
files:
|
||||||
- ./scripts/transcode.sh
|
- ./scripts/transcode.sh
|
||||||
- ./scripts/transcode_exclude.cfg
|
- ./scripts/transcode_exclude.cfg
|
||||||
|
@@ -8,8 +8,14 @@ set -u
|
|||||||
set -o pipefail
|
set -o pipefail
|
||||||
|
|
||||||
# Set locale to UTF-8
|
# Set locale to UTF-8
|
||||||
export LANG=en_US.UTF-8
|
export LANG=C.UTF-8
|
||||||
export LC_ALL=en_US.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
|
# Create a logging function
|
||||||
log() {
|
log() {
|
||||||
@@ -31,6 +37,27 @@ cleanup() {
|
|||||||
exit $exit_code
|
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 cleanup EXIT
|
||||||
trap 'log "Script interrupted by user"; exit 1' INT TERM
|
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_FREAC_BIN="${TRANSCODE_FREAC_BIN:-/app/freaccmd}"
|
||||||
export TRANSCODE_COVER_EXTENSIONS="${TRANSCODE_COVER_EXTENSIONS:-png jpg}"
|
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_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
|
# Validate directories and files
|
||||||
for dir in "$TRANSCODE_INPUT_DIR" "$TRANSCODE_OUTPUT_DIR"; do
|
for dir in "$TRANSCODE_INPUT_DIR" "$TRANSCODE_OUTPUT_DIR"; do
|
||||||
@@ -254,7 +290,7 @@ convert_music() {
|
|||||||
if [[ $process_file == true ]]; then
|
if [[ $process_file == true ]]; then
|
||||||
transcode "$val" "$filename" "$md5_filename"
|
transcode "$val" "$filename" "$md5_filename"
|
||||||
fi
|
fi
|
||||||
done < <("$TRANSCODE_FD_BIN" --extension "$ext" $TRANSCODE_FD_FILTERS --type f)
|
done < <(fd_safe --extension "$ext" $TRANSCODE_FD_FILTERS --type f)
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -340,3 +376,12 @@ if [[ $MODE_DELETE == false ]]; then
|
|||||||
else
|
else
|
||||||
remove_absent_from_source
|
remove_absent_from_source
|
||||||
fi
|
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
|
||||||
|
Reference in New Issue
Block a user