diff --git a/.dockerignore b/.dockerignore index 09324fa9..93e7db9e 100644 --- a/.dockerignore +++ b/.dockerignore @@ -3,3 +3,5 @@ .git **/node_modules local +# Runtime log tree (bind-mounted at run time; the server image mkdir's its own). +log diff --git a/.gitignore b/.gitignore index 4e8d29c5..edd2ad8f 100644 --- a/.gitignore +++ b/.gitignore @@ -13,8 +13,13 @@ var/www/public/captcha data/ data.*.bak/ tmp/ -log/ captcha/ + +# Log tree: keep the directory skeleton (log/*/.gitkeep) but ignore the output. +log/**/*.log +log/**/*.gz +log/**/*.[0-9] +log/**/*.log.* /memcached/ node_modules/ .env diff --git a/bin/deploy.pl b/bin/deploy.pl index e1b29f3d..20719a7b 100755 --- a/bin/deploy.pl +++ b/bin/deploy.pl @@ -31,7 +31,9 @@ use Git::Wrapper; use AnyEvent::Util; use DateTime; $ENV{PATH} = '/data/apps/bin:' . $ENV{PATH}; -open STDOUT, '>>', '/tmp/lacuna-deploy.log'; +my $log_dir = $ENV{LACUNA_LOG_DIR} || '/home/lacuna/server/log'; +open(STDOUT, '>>', "$log_dir/deploy/deploy.log") + or open(STDOUT, '>>', '/tmp/lacuna-deploy.log'); open STDERR, '>&', \*STDOUT; sub out { diff --git a/bin/deploy.psgi b/bin/deploy.psgi index bd5a3b40..db91b5ba 120000 --- a/bin/deploy.psgi +++ b/bin/deploy.psgi @@ -28,7 +28,7 @@ sub dispatch { return "ignored: missing repo/branch\n" unless $repo && $branch; # Fire and forget - deploy.pl daemonises itself and logs to - # /tmp/lacuna-deploy.log. + # $LACUNA_LOG_DIR/deploy/deploy.log (falling back to /tmp/lacuna-deploy.log). system('perl', $deploy_script, $repo, $branch); return "deploying $repo / $branch\n"; } diff --git a/bin/init_sched.sh b/bin/init_sched.sh index bec62c7e..d251a2b2 100644 --- a/bin/init_sched.sh +++ b/bin/init_sched.sh @@ -1,2 +1,8 @@ +#!/bin/bash +# Legacy bare-metal launcher for the scheduler daemons (--daemonize). Under +# compose these run via bin/run_scheduler.sh instead. App::Daemon writes to +# $App::Daemon::logfile (set in each schedule_*.pl) but won't create the dir. +mkdir -p "${LACUNA_LOG_DIR:-/home/lacuna/server/log}/scheduler" + /data/apps/bin/perl /home/lacuna/server/bin/schedule_building.pl --noquiet --daemonize --initialize /data/apps/bin/perl /home/lacuna/server/bin/schedule_ship_arrival.pl --noquiet --daemonize --initialize diff --git a/bin/lacuna.logrotate b/bin/lacuna.logrotate index fcd66551..0e47136d 120000 --- a/bin/lacuna.logrotate +++ b/bin/lacuna.logrotate @@ -1,45 +1,28 @@ # logrotate configuration for The Lacuna Expanse server. # -# Reconstructed: this file only ever existed in this repo as a symlink into the -# (now gone) Lacuna-Server-Private repo. It is consumed by the OS logrotate cron, -# not by any repo code. Install it as /etc/logrotate.d/lacuna (or point logrotate -# at it directly). +# Consumed by the logrotate sidecar defined in docker/docker-compose.homelab.yml, +# which bind-mounts host ./log at /home/lacuna/server/log and this file at +# /etc/logrotate.d/lacuna. (It can equally be installed as /etc/logrotate.d/lacuna +# on a bare-metal host.) The paths below are the in-container log tree, which is +# also the host ./log tree via the bind mount. # -# The server's cron drivers (bin/run_*.sh), the schedule daemons -# (bin/schedule_{building,ship_arrival,captcha}.pl) and the deploy webhook all -# append to flat files under /tmp; the plack/starman processes write to -# /home/lacuna/server/log. Everything is rotated with copytruncate because those -# long-running processes keep the log file handles open and have no reopen signal. +# Every producer now writes into this tree: +# server/ - the plack app (Log4perl FILE appender) + plackup framework noise +# scheduler/ - schedule_{building,ship_arrival,captcha}.pl (via bin/run_scheduler.sh) +# cron/ - the ofelia-driven bin/run_*.sh batch scripts +# deploy/ - bin/deploy.pl +# nginx/ - nginx access.log + error.log +# +# copytruncate: plackup, the scheduler daemons and nginx hold their log handles +# open and have no cross-container reopen signal; truncating in place on the +# shared bind mount needs none. -/tmp/hourly.log -/tmp/run_two_hourly.log -/tmp/four_hourly.log -/tmp/daily.log -/tmp/weekly.log -/tmp/weekly_medals.log -/tmp/news_feeds.log -/tmp/tick_planets.log -/tmp/tick_spies.log -/tmp/tick_fissures.log -/tmp/test_weather.log -/tmp/schedule_building.log -/tmp/schedule_ship_arrival.log -/tmp/schedule_captcha.log -/tmp/attack_saben.log -/tmp/attack_diab.log -/tmp/attack_trel.log -/tmp/lacuna-deploy.log +/home/lacuna/server/log/server/*.log +/home/lacuna/server/log/scheduler/*.log +/home/lacuna/server/log/cron/*.log +/home/lacuna/server/log/deploy/*.log +/home/lacuna/server/log/nginx/*.log { - daily - rotate 7 - missingok - notifempty - compress - delaycompress - copytruncate -} - -/home/lacuna/server/log/*.log { daily rotate 14 missingok diff --git a/bin/run_daily.sh b/bin/run_daily.sh index b4135504..57eed565 100755 --- a/bin/run_daily.sh +++ b/bin/run_daily.sh @@ -1,10 +1,14 @@ #!/bin/bash export PATH=/data/apps/bin:$PATH -touch /tmp/daily.log cd /home/lacuna/server/bin -# redirect everything. -exec >> /tmp/daily.log +LOG_DIR="${LACUNA_LOG_DIR:-/home/lacuna/server/log}/cron" +mkdir -p "$LOG_DIR" + +# Single target for the whole run -> redirect once with `exec` (the multi-target +# run_*.sh scripts redirect per-line instead). +touch "$LOG_DIR/daily.log" +exec >> "$LOG_DIR/daily.log" exec 2>&1 perl trickle_essentia_veins.pl diff --git a/bin/run_four_hourly.sh b/bin/run_four_hourly.sh index ec2ff5b7..7a4b9d7f 100755 --- a/bin/run_four_hourly.sh +++ b/bin/run_four_hourly.sh @@ -1,5 +1,8 @@ #!/bin/bash export PATH=/data/apps/bin:$PATH cd /home/lacuna/server/bin -perl summarize_spies.pl >>/tmp/four_hourly.log 2>>/tmp/four_hourly.log +LOG_DIR="${LACUNA_LOG_DIR:-/home/lacuna/server/log}/cron" +mkdir -p "$LOG_DIR" + +perl summarize_spies.pl >>"$LOG_DIR/four_hourly.log" 2>>"$LOG_DIR/four_hourly.log" diff --git a/bin/run_hourly.sh b/bin/run_hourly.sh index 170328bf..13374cc9 100755 --- a/bin/run_hourly.sh +++ b/bin/run_hourly.sh @@ -1,20 +1,26 @@ #!/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 + +# Batch output goes to the shared log tree (host log/cron/). Several targets here, +# so redirect per-line; single-target scripts (run_daily.sh) use `exec` instead. +LOG_DIR="${LACUNA_LOG_DIR:-/home/lacuna/server/log}/cron" +mkdir -p "$LOG_DIR" + +perl clean_up_empires.pl >>"$LOG_DIR/hourly.log" 2>>"$LOG_DIR/hourly.log" +perl sanitize_ss.pl >>"$LOG_DIR/hourly.log" 2>>"$LOG_DIR/hourly.log" +perl summarize_economy.pl >>"$LOG_DIR/hourly.log" 2>>"$LOG_DIR/hourly.log" +perl generate_news_feeds.pl >>"$LOG_DIR/news_feeds.log" 2>>"$LOG_DIR/news_feeds.log" +perl tick_parliament.pl >>"$LOG_DIR/hourly.log" 2>>"$LOG_DIR/hourly.log" +perl add_missions.pl >>"$LOG_DIR/hourly.log" 2>>"$LOG_DIR/hourly.log" +perl clean_up_market.pl >>"$LOG_DIR/hourly.log" 2>>"$LOG_DIR/hourly.log" +perl jackpot/hourly_update.pl >>"$LOG_DIR/hourly.log" 2>>"$LOG_DIR/hourly.log" +perl trelvestian/hourly_update.pl >>"$LOG_DIR/hourly.log" 2>>"$LOG_DIR/hourly.log" +perl diablotin/hourly_update.pl >>"$LOG_DIR/hourly.log" 2>>"$LOG_DIR/hourly.log" +perl saben/hourly_update.pl >>"$LOG_DIR/hourly.log" 2>>"$LOG_DIR/hourly.log" +perl delambert/hourly_update.pl >>"$LOG_DIR/hourly.log" 2>>"$LOG_DIR/hourly.log" +perl cult/hourly_update.pl >>"$LOG_DIR/hourly.log" 2>>"$LOG_DIR/hourly.log" +perl tick_fissures.pl >>"$LOG_DIR/tick_fissures.log" 2>>"$LOG_DIR/tick_fissures.log" +#perl test_weather.pl >>"$LOG_DIR/test_weather.csv" 2>"$LOG_DIR/test_weather.log" +perl trelvestian/send_attack.pl >>"$LOG_DIR/attack_trel.log" 2>>"$LOG_DIR/attack_trel.log" & +perl tick_stations.pl >>"$LOG_DIR/hourly.log" 2>>"$LOG_DIR/hourly.log" diff --git a/bin/run_scheduler.sh b/bin/run_scheduler.sh new file mode 100644 index 00000000..34657231 --- /dev/null +++ b/bin/run_scheduler.sh @@ -0,0 +1,20 @@ +#!/bin/bash +# +# Wrapper for the long-running beanstalk scheduler daemons +# (schedule_building.pl / schedule_ship_arrival.pl / schedule_captcha.pl). +# +# Under compose these run --nodaemonize, so App::Daemon never redirects and their +# output would live only in `docker logs`. This tees combined stdout+stderr to +# the shared log tree (log/scheduler/