Browse Source

new: [gogocarto,cron] adding scheduled maintenance

Signed-off-by: Valentin Lab <valentin.lab@kalysto.org>
pull/1/head
Valentin Lab 4 years ago
parent
commit
9bbdd7c9a2
  1. 4
      cron/metadata.yml
  2. 10
      gogocarto/hooks/publish_dir-relation-joined
  3. 44
      gogocarto/hooks/schedule_commands-relation-joined
  4. 6
      gogocarto/lib/common
  5. 5
      gogocarto/metadata.yml

4
cron/metadata.yml

@ -11,7 +11,9 @@ data-resources:
host-resources: host-resources:
- /var/run/docker.sock - /var/run/docker.sock
provides: provides:
schedule-command:
schedule-command: ## for one command
tech-dep: False
schedule-commands: ## for several commands
tech-dep: False tech-dep: False
uses: ## optional uses: ## optional

10
gogocarto/hooks/publish_dir-relation-joined

@ -60,10 +60,10 @@ config-add "
services: services:
$MASTER_TARGET_SERVICE_NAME: $MASTER_TARGET_SERVICE_NAME:
volumes: 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 ## Required to give PHP access to this dir
- $upload_dir:/opt/apps/gogocarto/web/uploads:rw
- $upload_dir:$GOGOCARTO_DIR/web/uploads:rw
" "

44
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" <<EOF
@daily root lock ${label}-checkvote -D -p 10 -c "\
$bin_console app:elements:checkvote" 2>&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"

6
gogocarto/lib/common

@ -1,7 +1,7 @@
# -*- mode: shell-script -*- # -*- 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_RELEASE=3.1.3-56-g6b8ba361
GOGOCARTO_URL=https://docker.0k.io/downloads/gogocarto-"${GOGOCARTO_RELEASE}".tar.bz2 GOGOCARTO_URL=https://docker.0k.io/downloads/gogocarto-"${GOGOCARTO_RELEASE}".tar.bz2
@ -51,7 +51,7 @@ gogocarto:config() {
cat <<EOF > "${GOGOCARTO_CODE}"/.env cat <<EOF > "${GOGOCARTO_CODE}"/.env
###> symfony/framework-bundle ### ###> symfony/framework-bundle ###
APP_ENV=$APP_ENV
APP_ENV=${APP_ENV}
APP_SECRET=82ec369b81caab5446ddfc3b5edb4d00 APP_SECRET=82ec369b81caab5446ddfc3b5edb4d00
CSRF_PROTECTION=$( CSRF_PROTECTION=$(
[ "$APP_ENV" == "prod" ] && [ "$APP_ENV" == "prod" ] &&

5
gogocarto/metadata.yml

@ -26,3 +26,8 @@ uses:
auto: summon auto: summon
solves: solves:
database: "main storage" database: "main storage"
schedule-commands:
constraint: recommended
auto: pair
solves:
maintenance: "Production scheduled tasks"
Loading…
Cancel
Save