From 1adedd4c5ec9c5128115d51c73c81d6cb08b2177 Mon Sep 17 00:00:00 2001 From: Natalie Rose Date: Tue, 12 Aug 2025 15:15:08 +1000 Subject: [PATCH] Implement scheduled tasks stuff --- .gitignore | 2 + bin/run_four_hourly.sh | 2 +- bin/run_hourly.sh | 21 +++++++- bin/run_hourly.sh.sample | 20 ------- bin/run_two_hourly.sh | 4 +- bin/startdev.sh | 2 + docker-compose.yml | 110 ++++++++++++++++++++++++++++++--------- etc-docker/crontab | 8 --- etc-docker/lacuna.conf | 10 ++-- etc-docker/schedule.ini | 42 +++++++++++++++ 10 files changed, 159 insertions(+), 62 deletions(-) mode change 120000 => 100755 bin/run_hourly.sh delete mode 100755 bin/run_hourly.sh.sample delete mode 100644 etc-docker/crontab create mode 100644 etc-docker/schedule.ini diff --git a/.gitignore b/.gitignore index 4ef82a03..8c6f24da 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,5 @@ var/www/public/api var/www/public/captcha data/ etc-docker/logs/ +tmp/ +log/ diff --git a/bin/run_four_hourly.sh b/bin/run_four_hourly.sh index cc121322..ec2ff5b7 100755 --- a/bin/run_four_hourly.sh +++ b/bin/run_four_hourly.sh @@ -1,5 +1,5 @@ #!/bin/bash export PATH=/data/apps/bin:$PATH cd /home/lacuna/server/bin -perl summarize_spies.pl >>/var/log/four_hourly.log 2>>/var/log/four_hourly.log +perl summarize_spies.pl >>/tmp/four_hourly.log 2>>/tmp/four_hourly.log diff --git a/bin/run_hourly.sh b/bin/run_hourly.sh deleted file mode 120000 index 28772af5..00000000 --- a/bin/run_hourly.sh +++ /dev/null @@ -1 +0,0 @@ -../../Lacuna-Server-Private/bin/run_hourly.sh \ No newline at end of file diff --git a/bin/run_hourly.sh b/bin/run_hourly.sh new file mode 100755 index 00000000..170328bf --- /dev/null +++ b/bin/run_hourly.sh @@ -0,0 +1,20 @@ +#!/bin/bash +export PATH=/data/apps/bin:$PATH +cd /home/lacuna/server/bin +perl clean_up_empires.pl >>/tmp/hourly.log 2>>/tmp/hourly.log +perl sanitize_ss.pl >>/tmp/hourly.log 2>>/tmp/hourly.log +perl summarize_economy.pl >>/tmp/hourly.log 2>>/tmp/hourly.log +perl generate_news_feeds.pl >>/tmp/news_feeds.log 2>>/tmp/news_feeds.log +perl tick_parliament.pl >>/tmp/hourly.log 2>>/tmp/hourly.log +perl add_missions.pl >>/tmp/hourly.log 2>>/tmp/hourly.log +perl clean_up_market.pl >>/tmp/hourly.log 2>>/tmp/hourly.log +perl jackpot/hourly_update.pl >>/tmp/hourly.log 2>>/tmp/hourly.log +perl trelvestian/hourly_update.pl >>/tmp/hourly.log 2>>/tmp/hourly.log +perl diablotin/hourly_update.pl >>/tmp/hourly.log 2>>/tmp/hourly.log +perl saben/hourly_update.pl >>/tmp/hourly.log 2>>/tmp/hourly.log +perl delambert/hourly_update.pl >>/tmp/hourly.log 2>>/tmp/hourly.log +perl cult/hourly_update.pl >>/tmp/hourly.log 2>>/tmp/hourly.log +perl tick_fissures.pl >>/tmp/tick_fissures.log 2>>/tmp/tick_fissures.log +#perl test_weather.pl >>/tmp/test_weather.csv 2>/tmp/test_weather.log +perl trelvestian/send_attack.pl >>/tmp/attack_trel.log 2>>/tmp/attack_trel.log & +perl tick_stations.pl >>/tmp/hourly.log 2>>/tmp/hourly.log diff --git a/bin/run_hourly.sh.sample b/bin/run_hourly.sh.sample deleted file mode 100755 index 170328bf..00000000 --- a/bin/run_hourly.sh.sample +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash -export PATH=/data/apps/bin:$PATH -cd /home/lacuna/server/bin -perl clean_up_empires.pl >>/tmp/hourly.log 2>>/tmp/hourly.log -perl sanitize_ss.pl >>/tmp/hourly.log 2>>/tmp/hourly.log -perl summarize_economy.pl >>/tmp/hourly.log 2>>/tmp/hourly.log -perl generate_news_feeds.pl >>/tmp/news_feeds.log 2>>/tmp/news_feeds.log -perl tick_parliament.pl >>/tmp/hourly.log 2>>/tmp/hourly.log -perl add_missions.pl >>/tmp/hourly.log 2>>/tmp/hourly.log -perl clean_up_market.pl >>/tmp/hourly.log 2>>/tmp/hourly.log -perl jackpot/hourly_update.pl >>/tmp/hourly.log 2>>/tmp/hourly.log -perl trelvestian/hourly_update.pl >>/tmp/hourly.log 2>>/tmp/hourly.log -perl diablotin/hourly_update.pl >>/tmp/hourly.log 2>>/tmp/hourly.log -perl saben/hourly_update.pl >>/tmp/hourly.log 2>>/tmp/hourly.log -perl delambert/hourly_update.pl >>/tmp/hourly.log 2>>/tmp/hourly.log -perl cult/hourly_update.pl >>/tmp/hourly.log 2>>/tmp/hourly.log -perl tick_fissures.pl >>/tmp/tick_fissures.log 2>>/tmp/tick_fissures.log -#perl test_weather.pl >>/tmp/test_weather.csv 2>/tmp/test_weather.log -perl trelvestian/send_attack.pl >>/tmp/attack_trel.log 2>>/tmp/attack_trel.log & -perl tick_stations.pl >>/tmp/hourly.log 2>>/tmp/hourly.log diff --git a/bin/run_two_hourly.sh b/bin/run_two_hourly.sh index a695d40c..86cc938d 100755 --- a/bin/run_two_hourly.sh +++ b/bin/run_two_hourly.sh @@ -1,8 +1,8 @@ #!/bin/bash export PATH=/data/apps/bin:$PATH cd /home/lacuna/server/bin -perl tick_planets.pl >>/var/log/tick_planets.log 2>>/var/log/tick_planets.log & +perl tick_planets.pl >>/tmp/tick_planets.log 2>>/tmp/tick_planets.log & perl tick_spies.pl >>/tmp/tick_spies.log 2>>/tmp/tick_spies.log & -perl summarize_server.pl >>/var/log/run_two_hourly.log 2>>/var/log/run_two_hourly.log +perl summarize_server.pl >>/tmp/run_two_hourly.log 2>>/tmp/run_two_hourly.log perl saben/send_attack.pl >>/tmp/attack_saben.log 2>>/tmp/attack_saben.log & perl diablotin/send_attack.pl >>/tmp/attack_diab.log 2>>/tmp/attack_diab.log & diff --git a/bin/startdev.sh b/bin/startdev.sh index b92b2cdf..dc35a22b 100755 --- a/bin/startdev.sh +++ b/bin/startdev.sh @@ -1 +1,3 @@ +perl generate_docs.pl > /dev/null + plackup --env development --server Plack::Handler::Standalone --app lacuna.psgi diff --git a/docker-compose.yml b/docker-compose.yml index 8149d6ea..1da3320e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -25,25 +25,6 @@ services: ports: - '11300:11300' - ############### - ## BG WORKER ## - ############### - - # lacuna-bg-worker: - # command: 'perl bg_worker.pl daemon --nodaemonize --verbose' - # container_name: 'lacuna-bg-worker' - # depends_on: - # - 'lacuna-server' - # image: 'lacuna/lacuna-server' - # volumes: - # - ./bin:/home/lacuna/server/bin - # - ./docs:/home/lacuna/server/docs - # - ./etc-docker:/home/lacuna/server/etc - # - ./log:/home/lacuna/server/log - # - ./lib:/home/lacuna/server/lib - # - ./t:/home/lacuna/server/t - # - ./var:/home/lacuna/server/var - ############### ## MEMCACHED ## ############### @@ -94,7 +75,6 @@ services: container_name: 'lacuna-nginx' depends_on: - 'lacuna-server' - # image: 'lacuna/lacuna-nginx' ports: - '8080:80' - '8443:443' @@ -102,10 +82,11 @@ services: - ./etc-docker/nginx.conf:/etc/nginx/nginx.conf - ./etc-docker:/home/lacuna/server/etc - ./var:/home/lacuna/server/var - - ./log:/home/lacuna/server/log + - ./log/nginx:/etc/nginx/logs - ./captcha:/home/lacuna/server/captcha - ./assets:/home/lacuna/server/var/www/public/assets - ./var/www/public/api/api.css:/home/lacuna/server/var/www/public/api/api.css + # TODO: fix CORS etc so that the app can run here properly # - ./app/dist/index.html:/home/lacuna/server/var/www/public/index.html # - ./app/dist/app:/home/lacuna/server/var/www/public/app - ./app/dist:/home/lacuna/server/var/www/public/app @@ -120,7 +101,6 @@ services: ports: - '6379:6379' - ######### ## APP ## ######### @@ -135,8 +115,8 @@ services: - app-node_modules:/usr/src/app/node_modules - ./app:/usr/src/app environment: - - 'LACUNA_ASSETS_URL=/assets/' - - 'LACUNA_SERVER_URL=/' + - 'LACUNA_ASSETS_URL=https://lacuna.ocean74.net/assets/' + - 'LACUNA_SERVER_URL=https://lacuna.ocean74.net' - 'LACUNA_API_KEY=anonymous' ############ @@ -157,7 +137,6 @@ services: - 'lacuna-beanstalkd' environment: - 'TLE_NO_MIDDLEWARE=1' - image: 'lacuna/lacuna-server' ports: - '3050:5000' volumes: @@ -165,8 +144,87 @@ services: - ./captcha:/home/lacuna/server/captcha - ./docs:/home/lacuna/server/docs - ./etc-docker:/home/lacuna/server/etc - - ./log:/home/lacuna/server/log - ./lib:/home/lacuna/server/lib - ./t:/home/lacuna/server/t - ./var:/home/lacuna/server/var - ./var/www/public/api/api.css:/home/lacuna/server/var/www/public/api/api.css + - ./tmp:/tmp + + lacuna-server-building-scheduler: + build: + context: . + dockerfile: ./docker/build-server/Dockerfile + command: 'perl schedule_building.pl --noquiet --nodaemonize --noinitialize' + container_name: 'lacuna-server-building-scheduler' + depends_on: + - 'lacuna-mysql-server' + - 'lacuna-phpmyadmin' + - 'lacuna-redis' + - 'lacuna-memcached' + - 'lacuna-beanstalkd' + volumes: + - ./bin:/home/lacuna/server/bin + - ./captcha:/home/lacuna/server/captcha + - ./docs:/home/lacuna/server/docs + - ./etc-docker:/home/lacuna/server/etc + - ./lib:/home/lacuna/server/lib + - ./t:/home/lacuna/server/t + - ./var:/home/lacuna/server/var + - ./var/www/public/api/api.css:/home/lacuna/server/var/www/public/api/api.css + - ./tmp:/tmp + + lacuna-server-ship-scheduler: + build: + context: . + dockerfile: ./docker/build-server/Dockerfile + command: 'perl schedule_ship_arrival.pl --noquiet --nodaemonize --noinitialize' + container_name: 'lacuna-server-ship-scheduler' + depends_on: + - 'lacuna-mysql-server' + - 'lacuna-phpmyadmin' + - 'lacuna-redis' + - 'lacuna-memcached' + - 'lacuna-beanstalkd' + volumes: + - ./bin:/home/lacuna/server/bin + - ./captcha:/home/lacuna/server/captcha + - ./docs:/home/lacuna/server/docs + - ./etc-docker:/home/lacuna/server/etc + - ./lib:/home/lacuna/server/lib + - ./t:/home/lacuna/server/t + - ./var:/home/lacuna/server/var + - ./var/www/public/api/api.css:/home/lacuna/server/var/www/public/api/api.css + - ./tmp:/tmp + + lacuna-server-captcha-scheduler: + build: + context: . + dockerfile: ./docker/build-server/Dockerfile + command: 'perl schedule_captcha.pl --noquiet --nodaemonize --noinitialize' + container_name: 'lacuna-server-captcha-scheduler' + depends_on: + - 'lacuna-mysql-server' + - 'lacuna-phpmyadmin' + - 'lacuna-redis' + - 'lacuna-memcached' + - 'lacuna-beanstalkd' + volumes: + - ./bin:/home/lacuna/server/bin + - ./captcha:/home/lacuna/server/captcha + - ./docs:/home/lacuna/server/docs + - ./etc-docker:/home/lacuna/server/etc + - ./lib:/home/lacuna/server/lib + - ./t:/home/lacuna/server/t + - ./var:/home/lacuna/server/var + - ./var/www/public/api/api.css:/home/lacuna/server/var/www/public/api/api.css + - ./tmp:/tmp + + lacuna-server-script-scheduler: + container_name: 'lacuna-server-script-scheduler' + image: mcuadros/ofelia:latest + depends_on: + - lacuna-server + command: daemon + volumes: + - /var/run/docker.sock:/var/run/docker.sock:ro + - ./etc-docker/schedule.ini:/etc/ofelia.conf diff --git a/etc-docker/crontab b/etc-docker/crontab deleted file mode 100644 index 0c432300..00000000 --- a/etc-docker/crontab +++ /dev/null @@ -1,8 +0,0 @@ -20 * * * * /data/apps/bin/perl /home/lacuna/server/bin/schedule_building.pl --noquiet --daemonize --noinitialize -50 * * * * /data/apps/bin/perl /home/lacuna/server/bin/schedule_ship_arrival.pl --noquiet --daemonize --noinitialize - -0 * * * * /home/lacuna/server/bin/run_hourly.sh -10 1,3,5,7,9,11,13,15,17,19,21,23 * * * /home/lacuna/server/bin/run_two_hourly.sh -40 2,6,10,14,18,22 * * * /home/lacuna/server/bin/run_four_hourly.sh -15 3 * * * /home/lacuna/server/bin/run_daily.sh -15 6 * * 0 /home/lacuna/server/bin/run_weekly.sh diff --git a/etc-docker/lacuna.conf b/etc-docker/lacuna.conf index f8cb5528..1ff9dba1 100644 --- a/etc-docker/lacuna.conf +++ b/etc-docker/lacuna.conf @@ -2,7 +2,10 @@ { "develop_mode" : 0, - "access_key" : "XXXX", + # Amazon S3 details + # "access_key" : "XXXX", + # "secret_key" : "XXXX", + "bhg_param" : { # If any are set to 0, use default. "success" : 0, @@ -107,14 +110,13 @@ }, "rpc_limit" : 10000, "rpc_throttle" : 200, - "secret_key" : "XXXX", "self_destruct_after_inactive_days" : 9999999, "server_key" : "XXXX", "server_keys" : [ "XXXX" ], - "server_url" : "http://localhost:8080/", - "assets_url": "http://raw.githubusercontent.com/Kantigen/Lacuna-Assets/master/", + "server_url" : "https://lacuna.ocean74.net/", + "assets_url": "https://lacuna.ocean74.net/assets/", "starter_zone" : { # If zone is set to a valid zone, x & y are confined to within that zone. # Coord set to 1 will further narrow area. diff --git a/etc-docker/schedule.ini b/etc-docker/schedule.ini new file mode 100644 index 00000000..6085697d --- /dev/null +++ b/etc-docker/schedule.ini @@ -0,0 +1,42 @@ +# +# TLE schedule based off of the following example cron file that was probably used in production back in the day +# +# +# 20 * * * * /data/apps/bin/perl /home/lacuna/server/bin/schedule_building.pl --noquiet --daemonize --noinitialize +# 50 * * * * /data/apps/bin/perl /home/lacuna/server/bin/schedule_ship_arrival.pl --noquiet --daemonize --noinitialize +# +# 0 * * * * /home/lacuna/server/bin/run_hourly.sh +# 10 1,3,5,7,9,11,13,15,17,19,21,23 * * * /home/lacuna/server/bin/run_two_hourly.sh +# 40 2,6,10,14,18,22 * * * /home/lacuna/server/bin/run_four_hourly.sh +# 15 3 * * * /home/lacuna/server/bin/run_daily.sh +# 15 6 * * 0 /home/lacuna/server/bin/run_weekly.sh +# +# Special note that the building and ship schedule scripts now run as separate docker containers +# +# This config is passed to Ofelia, docs here https://github.com/mcuadros/ofelia +# + +[job-exec "hourly-tasks"] +schedule = @hourly +container = lacuna-server +command = ./run_hourly.sh + +[job-exec "two-hourly-tasks"] +schedule = 10 1,3,5,7,9,11,13,15,17,19,21,23 * * * +container = lacuna-server +command = ./run_two_hourly.sh + +[job-exec "four-hourly-tasks"] +schedule = 40 2,6,10,14,18,22 * * * +container = lacuna-server +command = ./run_four_hourly.sh + +[job-exec "daily-tasks"] +schedule = 15 3 * * * +container = lacuna-server +command = ./run_daily.sh + +[job-exec "weekly-tasks"] +schedule = 15 6 * * 0 +container = lacuna-server +command = ./run_weekly.sh -- 2.54.0