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.

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