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.

34 lines
1.1 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. COMPOSE_LAUNCHER_OPTS=$COMPOSE_LAUNCHER_OPTS
  23. $schedule root lock $label -D -p 10 -c "\
  24. compose crt $SERVICE_NAME renew" 2>&1 | ts '\%F \%T \%Z' >> $LOCAL_LOG
  25. EOF
  26. chmod +x "$DST"