diff --git a/rhodecode-app/rhodecode-community.nomad.tpl b/rhodecode-app/rhodecode-community.nomad.tpl index 52ac6f6..a8d8897 100644 --- a/rhodecode-app/rhodecode-community.nomad.tpl +++ b/rhodecode-app/rhodecode-community.nomad.tpl @@ -67,6 +67,10 @@ job "rhodecode-community" { } } task "rhodecode" { + + # log-shipper + leader = true + artifact { source = "${extensions_url}" destination = "local" @@ -103,6 +107,7 @@ DB_UPGRADE=1 SETUP_APP=0 MAIN_INI_PATH="/secrets/rhodecode.optimized.ini" EXTERNAL_HOSTNAME={{ with secret "forge/rhodecode/app" }}{{ .Data.data.rc_external_hostname }}{{end}} +EXTERNAL_VIP_HOSTNAME={{ with secret "forge/rhodecode/app" }}{{ .Data.data.rc_external_vip_hostname }}{{end}} EOT destination="local/rc.env" env = true @@ -659,7 +664,10 @@ EOT } service { name = "$\u007BNOMAD_TASK_NAME\u007D-http" - tags = ["urlprefix-$\u007BEXTERNAL_HOSTNAME\u007D"] + tags = [ + "urlprefix-$${EXTERNAL_HOSTNAME}", + "urlprefix-$${EXTERNAL_VIP_HOSTNAME}" + ] port = "rhodecode" check { name = "rhodecode-alive" @@ -1081,6 +1089,35 @@ EOT } } - } -} + # log-shipper + task "log-shipper" { + driver = "docker" + restart { + interval = "3m" + attempts = 5 + delay = "15s" + mode = "delay" + } + meta { + INSTANCE = "$\u007BNOMAD_ALLOC_NAME\u007D" + } + template { + data = < $BACKUP_DIR/$DATE/$BACKUP_REPO_FILENAME +BACKUP_RESULT=$? +if [ $BACKUP_RESULT -gt 1 ] +then + echo "Repo backup failed with error code : ${BACKUP_RESULT}" + exit 1 +else + echo "Repo backup done" +fi + +# Dump rhodecode bdd +echo "starting rhodecode dump..." +$NOMAD exec -task rhodecode-postgres -job rhodecode-postgres pg_dump -F c --dbname=postgresql://postgres@localhost/rhodecode > $BACKUP_DIR/$DATE/$DUMP_FILENAME + +DUMP_RESULT=$? +if [ $DUMP_RESULT -gt 0 ] +then + echo "Rhodecode dump failed with error code : ${DUMP_RESULT}" + exit 1 +else + echo "Rhodecode dump done" +fi + +# Remove files older than X days +find $BACKUP_DIR/* -mtime +$RETENTION -exec rm -rf {} \; + +echo "Backup Rhodecode finished" + +echo "Purging data from user_logs" +$NOMAD exec -task rhodecode-postgres -job rhodecode-postgres su -c "psql -d rhodecode -c \"copy (select * from user_logs where DATE(action_date) < NOW() - INTERVAL '15 DAY') to '/tmp/rhodecode_user_logs.csv' delimiter ',' CSV HEADER;\"" - postgres +$NOMAD exec -task rhodecode-postgres -job rhodecode-postgres tar -cOzv /tmp/rhodecode_user_logs.csv > $BACKUP_USER_LOGS_DIR/$BACKUP_USER_LOGS_FILENAME +$NOMAD exec -task rhodecode-postgres -job rhodecode-postgres rm -f /tmp/rhodecode_user_logs.csv +$NOMAD exec -task rhodecode-postgres -job rhodecode-postgres su -c "psql -d rhodecode -c \"delete from user_logs where DATE(action_date) < NOW() - INTERVAL '15 DAY';\"" - postgres +$NOMAD exec -task rhodecode-postgres -job rhodecode-postgres su -c "psql -d rhodecode -c \"VACUUM (VERBOSE, ANALYZE) user_logs;\"" - postgres + +echo "Data purging finished"