diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..c7a9da9 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,13 @@ +from mariadb:10.5 + +ENV PATH_TO_STATS=/stats/ + +COPY . $PATH_TO_STATS + +RUN apt-get update && \ + apt install cron curl wget jq -y && \ + apt-get clean + +WORKDIR $PATH_TO_STATS + +ENTRYPOINT /stats/entrypoint.sh diff --git a/config.ini.example b/config.ini.example index 471c287..a177023 100644 --- a/config.ini.example +++ b/config.ini.example @@ -11,6 +11,12 @@ PATH_TO_STATS=/home/dkmur/temp/Stats/ DEFINED_SCAN_AREAS='Amsterdam, London, Paris' DEFAULT_AREA=London +## Quest Settings ## +QUEST_START='02:00:00' +QUEST_END='06:00:00' +QUEST_CLEAN_HR=6 +QUEST_CLEAN_MIN=13 + ## Grafana ## DataSource=pogodb diff --git a/crontab.txt.default b/crontab.txt.default index a74f204..99bb088 100644 --- a/crontab.txt.default +++ b/crontab.txt.default @@ -12,4 +12,4 @@ 7 0 * * * cd pathToStatssql_cron/ && mysql userpass < 1440_worker.sql 9 0 * * 1 cd pathToStatssql_cron/ && mysql userpass < 10080_worker.sql ## Cleanup spawnpoints discovered during Quest hours -# 13 6 * * 1 cd pathToStatssql_cron/ && mysql userpass < quest_spawn_cleanup.sql +# QMIN QHR * * 1 cd pathToStatssql_cron/ && mysql userpass < quest_spawn_cleanup.sql diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 0000000..9c9cc4b --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash +# This is a k8s concession, since you can not map a volume to a specific +# file, you must map an entire directory. This simply moves the file to +# where the stats cronjobs are expecting to find it. +cp /stats/config/config.ini /stats/config.ini + +# Initialization is idempotent, and creates files which will die with the +# container. +/stats/settings.run + +if "$QUEST_CLEAN" +then + sed -i '$ s/# //g' /stats/crontab.txt +fi + +crontab /stats/crontab.txt +crontab -l + +# Run the cron deaemon +/usr/sbin/cron -f -L /dev/stdout diff --git a/settings.run b/settings.run index 4faad2f..e78b69c 100755 --- a/settings.run +++ b/settings.run @@ -7,6 +7,8 @@ cp crontab.txt.default crontab.txt PATH_TO_STATS2=$(sed 's@/@\\/@g' <<< $PATH_TO_STATS) cd $PATH_TO_STATS && sed -i "s/pathToStats/$PATH_TO_STATS2/g" *.txt cd $PATH_TO_STATS && sed -i "s/STATS_DB/$STATS_DB/g" *.txt +cd $PATH_TO_STATS && sed -i "s/QMIN/$QUEST_CLEAN_MIN/g" *.txt +cd $PATH_TO_STATS && sed -i "s/QHR/$QUEST_CLEAN_HR/g" *.txt if [ -z "$SQL_password" ] then diff --git a/sql_cron/quest_spawn_cleanup.sql.default b/sql_cron/quest_spawn_cleanup.sql.default index 09a0ce6..01ef54b 100644 --- a/sql_cron/quest_spawn_cleanup.sql.default +++ b/sql_cron/quest_spawn_cleanup.sql.default @@ -5,16 +5,16 @@ select spawnpoint,latitude,longitude,spawndef,earliest_unseen,last_scanned,first from rmdb.trs_spawn where date(first_detection) = curdate() and -time(first_detection) >= '02:00:00' and -time(first_detection) <= '06:00:00' +time(first_detection) >= 'queststart' and +time(first_detection) <= 'questend' ; -- remove from trs_spawn delete from rmdb.trs_spawn where date(first_detection) = curdate() and -time(first_detection) >= '02:00:00' and -time(first_detection) <= '06:00:00' +time(first_detection) >= 'queststart' and +time(first_detection) <= 'questend' ; -- daily cleanup spawns not seen for 5 days