From 9bbdd7c9a21d13603c32cda39df00a86d7d0140d Mon Sep 17 00:00:00 2001 From: Valentin Lab Date: Thu, 4 Feb 2021 12:00:27 +0100 Subject: [PATCH] new: [gogocarto,cron] adding scheduled maintenance Signed-off-by: Valentin Lab --- cron/metadata.yml | 4 +- gogocarto/hooks/publish_dir-relation-joined | 10 ++--- .../hooks/schedule_commands-relation-joined | 44 +++++++++++++++++++ gogocarto/lib/common | 6 +-- gogocarto/metadata.yml | 5 +++ 5 files changed, 60 insertions(+), 9 deletions(-) create mode 100755 gogocarto/hooks/schedule_commands-relation-joined diff --git a/cron/metadata.yml b/cron/metadata.yml index dc71193..131149a 100644 --- a/cron/metadata.yml +++ b/cron/metadata.yml @@ -11,7 +11,9 @@ data-resources: host-resources: - /var/run/docker.sock provides: - schedule-command: + schedule-command: ## for one command + tech-dep: False + schedule-commands: ## for several commands tech-dep: False uses: ## optional diff --git a/gogocarto/hooks/publish_dir-relation-joined b/gogocarto/hooks/publish_dir-relation-joined index c17873e..1e8aa92 100755 --- a/gogocarto/hooks/publish_dir-relation-joined +++ b/gogocarto/hooks/publish_dir-relation-joined @@ -60,10 +60,10 @@ config-add " services: $MASTER_TARGET_SERVICE_NAME: volumes: - - $SERVICE_CONFIGSTORE/opt/apps/gogocarto:/opt/apps/gogocarto:rw - - $SERVICE_DATASTORE/var/cache/gogocarto:/opt/apps/gogocarto/var/cache:rw - - $SERVICE_DATASTORE/var/lib/gogocarto/sessions:/opt/apps/gogocarto/var/sessions:rw - - $SERVICE_DATASTORE/var/log/gogocarto:/opt/apps/gogocarto/var/log:rw + - $GOGOCARTO_CODE:$GOGOCARTO_DIR:rw + - $SERVICE_DATASTORE/var/cache/gogocarto:$GOGOCARTO_DIR/var/cache:rw + - $SERVICE_DATASTORE/var/lib/gogocarto/sessions:$GOGOCARTO_DIR/var/sessions:rw + - $SERVICE_DATASTORE/var/log/gogocarto:$GOGOCARTO_DIR/var/log:rw ## Required to give PHP access to this dir - - $upload_dir:/opt/apps/gogocarto/web/uploads:rw + - $upload_dir:$GOGOCARTO_DIR/web/uploads:rw " diff --git a/gogocarto/hooks/schedule_commands-relation-joined b/gogocarto/hooks/schedule_commands-relation-joined new file mode 100755 index 0000000..3dad3c9 --- /dev/null +++ b/gogocarto/hooks/schedule_commands-relation-joined @@ -0,0 +1,44 @@ +#!/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``. + +. lib/common + +set -e + +## XXXvlab: should use container name here so that it could support +## multiple postgres +label=${SERVICE_NAME} +DST=$CONFIGSTORE/$TARGET_SERVICE_NAME/etc/cron/$label + +## XXXvlab: Should we do a 'docker exec' instead ? +bin_console="dc run -u www-data --rm --entrypoint \\\"$GOGOCARTO_DIR/bin/console\\\" $MASTER_BASE_SERVICE_NAME" + +## Warning: 'docker -v' will use HOST directory even if launched from +## 'cron' container. +file_put "$DST" <&1 | ts '\%F \%T \%Z' >> /var/log/cron/${SERVICE_NAME}-checkvote_script.log + +@daily root lock ${label}-checkExternalSourceToUpdate -D -p 10 -c "\ + $bin_console app:elements:checkExternalSourceToUpdate" 2>&1 | ts '\%F \%T \%Z' >> /var/log/cron/${SERVICE_NAME}-checkExternalSourceToUpdate_script.log + +@daily root lock ${label}-notify-moderation -D -p 10 -c "\ + $bin_console app:notify-moderation" 2>&1 | ts '\%F \%T \%Z' >> /var/log/cron/${SERVICE_NAME}-notify-moderation_script.log + + +@hourly root lock ${label}-sendNewsletter -D -p 10 -c "\ + $bin_console app:users:sendNewsletter" 2>&1 | ts '\%F \%T \%Z' >> /var/log/cron/${SERVICE_NAME}-sendNewsletter_script.log + + +*/5 * * * * root lock ${label}-webhooks-post -D -p 10 -c "\ + $bin_console --env=prod app:webhooks:post" 2>&1 | ts '\%F \%T \%Z' >> /var/log/cron/${SERVICE_NAME}-webhooks-post_script.log + + +EOF +chmod +x "$DST" diff --git a/gogocarto/lib/common b/gogocarto/lib/common index 12cd27a..b89a00e 100644 --- a/gogocarto/lib/common +++ b/gogocarto/lib/common @@ -1,7 +1,7 @@ # -*- mode: shell-script -*- - -GOGOCARTO_CODE="$SERVICE_CONFIGSTORE/opt/apps/gogocarto" +GOGOCARTO_DIR="/opt/apps/gogocarto" +GOGOCARTO_CODE="$SERVICE_CONFIGSTORE$GOGOCARTO_DIR" GOGOCARTO_RELEASE=3.1.3-56-g6b8ba361 GOGOCARTO_URL=https://docker.0k.io/downloads/gogocarto-"${GOGOCARTO_RELEASE}".tar.bz2 @@ -51,7 +51,7 @@ gogocarto:config() { cat < "${GOGOCARTO_CODE}"/.env ###> symfony/framework-bundle ### -APP_ENV=$APP_ENV +APP_ENV=${APP_ENV} APP_SECRET=82ec369b81caab5446ddfc3b5edb4d00 CSRF_PROTECTION=$( [ "$APP_ENV" == "prod" ] && diff --git a/gogocarto/metadata.yml b/gogocarto/metadata.yml index 47486f3..05b609b 100644 --- a/gogocarto/metadata.yml +++ b/gogocarto/metadata.yml @@ -26,3 +26,8 @@ uses: auto: summon solves: database: "main storage" + schedule-commands: + constraint: recommended + auto: pair + solves: + maintenance: "Production scheduled tasks"