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.

35 lines
1.3 KiB

  1. #!/bin/bash
  2. ## When writing relation script, remember:
  3. ## - they should be idempotents
  4. ## - they can be launched while the dockers is already up
  5. ## - they are launched from the host
  6. ## - the target of the link is launched first, and get a chance to ``relation-set``
  7. ## - both side of the scripts get to use ``relation-get``.
  8. set -e
  9. label=${SERVICE_NAME}-renew
  10. DST=$CONFIGSTORE/$TARGET_SERVICE_NAME/etc/cron/$label
  11. LOCAL_LOG=/var/log/cron/${label}_script.log
  12. schedule=$(relation-get schedule)
  13. if ! echo "$schedule" | egrep '^\s*(([0-9/,*-]+\s+){4,4}[0-9/,*-]+|@[a-z]+)\s*$' >/dev/null 2>&1; then
  14. err "Unrecognized schedule '$schedule'."
  15. exit 1
  16. fi
  17. ## Warning: using '\' in heredoc will be removed in the final cron file, which
  18. ## is totally wanted: cron does not support multilines.
  19. ## Warning: 'docker -v' will use HOST directory even if launched from
  20. ## 'cron' container.
  21. file_put "$DST" <<EOF
  22. $schedule root lock $label -D -p 10 -c "\
  23. docker run --rm \
  24. -v $BASE_CHARM_PATH/etc/letsencrypt:/etc/letsencrypt:rw \
  25. -v $BASE_CHARM_PATH/var/log/letsencrypt:/var/log/letsencrypt:rw \
  26. -v $BASE_CHARM_PATH/var/lib/tldextract:/var/lib/tldextract:rw \
  27. \"$DOCKER_BASE_IMAGE\" crt renew" 2>&1 | ts '\%F \%T \%Z' >> $LOCAL_LOG
  28. EOF
  29. chmod +x "$DST"