Add option to use cron within container

This commit is contained in:
B 2018-03-17 00:08:35 +01:00
parent 2461b575c1
commit b1c66167ee
3 changed files with 34 additions and 13 deletions

View File

@ -3,8 +3,8 @@ MAINTAINER Jeroen Geusebroek <me@jeroengeusebroek.nl>
ENV DEBIAN_FRONTEND="noninteractive" \ ENV DEBIAN_FRONTEND="noninteractive" \
TERM="xterm" \ 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" \ 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='2017-11-09' REFRESHED_AT='2018-03-16'
RUN echo "force-unsafe-io" > /etc/dpkg/dpkg.cfg.d/02apt-speedup &&\ 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 && \ echo "Acquire::http {No-Cache=True;};" > /etc/apt/apt.conf.d/no-cache && \

View File

@ -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. You should now be able to reach the spotweb interface on port 80.
### Automatic retreiving of new spots ### Automatic retrieval of new spots
To enable automatic retrieval, you need to setup a cronjob on either the docker host or within the container.
To enable automatic retreiving, you need to setup a cronjob on the docker host. #### 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 */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. 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 ### Updates
The container will try to auto-update the database when a newer version is released. The container will try to auto-update the database when a newer version is released.
### Environment variables ### Environment variables
| Variable | Function |
* `TZ` The timezone the server is running in. Defaults to `Europe/Amsterdam`. | --- | --- |
* `SPOTWEB_DB_TYPE` Database type. Use `pdo_mysql` for MySQL. | `TZ` | The timezone the server is running in. Defaults to `Europe/Amsterdam`. |
* `SPOTWEB_DB_HOST` The hostname / IP of the database server. | `SPOTWEB_DB_TYPE` | Database type. Use `pdo_mysql` for MySQL. |
* `SPOTWEB_DB_NAME` The database used for spotweb. | `SPOTWEB_DB_HOST` | The hostname / IP of the database server. |
* `SPOTWEB_DB_USER` The database server username. | `SPOTWEB_DB_NAME` | The database used for spotweb. |
* `SPOTWEB_DB_PASS` The database server password. | `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 ## License

View File

@ -32,6 +32,18 @@ TZ=${TZ:-"Europe/Amsterdam"}
echo -e "Setting (PHP) time zone to ${TZ}\n" echo -e "Setting (PHP) time zone to ${TZ}\n"
sed -i "s#^;date.timezone =.*#date.timezone = ${TZ}#g" /etc/php/7.*/*/php.ini 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 # Run database update
/usr/bin/php /var/www/spotweb/bin/upgrade-db.php >/dev/null 2>&1 /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 # Enabling PHP mod rewrite
/usr/sbin/a2enmod rewrite && /etc/init.d/apache2 restart /usr/sbin/a2enmod rewrite && /etc/init.d/apache2 restart
tail -F /var/log/apache2/* tail -F /var/log/apache2/* /dev/stdout /dev/stderr