fork 0k-charms
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.

80 lines
2.4 KiB

  1. #!/bin/bash
  2. ## Should be executable N time in a row with same result.
  3. exit 0
  4. . lib/common
  5. set -e
  6. LOGS=/var/log/apache2
  7. ## XXXvlab: hum it seems apache logging is run as root, so well...
  8. # logs_creds=$(cached_cmd_on_base_image apache "stat -c '%u %g' '$LOGS'") || {
  9. # debug "Failed to query for www-data gid in ${DARKYELLOW}apache${NORMAL} base image."
  10. # return 1
  11. # }
  12. rotated_count=$(relation-get rotated-count 2>/dev/null) || true
  13. rotated_count=${rotated_count:-52}
  14. ## XXXvlab: a lot of this intelligence should be moved away into
  15. ## ``logrotate`` charm
  16. ##
  17. ## Issues:
  18. ## - relation-joined will execute first log-rotate charm part of the
  19. ## relation, which is not what we want here, as we need to send
  20. ## default value for the creation of the config file on the server
  21. ## part.
  22. ## - we need to send the directory it seems, otherwise, docker will
  23. ## create directory when the log file is missing, and I'm not sure
  24. ## how processes will react when their file is moved out of their
  25. ## file-system scope when rotated (but I think there will be no
  26. ## issue here).
  27. ## The problem here is that we can't cleanly put all file in the
  28. ## same directory (and there are collision possible anyway).
  29. ## This means that if we want more than one target, we need
  30. ## sub-directories.
  31. ## - For this issue, we only fear the 'docker' run and mounting
  32. ## moment, and we are sure to run before, so we can make sure to
  33. ## ``touch`` the files.
  34. ## - can we move file that was been bound in a docker ? Well yes,
  35. ## but it won't change place in the docker:( ... I guess you need
  36. ## to reload the docker and the binding to work.
  37. ##
  38. DST="$CONFIGSTORE/$TARGET_SERVICE_NAME/etc/logrotate.d/$SERVICE_NAME"
  39. file_put "$DST" <<EOF
  40. /var/log/docker/$SERVICE_NAME/*error.log
  41. /var/log/docker/$SERVICE_NAME/*access.log
  42. {
  43. weekly
  44. missingok
  45. dateext
  46. dateyesterday
  47. dateformat _%Y-%m-%d
  48. extension .log
  49. rotate $rotated_count
  50. compress
  51. delaycompress
  52. notifempty
  53. create 640 root root
  54. sharedscripts
  55. postrotate
  56. docker-send-signal \$${MASTER_BASE_CHARM_NAME^^}_NAME SIGUSR1;
  57. endscript
  58. }
  59. EOF
  60. config-add "\
  61. $MASTER_TARGET_CHARM_NAME:
  62. volumes:
  63. - $DST:/etc/logrotate.d/docker-${SERVICE_NAME}:ro
  64. - $SERVICE_DATASTORE$LOGS:/var/log/docker/$SERVICE_NAME:rw
  65. $MASTER_BASE_CHARM_NAME:
  66. volumes:
  67. - $SERVICE_DATASTORE$LOGS:$LOGS:rw
  68. "