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.

91 lines
2.6 KiB

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