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.

32 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=launch-$SERVICE_NAME
  10. DST=$CONFIGSTORE/$TARGET_SERVICE_NAME/etc/cron/$label
  11. schedule=$(relation-get schedule) || true
  12. ## It should really stay at midnight as most logs are dated
  13. schedule=${schedule:-0 0 * * *}
  14. if ! echo "$schedule" | egrep '^\s*(([0-9/,*-]+\s+){4,4}[0-9/,*-]+|@[a-z]+)\s*$' >/dev/null 2>&1; then
  15. err "Unrecognized schedule '$schedule'."
  16. exit 1
  17. fi
  18. ## Warning: using '\' in heredoc will be removed in the final cron file, which
  19. ## is totally wanted: cron does not support multilines.
  20. ## Warning: 'docker -v' will use HOST directory even if launched from
  21. ## 'cron' container.
  22. file_put "$DST" <<EOF
  23. $schedule root lock $label -D -p 10 -c "\
  24. dc run --rm $SERVICE_NAME" 2>&1 | ts '\%F \%T \%Z' >> /var/log/cron/${label}_script.log
  25. EOF
  26. chmod +x "$DST"