diff --git a/docker-compose.yml b/docker-compose.yml index 916f816571..817bf0570d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -74,6 +74,8 @@ services: # SHARELATEX_EMAIL_SMTP_LOGGER: true # SHARELATEX_CUSTOM_EMAIL_FOOTER: "This system is run by department x" + # ENABLE_CRON_RESOURCE_DELETION: true + ################ ## Server Pro ## ################ diff --git a/server-ce/Dockerfile b/server-ce/Dockerfile index ccf203b6cd..9929211574 100644 --- a/server-ce/Dockerfile +++ b/server-ce/Dockerfile @@ -51,6 +51,8 @@ RUN chmod 644 /etc/logrotate.d/sharelatex ADD server-ce/cron /overleaf/cron ADD server-ce/config/crontab-history /etc/cron.d/crontab-history RUN chmod 600 /etc/cron.d/crontab-history +ADD server-ce/config/crontab-deletion /etc/cron.d/crontab-deletion +RUN chmod 600 /etc/cron.d/crontab-deletion # Copy Phusion Image startup and shutdown scripts to their locations # ------------------------------------------------------------------ diff --git a/server-ce/config/crontab-deletion b/server-ce/config/crontab-deletion new file mode 100644 index 0000000000..b3238738da --- /dev/null +++ b/server-ce/config/crontab-deletion @@ -0,0 +1,3 @@ +5 * * * * root /overleaf/cron/deactivate-projects.sh >> /var/log/sharelatex/cron-deactivate-projects.log 2>&1 +15 * * * * root /overleaf/cron/delete-users.sh >> /var/log/sharelatex/cron-delete-users.log 2>&1 +20 * * * * root /overleaf/cron/delete-projects.sh >> /var/log/sharelatex/cron-delete-projects.log 2>&1 diff --git a/server-ce/cron/deactivate-projects.sh b/server-ce/cron/deactivate-projects.sh new file mode 100755 index 0000000000..b5c5083d95 --- /dev/null +++ b/server-ce/cron/deactivate-projects.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env bash + +set -eux + +echo "-------------------------" +echo "Deactivating old projects" +echo "-------------------------" +date + +ENABLE_CRON_RESOURCE_DELETION=$(cat /etc/container_environment/ENABLE_CRON_RESOURCE_DELETION) + +if [[ "${ENABLE_CRON_RESOURCE_DELETION:-null}" != "true" ]]; then + echo "Skipping old project deactivation due to ENABLE_CRON_RESOURCE_DELETION not set to true" + exit 0 +fi + +WEB_URL='http://localhost:3000' + +USER=$(cat /etc/container_environment/WEB_API_USER) +PASS=$(cat /etc/container_environment/WEB_API_PASSWORD) + +curl -v -X POST \ + -u "${USER}:${PASS}" \ + -H "Content-Type: application/json" \ + -d '{"numberOfProjectsToArchive":"720","ageOfProjects":"7"}' \ + "${WEB_URL}/internal/deactivateOldProjects" + +echo "Done." diff --git a/server-ce/cron/delete-projects.sh b/server-ce/cron/delete-projects.sh new file mode 100755 index 0000000000..e4127a87fc --- /dev/null +++ b/server-ce/cron/delete-projects.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash + +set -eux + +echo "-------------------------" +echo "Expiring deleted projects" +echo "-------------------------" +date + +ENABLE_CRON_RESOURCE_DELETION=$(cat /etc/container_environment/ENABLE_CRON_RESOURCE_DELETION) + +if [[ "${ENABLE_CRON_RESOURCE_DELETION:-null}" != "true" ]]; then + echo "Skipping project expiration due to ENABLE_CRON_RESOURCE_DELETION not set to true" + exit 0 +fi + +WEB_URL='http://localhost:3000' + +USER=$(cat /etc/container_environment/WEB_API_USER) +PASS=$(cat /etc/container_environment/WEB_API_PASSWORD) + +curl -X POST -v -u "${USER}:${PASS}" \ + "${WEB_URL}/internal/expire-deleted-projects-after-duration" + +echo "Done." diff --git a/server-ce/cron/delete-users.sh b/server-ce/cron/delete-users.sh new file mode 100755 index 0000000000..ae015e751d --- /dev/null +++ b/server-ce/cron/delete-users.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash + +set -eux + +echo "----------------------" +echo "Expiring deleted users" +echo "----------------------" +date + +ENABLE_CRON_RESOURCE_DELETION=$(cat /etc/container_environment/ENABLE_CRON_RESOURCE_DELETION) + +if [[ "${ENABLE_CRON_RESOURCE_DELETION:-null}" != "true" ]]; then + echo "Skipping user expiration due to ENABLE_CRON_RESOURCE_DELETION not set to true" + exit 0 +fi + +WEB_URL='http://localhost:3000' + +USER=$(cat /etc/container_environment/WEB_API_USER) +PASS=$(cat /etc/container_environment/WEB_API_PASSWORD) + +curl -X POST -v -u "${USER}:${PASS}" \ + "${WEB_URL}/internal/expire-deleted-users-after-duration" + +echo "Done."