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.

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