Skip to content
Snippets Groups Projects
Commit a6b7eac5 authored by Arie Peterson's avatar Arie Peterson
Browse files

Trap and report errors in postStart script

parent db77be8d
No related branches found
No related tags found
1 merge request!495Resolve "Consider allowing nextcloud to run when postStart fails"
Pipeline #37702 passed with stages
in 8 minutes and 37 seconds
...@@ -4,7 +4,7 @@ description: | ...@@ -4,7 +4,7 @@ description: |
A helm chart for installing NextCloud and setting up ONLYOFFICE integration A helm chart for installing NextCloud and setting up ONLYOFFICE integration
name: nextcloud-onlyoffice name: nextcloud-onlyoffice
appVersion: NC-25.0.3-OO-7.2.2.56 appVersion: NC-25.0.3-OO-7.2.2.56
version: 0.15.10 version: 0.15.11-poststart-1
icon: https://cdn.rawgit.com/docker-library/docs/defa5ffc7123177acd60ddef6e16bddf694cc35f/nextcloud/logo.svg icon: https://cdn.rawgit.com/docker-library/docs/defa5ffc7123177acd60ddef6e16bddf694cc35f/nextcloud/logo.svg
dependencies: dependencies:
# https://artifacthub.io/packages/helm/nextcloud/nextcloud # https://artifacthub.io/packages/helm/nextcloud/nextcloud
......
{{- if (.Capabilities.APIVersions.Has "monitoring.coreos.com/v1") }}
apiVersion: monitoring.coreos.com/v1
kind: PodMonitor
metadata:
name: nextcloud
labels:
app.kubernetes.io/managed-by: {{ .Release.Service | quote }}
app.kubernetes.io/name: nextcloud
app.kubernetes.io/instance: {{ .Release.Name | quote }}
helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
spec:
namespaceSelector:
matchNames:
- stackspin-apps
podMetricsEndpoints:
- port: metrics
jobLabel: app.kubernetes.io/name
selector:
matchLabels:
app.kubernetes.io/component: app
app.kubernetes.io/instance: {{ .Release.Name | quote }}
app.kubernetes.io/name: nextcloud
---
apiVersion: monitoring.coreos.com/v1
kind: PrometheusRule
metadata:
labels:
app.kubernetes.io/managed-by: {{ .Release.Service | quote }}
app.kubernetes.io/name: nextcloud
app.kubernetes.io/instance: {{ .Release.Name | quote }}
helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
name: nextcloud
spec:
groups:
- name: nextcloud
rules:
- alert: NextcloudSetupError
annotations:
message: The setup-apps.sh script of Nextcloud has encountered errors. See the postStart logs for more information.
expr: nextcloud_poststart_errors > 0
labels:
severity: warning
{{- end }}
...@@ -30,6 +30,40 @@ data: ...@@ -30,6 +30,40 @@ data:
exec > /var/www/tmp/postStart-$(date +"%s").log exec > /var/www/tmp/postStart-$(date +"%s").log
exec 2> /var/www/tmp/postStart-$(date +"%s")_error.log exec 2> /var/www/tmp/postStart-$(date +"%s")_error.log
# Write a simple status (errors or no errors) to a file, to be served to
# prometheus by a sidecar container.
report_metrics() {
errors=$1
outfile=/srv/metrics/status
truncate -s 0 $outfile
echo '# HELP nextcloud_poststart_errors Whether the nextcloud postStart script has encountered errors.' >> $outfile
echo '# TYPE nextcloud_poststart_errors gauge' >> $outfile
echo "nextcloud_poststart_errors $errors" >> $outfile
}
# We just started, so no errors yet!
report_metrics "0"
exception_handler() {
signal=$1
exitCode=$2
lineNumber=$3
echo "setup-apps.sh received $signal (code $exitCode) on line $lineNumber"
echo "Exiting with status 0 to allow nextcloud to start."
# Report to prometheus that we have an error.
report_metrics "1"
# Remove the handler for `EXIT` so we don't run that as well. If we're
# currently handling `EXIT` already then this is not necessary because
# bash treats an `exit` specially if it happens in the `EXIT` handler.
# If we're handling another signal though, then we want to prevent that
# the call to `exit` also triggers the `EXIT` handler.
trap '' EXIT
exit 0
}
trap 'exception_handler ERR $? $LINENO' ERR
trap 'exception_handler EXIT $? $LINENO' EXIT
trap 'exception_handler SIGINT $? $LINENO' SIGINT
trap 'exception_handler SIGTERM $? $LINENO' SIGTERM
# Copied from the NC docker entrypoint to run OCC commands # Copied from the NC docker entrypoint to run OCC commands
run_as() { run_as() {
......
...@@ -37,10 +37,23 @@ nextcloud: ...@@ -37,10 +37,23 @@ nextcloud:
- name: nextcloud-onlyoffice-config - name: nextcloud-onlyoffice-config
configMap: configMap:
name: nextcloud-onlyoffice-config-and-scripts name: nextcloud-onlyoffice-config-and-scripts
- name: poststart-metrics
emptyDir:
medium: Memory
extraVolumeMounts: extraVolumeMounts:
- name: nextcloud-onlyoffice-config - name: nextcloud-onlyoffice-config
mountPath: /var/local mountPath: /var/local
- name: poststart-metrics
mountPath: "/srv/metrics"
extraSidecarContainers:
- name: poststart-metrics
image: "weibeld/file-exporter:0.0.2"
ports:
- name: metrics
containerPort: 9872
volumeMounts:
- name: poststart-metrics
mountPath: "/srv/metrics"
lifecycle: lifecycle:
postStartCommand: postStartCommand:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment