From f14046610ea74d411eee1288169235548b27835c Mon Sep 17 00:00:00 2001 From: Valentin Lab Date: Thu, 15 Nov 2018 16:37:35 +0100 Subject: [PATCH] new: [letsencrypt] support for scheduling relation. --- .../hooks/schedule_command-relation-joined | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100755 letsencrypt/hooks/schedule_command-relation-joined diff --git a/letsencrypt/hooks/schedule_command-relation-joined b/letsencrypt/hooks/schedule_command-relation-joined new file mode 100755 index 0000000..e2fb7b1 --- /dev/null +++ b/letsencrypt/hooks/schedule_command-relation-joined @@ -0,0 +1,35 @@ +#!/bin/bash + +## When writing relation script, remember: +## - they should be idempotents +## - they can be launched while the dockers is already up +## - they are launched from the host +## - the target of the link is launched first, and get a chance to ``relation-set`` +## - both side of the scripts get to use ``relation-get``. + +set -e + +label=${SERVICE_NAME}-renew +DST=$CONFIGSTORE/$TARGET_SERVICE_NAME/etc/cron/$label +LOCAL_LOG=/var/log/cron/${label}_script.log +schedule=$(relation-get schedule) + +if ! echo "$schedule" | egrep '^\s*(([0-9/,*-]+\s+){4,4}[0-9/,*-]+|@[a-z]+)\s*$' >/dev/null 2>&1; then + err "Unrecognized schedule '$schedule'." + exit 1 +fi + +## Warning: using '\' in heredoc will be removed in the final cron file, which +## is totally wanted: cron does not support multilines. + +## Warning: 'docker -v' will use HOST directory even if launched from +## 'cron' container. +file_put "$DST" <&1 | ts '\%F \%T \%Z' >> $LOCAL_LOG +EOF +chmod +x "$DST"