From 6dc7f53df18927e5587cd1f12cbbc4edbde2bc13 Mon Sep 17 00:00:00 2001 From: Maarten de Waard <maarten@greenhost.nl> Date: Mon, 24 Oct 2022 16:19:47 +0200 Subject: [PATCH] improve setup apps script --- README.md | 10 +++---- templates/nextcloud-onlyoffice-config.yaml | 35 ++++++++++++++-------- 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index fb7147cb..783af9b2 100644 --- a/README.md +++ b/README.md @@ -83,11 +83,11 @@ This chart adds a "postStart" command to the Nextcloud pod, that installs apps integration with ONLYOFFICE as well as the Stackspin OIDC provider. Kubernetes postStart commands do not log to the pod log. Instead, the script -creates its own log in `/var/www/html/data/postStart.log`. This means that even -if you can't `exec` into the pod (because something is failing), you can see the -logs inside the `data` folder in the PVC. Often, if the `postStart` command -fails, you can also see the problem by running `kubectl describe pod <nextcloud -pod>`. +creates its own log in `/var/www/html/tmp/postStart<date>.log`. This means that +even if you can't `exec` into the pod (because something is failing), you can +see the logs inside the `data` folder in the PVC. Often, if the `postStart` +command fails, you can also see the problem by running `kubectl describe pod +<nextcloud pod>`. ## Apps diff --git a/templates/nextcloud-onlyoffice-config.yaml b/templates/nextcloud-onlyoffice-config.yaml index 3bd9f492..addc5e9e 100644 --- a/templates/nextcloud-onlyoffice-config.yaml +++ b/templates/nextcloud-onlyoffice-config.yaml @@ -26,7 +26,9 @@ data: # * Persists and loads the config.json config file # * Updates database indices, columns, keys, etc needed after NC upgrade # * Writes a log to /var/www/html/data/postStart.log - exec 1>/var/www/html/data/postStart.log + exec > /var/www/tmp/postStart-$(date +"%s").log + exec 2> /var/www/tmp/postStart-$(date +"%s")_error.log + # Copied from the NC docker entrypoint to run OCC commands run_as() { @@ -39,32 +41,41 @@ data: echo "STARTING SETUP-APPS.SH" - set -ev - # Debug: place the json file in a persistent location for reuse cp /var/local/config.json /var/www/html/ occ="/var/www/html/occ" + count=0 + limit=10 # There's a nextcloud setup process. First, wait for `occ` to exist - until [ -e $occ ]; do - echo "$occ doesn't exist yet..." - sleep 1 + until [ -f "$occ" ] || [ "$count" -gt "$limit" ] + do + count=$((count+1)) + wait=$((count*10)) + echo "$occ doesn't exist yet, waiting $wait seconds" + sleep $wait done echo "$occ now exists!!!" - lock=/var/www/html/nextcloud-init-sync.lock - # If Nextcloud is still installing files at this point, a "lock file" will - # exist, wait until that's gone too before running our own setup: - until [ ! -f "$lock" ] + count=0 + + # As soon as the $occ command exist, we know that we can run occ, but + # Nextcloud might still be initializing, a "lock file" will exist, wait + # until that's gone before running our own setup: + until run_as "php occ status --output json" | grep '"installed":true' || [ "$count" -gt "$limit" ] do - echo "Nextcloud lock file $lock still exists..." - sleep 1 + count=$((count+1)) + wait=$((count*10)) + echo "Nextcloud is not installed yet. Waiting $wait seconds..." + sleep $wait done echo "Nextcloud lock file $lock is gone, we can do our thing!" + set -e + # Enable app store so we can run `install` and `enable` commands run_as "php $occ config:system:set appstoreenabled --type boolean --value true" -- GitLab