diff --git a/nextcloud/hooks/log_rotate-relation-joined b/nextcloud/hooks/log_rotate-relation-joined new file mode 100755 index 0000000..3505480 --- /dev/null +++ b/nextcloud/hooks/log_rotate-relation-joined @@ -0,0 +1,76 @@ +#!/bin/bash + +## Should be executable N time in a row with same result. + +. lib/common + +set -e + +nextcloud_uid=$(docker_get_uid "$SERVICE_NAME" www-data) || { + echo "ERROR: failed to get uid for www-data" + exit 1 +} + +LOGS=/var/log/nextcloud +mkdir -p "$SERVICE_DATASTORE/$LOGS" +chown -R "$nextcloud_uid" "$SERVICE_DATASTORE/$LOGS" + +## check old location for log files +OLDLOG="$SERVICE_DATASTORE/var/lib/nextcloud/data/nextcloud.log" +if [ -s "$OLDLOG" ]; then + ## check we don't have a log file already + if [ -s "$SERVICE_DATASTORE/$LOGS/nextcloud.log" ]; then + err "Old log file found at $OLDLOG" \ + "but new log file already exists at $SERVICE_DATASTORE/$LOGS/nextcloud.log" + exit 1 + fi + info "Migrating old log file" \ + "from $OLDLOG" \ + "to $SERVICE_DATASTORE/$LOGS/nextcloud.log" + mv -v "$OLDLOG" "$SERVICE_DATASTORE/$LOGS/nextcloud.log" || { + err "Failed to move old log file" + exit 1 + } +fi + + +rotated_count=$(relation-get rotated-count 2>/dev/null) || true +rotated_count=${rotated_count:-52} + + +## No postrotate script as nextcloud is a php script that gets +## reloaded for each client requests + +## XXXvlab: a lot of this intelligence should be moved away into ``logrotate`` charm +DST="$CONFIGSTORE/$TARGET_SERVICE_NAME/etc/logrotate.d/$SERVICE_NAME" +file_put "$DST" < + log-rotate: + #constraint: required | recommended | optional + #auto: pair | summon | none ## default: pair + constraint: recommended + auto: pair + solves: + unmanaged-logs: "in docker logs" + #default-options: backup: constraint: recommended auto: pair