From b1c66167eee06a60ccf6734dc476d73141617603 Mon Sep 17 00:00:00 2001 From: B Date: Sat, 17 Mar 2018 00:08:35 +0100 Subject: [PATCH] Add option to use cron within container --- Dockerfile | 4 ++-- README.md | 29 +++++++++++++++++++---------- entrypoint.sh | 14 +++++++++++++- 3 files changed, 34 insertions(+), 13 deletions(-) diff --git a/Dockerfile b/Dockerfile index 3806b7f..c98cfd1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,8 +3,8 @@ MAINTAINER Jeroen Geusebroek ENV DEBIAN_FRONTEND="noninteractive" \ TERM="xterm" \ - APTLIST="apache2 php7.1 php7.1-curl php7.1-gd php7.1-gmp php7.1-mysql php7.1-xml php7.1-xmlrpc php7.1-mbstring php7.1-zip git-core" \ - REFRESHED_AT='2017-11-09' + APTLIST="apache2 php7.1 php7.1-curl php7.1-gd php7.1-gmp php7.1-mysql php7.1-xml php7.1-xmlrpc php7.1-mbstring php7.1-zip git-core cron" \ + REFRESHED_AT='2018-03-16' RUN echo "force-unsafe-io" > /etc/dpkg/dpkg.cfg.d/02apt-speedup &&\ echo "Acquire::http {No-Cache=True;};" > /etc/apt/apt.conf.d/no-cache && \ diff --git a/README.md b/README.md index 81b29ad..0b031e2 100644 --- a/README.md +++ b/README.md @@ -43,26 +43,35 @@ Please NOTE that the volume is optional. Only necessary when you have special co You should now be able to reach the spotweb interface on port 80. -### Automatic retreiving of new spots - -To enable automatic retreiving, you need to setup a cronjob on the docker host. +### Automatic retrieval of new spots +To enable automatic retrieval, you need to setup a cronjob on either the docker host or within the container. +#### Automatic retrieval of new spots on the docker host +To enable automatic retrieval, you need to setup a cronjob on the docker host. */15 * * * * docker exec spotweb su -l www-data -s /usr/bin/php /var/www/spotweb/retrieve.php >/dev/null 2>&1 This example will retrieve new spots every 15 minutes. +#### Automatic retrieval of new spots from within the container +To enable automatic retrieval from within the container, use the `SPOTWEB_CRON_RETRIEVE` variable to specify the cron timing for retrieval. For example as additional parameter to the `docker run` command: + + -e SPOTWEB_CRON_RETRIEVE='*/15 * * * *' + ### Updates The container will try to auto-update the database when a newer version is released. ### Environment variables - -* `TZ` The timezone the server is running in. Defaults to `Europe/Amsterdam`. -* `SPOTWEB_DB_TYPE` Database type. Use `pdo_mysql` for MySQL. -* `SPOTWEB_DB_HOST` The hostname / IP of the database server. -* `SPOTWEB_DB_NAME` The database used for spotweb. -* `SPOTWEB_DB_USER` The database server username. -* `SPOTWEB_DB_PASS` The database server password. +| Variable | Function | +| --- | --- | +| `TZ` | The timezone the server is running in. Defaults to `Europe/Amsterdam`. | +| `SPOTWEB_DB_TYPE` | Database type. Use `pdo_mysql` for MySQL. | +| `SPOTWEB_DB_HOST` | The hostname / IP of the database server. | +| `SPOTWEB_DB_NAME` | The database used for spotweb. | +| `SPOTWEB_DB_USER` | The database server username. | +| `SPOTWEB_DB_PASS` | The database server password. | +| `SPOTWEB_CRON_RETRIEVE` | Cron schedule for article retrieval. E.g. `'*/15 * * * *'` for every fifteen minutes.| +| `SPOTWEB_CRON_CACHE_CHECK` | Cron schedule for article cache sanity check. E.g. `'10 */1 * * *'` for 10 minutes after every hour. | ## License diff --git a/entrypoint.sh b/entrypoint.sh index 6848d87..4a5e832 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -32,6 +32,18 @@ TZ=${TZ:-"Europe/Amsterdam"} echo -e "Setting (PHP) time zone to ${TZ}\n" sed -i "s#^;date.timezone =.*#date.timezone = ${TZ}#g" /etc/php/7.*/*/php.ini +if [[ -n "$SPOTWEB_CRON_RETRIEVE" || -n "$SPOTWEB_CRON_CACHE_CHECK" ]]; then + ln -sf /proc/$$/fd/1 /var/log/stdout + service cron start + if [[ -n "$SPOTWEB_CRON_RETRIEVE" ]]; then + echo "$SPOTWEB_CRON_RETRIEVE su -l www-data -s /usr/bin/php /var/www/spotweb/retrieve.php >/var/log/stdout 2>&1" > /etc/crontab + fi + if [[ -n "$SPOTWEB_CRON_CACHE_CHECK" ]]; then + echo "$SPOTWEB_CRON_CACHE_CHECK su -l www-data -s /usr/bin/php /var/www/spotweb/bin/check-cache.php >/var/log/stdout 2>&1" >> /etc/crontab + fi + crontab /etc/crontab +fi + # Run database update /usr/bin/php /var/www/spotweb/bin/upgrade-db.php >/dev/null 2>&1 @@ -41,4 +53,4 @@ rm -rf /run/apache2/apache2.pid # Enabling PHP mod rewrite /usr/sbin/a2enmod rewrite && /etc/init.d/apache2 restart -tail -F /var/log/apache2/* +tail -F /var/log/apache2/* /dev/stdout /dev/stderr