You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

76 lines
1.9 KiB

  1. #!/bin/bash
  2. ## Should be executable N time in a row with same result.
  3. . lib/common
  4. set -e
  5. nextcloud_uid=$(docker_get_uid "$SERVICE_NAME" www-data) || {
  6. echo "ERROR: failed to get uid for www-data"
  7. exit 1
  8. }
  9. LOGS=/var/log/nextcloud
  10. mkdir -p "$SERVICE_DATASTORE/$LOGS"
  11. chown -R "$nextcloud_uid" "$SERVICE_DATASTORE/$LOGS"
  12. ## check old location for log files
  13. OLDLOG="$SERVICE_DATASTORE/var/lib/nextcloud/data/nextcloud.log"
  14. if [ -s "$OLDLOG" ]; then
  15. ## check we don't have a log file already
  16. if [ -s "$SERVICE_DATASTORE/$LOGS/nextcloud.log" ]; then
  17. err "Old log file found at $OLDLOG" \
  18. "but new log file already exists at $SERVICE_DATASTORE/$LOGS/nextcloud.log"
  19. exit 1
  20. fi
  21. info "Migrating old log file" \
  22. "from $OLDLOG" \
  23. "to $SERVICE_DATASTORE/$LOGS/nextcloud.log"
  24. mv -v "$OLDLOG" "$SERVICE_DATASTORE/$LOGS/nextcloud.log" || {
  25. err "Failed to move old log file"
  26. exit 1
  27. }
  28. fi
  29. rotated_count=$(relation-get rotated-count 2>/dev/null) || true
  30. rotated_count=${rotated_count:-52}
  31. ## No postrotate script as nextcloud is a php script that gets
  32. ## reloaded for each client requests
  33. ## XXXvlab: a lot of this intelligence should be moved away into ``logrotate`` charm
  34. DST="$CONFIGSTORE/$TARGET_SERVICE_NAME/etc/logrotate.d/$SERVICE_NAME"
  35. file_put "$DST" <<EOF
  36. /var/log/docker/$SERVICE_NAME/nextcloud.log
  37. {
  38. weekly
  39. missingok
  40. dateext
  41. dateyesterday
  42. dateformat _%Y-%m-%d
  43. extension .log
  44. rotate $rotated_count
  45. compress
  46. delaycompress
  47. notifempty
  48. create 640
  49. sharedscripts
  50. }
  51. EOF
  52. nextcloud:config:simple:add logfile "$LOGS/nextcloud.log"
  53. config-add "\
  54. services:
  55. $MASTER_TARGET_SERVICE_NAME:
  56. volumes:
  57. - $DST:/etc/logrotate.d/docker-${SERVICE_NAME}:ro
  58. - $SERVICE_DATASTORE$LOGS:/var/log/docker/$SERVICE_NAME:rw
  59. $MASTER_BASE_SERVICE_NAME:
  60. volumes:
  61. - $SERVICE_DATASTORE$LOGS:$LOGS:rw
  62. "