Преглед на файлове

Railway image: run UNA's scheduler every minute (#5875)

The Railway image (api.unacms.app and PR previews) never ran
periodic/cron.php: sys_cron_time stayed 0, transient jobs such as
recommendations_for_<id> piled up, and the email, push and transcoder
queues, timeline hot and pruning never ran. Friend and follow suggestions
stayed empty.

entrypoint.sh now starts a background loop, after install and seeding,
that starts cron.php at the top of every minute as www-data. Runs may
overlap, as under cron, so a long transcode does not hold up the queues.
UNA_HTTP_HOST and HTTPS are set for the scheduler only; Apache keeps
taking the host from each request.

configure.php turns sys_autoupdate off on every start. With cron running,
the nightly upgrade check would upgrade a master-built site to the latest
release, and the next deploy would put master's files back over the
upgraded database.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Andrey Yasko преди 5 дни
родител
ревизия
6c35780262
променени са 2 файла, в които са добавени 24 реда и са изтрити 0 реда
  1. 4 0
      scripts/railway/configure.php
  2. 20 0
      scripts/railway/entrypoint.sh

+ 4 - 0
scripts/railway/configure.php

@@ -58,6 +58,10 @@ $aOptions = [
     'sys_api_root_page_guest' => 'splash',
     'sys_api_root_page_member' => 'home',
     'sys_iconset_default' => 'sys_lucide',
+    // Deploys bring the code. UNA's nightly auto-update (a cron job, run by entrypoint.sh) would
+    // upgrade files and database to the latest release, and the next deploy would put this
+    // build's files back over the upgraded database.
+    'sys_autoupdate' => '',
 ];
 if ($sClientUrl !== '') {
     $aOptions['sys_api_url_root_email'] = $sClientUrl . '/';

+ 20 - 0
scripts/railway/entrypoint.sh

@@ -134,4 +134,24 @@ fi
 
 chown -R www-data:www-data inc cache cache_public logs tmp storage
 
+# UNA's scheduler. periodic/cron.php expects to be started every minute, like the crontab line
+# in UNA's install instructions (and scripts/docker-compose/Cron.Dockerfile). The image has no
+# cron daemon, so a background loop starts a run at the top of each minute. As under cron, runs
+# may overlap, so a long video transcode does not hold up the email and push queues. It starts
+# after install and seeding, so it never sees a half-installed site.
+# - It runs as www-data, so cache files it writes stay writable by Apache. setpriv keeps the
+#   environment (UNA_DB_*, UNA_ROOT_DIR...), which su would reset.
+# - A CLI run has no request to take a host from, so UNA_HTTP_HOST and HTTPS give it the public
+#   URL. They are set for the scheduler only: Apache keeps taking the host from each request.
+run_cron() {
+    env UNA_HTTP_HOST="${RAILWAY_PUBLIC_DOMAIN:-localhost}" HTTPS=on \
+        setpriv --reuid=www-data --regid=www-data --init-groups \
+        php /var/www/html/periodic/cron.php || echo "UNA cron failed (exit $?)" >&2
+}
+while true; do
+    sleep $((60 - $(date +%s) % 60))
+    jobs >/dev/null # dash keeps a record of every finished run until it is listed
+    run_cron &
+done &
+
 exec "$@"