From 416b590f88aea107a269f6a014e2519218852c78 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Mon, 23 Dec 2019 23:43:43 +0100 Subject: nextcloud: upgrade all instances and add occ script --- roles/nextcloud/templates/nextcloud-occ.j2 | 20 ++++++++++++ roles/nextcloud/templates/nextcloud-upgrade.j2 | 42 ++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100755 roles/nextcloud/templates/nextcloud-occ.j2 create mode 100755 roles/nextcloud/templates/nextcloud-upgrade.j2 (limited to 'roles/nextcloud/templates') diff --git a/roles/nextcloud/templates/nextcloud-occ.j2 b/roles/nextcloud/templates/nextcloud-occ.j2 new file mode 100755 index 00000000..91977ccd --- /dev/null +++ b/roles/nextcloud/templates/nextcloud-occ.j2 @@ -0,0 +1,20 @@ +#!/bin/bash + +INST_NAME="$1" +shift + +if [ -z "$INST_NAME" ]; then + echo "Usage: $0 [ ... ]" + exit 1 +fi + +set -eu +export CONTAINER_RUNTIME_ENDPOINT="unix:///run/containerd/containerd.sock" + +pod_id=$(crictl pods -q --state ready --name "$INST_NAME-{{ ansible_nodename }}") +if [ -z "$pod_id" ]; then echo "Pod not found"; exit 1; fi + +container_id=$(crictl ps -q --name '^nextcloud$' -p "$pod_id") +if [ -z "$container_id" ]; then echo "Container not found"; exit 1; fi + +exec crictl exec -it "$container_id" php /var/www/html/occ $@ diff --git a/roles/nextcloud/templates/nextcloud-upgrade.j2 b/roles/nextcloud/templates/nextcloud-upgrade.j2 new file mode 100755 index 00000000..aac5001f --- /dev/null +++ b/roles/nextcloud/templates/nextcloud-upgrade.j2 @@ -0,0 +1,42 @@ +#!/bin/bash + +INST_NAME="$1" +VERSION="$2" +if [ -z "$INST_NAME" ] || [ -z "$VERSION" ]; then + echo "Usage: $0 " + exit 1 +fi + +set -eu + +K8S_MANIFEST_D="/etc/kubernetes/manifests/" +K8S_MANIFEST_FILE="$K8S_MANIFEST_D/nextcloud-$INST_NAME.yml" +if [ ! -e "$K8S_MANIFEST_FILE" ]; then + echo "could not find manifest file: $K8S_MANIFEST_FILE" + exit 2 +fi + +TMP_D=$(mktemp -d -t nextcloud-upgrade.XXXXXXX) +function cleanup { + rm -rf "$TMP_D" +} +trap cleanup EXIT + +echo "*** Pre-Pulling the image" +echo "" +ctr -n k8s.io image pull "docker.io/library/nextcloud:$VERSION" +echo "" + +echo "*** Patching manifest file" +echo "" +sed "s#image: \"nextcloud:.*\"#image: \"nextcloud:$VERSION\"#" "$K8S_MANIFEST_FILE" > "$TMP_D/upgraded.yml" +set +e +diff -u "$K8S_MANIFEST_FILE" "$TMP_D/upgraded.yml" +if [ $? -eq 0 ]; then + echo "patching file failed?" + exit 2 +fi +cat "$TMP_D/upgraded.yml" > "$K8S_MANIFEST_FILE" +echo "" + +exit 0 -- cgit v1.2.3