diff --git a/charts/jellyfin/README.md b/charts/jellyfin/README.md index ebe5a24..e548b24 100644 --- a/charts/jellyfin/README.md +++ b/charts/jellyfin/README.md @@ -68,7 +68,7 @@ helm install my-jellyfin jellyfin/jellyfin -f values.yaml | jellyfin.enableDLNA | bool | `false` | Enable DLNA. Requires host network. See: https://jellyfin.org/docs/general/networking/dlna.html | | jellyfin.env | list | `[]` | Additional environment variables for the container. | | livenessProbe | object | `{"initialDelaySeconds":10,"tcpSocket":{"port":"http"}}` | Configure liveness probe for Jellyfin. | -| metrics | object | `{"command":["bash","-c","sed 's,false,true,' -i /config/config/system.xml && /jellyfin/jellyfin"],"enabled":false,"serviceMonitor":{"enabled":false,"interval":"30s","labels":{},"metricRelabelings":[],"namespace":"","path":"/metrics","port":8096,"relabelings":[],"scheme":"http","scrapeTimeout":"30s","targetLabels":[],"tlsConfig":{}}}` | Configuration for metrics collection and monitoring | +| metrics | object | `{"enabled":false,"serviceMonitor":{"enabled":false,"interval":"30s","labels":{},"metricRelabelings":[],"namespace":"","path":"/metrics","port":8096,"relabelings":[],"scheme":"http","scrapeTimeout":"30s","targetLabels":[],"tlsConfig":{}}}` | Configuration for metrics collection and monitoring | | metrics.enabled | bool | `false` | Enable or disable metrics collection - Ensure you have started and configured your Jellyfin instance first as this will fail if system.xml does not exist yet. | | metrics.serviceMonitor | object | `{"enabled":false,"interval":"30s","labels":{},"metricRelabelings":[],"namespace":"","path":"/metrics","port":8096,"relabelings":[],"scheme":"http","scrapeTimeout":"30s","targetLabels":[],"tlsConfig":{}}` | Configuration for the Prometheus ServiceMonitor | | metrics.serviceMonitor.enabled | bool | `false` | Enable or disable the creation of a ServiceMonitor resource | diff --git a/charts/jellyfin/templates/deployment.yaml b/charts/jellyfin/templates/deployment.yaml index 188540e..d458d87 100644 --- a/charts/jellyfin/templates/deployment.yaml +++ b/charts/jellyfin/templates/deployment.yaml @@ -45,13 +45,9 @@ spec: {{- toYaml .Values.securityContext | nindent 12 }} image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" imagePullPolicy: {{ .Values.image.pullPolicy }} - {{- if and .Values.image.command (not .Values.metrics.enabled) }} + {{- with .Values.jellyfin.command }} command: - {{- toYaml .Values.jellyfin.command | nindent 12 }} - {{- end }} - {{- if .Values.metrics.enabled }} - command: - {{- toYaml .Values.metrics.command | nindent 12 }} + {{- toYaml . | nindent 12 }} {{- end }} {{- with .Values.jellyfin.args }} args: @@ -61,6 +57,41 @@ spec: env: {{- toYaml . | nindent 12 }} {{- end }} + {{- if .Values.metrics.enabled }} + lifecycle: + postStart: + exec: + command: + - /bin/sh + - -c + - | + echo "Waiting for system.xml to enable metrics..." + timeout=300 # 5 minutes timeout + interval=5 # Check every 5 seconds + elapsed=0 + while [ ! -f /config/config/system.xml ]; do + if [ $elapsed -ge $timeout ]; then + echo "ERROR: Timed out waiting for /config/config/system.xml" >&2 + exit 1 + fi + sleep $interval + elapsed=$((elapsed + interval)) + done + echo "Found /config/config/system.xml, enabling metrics..." + # Check if metrics are already enabled before running sed + if ! grep -q 'true' /config/config/system.xml; then + sed 's,false,true,' -i /config/config/system.xml + if [ $? -eq 0 ]; then + echo "Metrics enabled successfully." + else + echo "ERROR: Failed to enable metrics in /config/config/system.xml" >&2 + exit 1 + fi + else + echo "Metrics already enabled." + fi + exit 0 + {{- end }} ports: - name: http containerPort: 8096 @@ -102,8 +133,16 @@ spec: {{- end }} - name: media {{- if .Values.persistence.media.enabled }} + {{- if eq .Values.persistence.media.type "pvc" }} persistentVolumeClaim: claimName: {{ if .Values.persistence.media.existingClaim }}{{ .Values.persistence.media.existingClaim }}{{- else }}{{ template "jellyfin.fullname" . }}-media{{- end }} + {{- else if eq .Values.persistence.media.type "hostPath" }} + hostPath: + path: {{ .Values.persistence.media.hostPath }} + type: Directory + {{- else }} + emptyDir: {} + {{- end }} {{- else }} emptyDir: {} {{- end }} diff --git a/charts/jellyfin/values.yaml b/charts/jellyfin/values.yaml index 382ad37..7422337 100644 --- a/charts/jellyfin/values.yaml +++ b/charts/jellyfin/values.yaml @@ -195,14 +195,8 @@ persistence: # -- Configuration for metrics collection and monitoring metrics: - # -- Enable or disable metrics collection - Ensure you have started and configured your Jellyfin instance first as this will fail if system.xml does not exist yet. + # -- Enable or disable metrics collection enabled: false - command: - - bash - - '-c' - - >- - sed 's,false,true,' -i /config/config/system.xml && - /jellyfin/jellyfin # -- Configuration for the Prometheus ServiceMonitor serviceMonitor: # -- Enable or disable the creation of a ServiceMonitor resource