cron in Docker image (#1871)

* cron in Docker image

https://github.com/FreshRSS/FreshRSS/issues/1869

* Fix cron CMD

* Minor readme

* Docker run d instead of dit

There should not be a need for STDIN or TTY

* Minor sed param
This commit is contained in:
Alexandre Alapetite authored and GitHub committed 2018-04-26 12:00:14 +02:00
1 parent d454e90d29
commit 4381117a19
3 files changed
+66 -12

No files matched your search

+7 -3
View File
@@ -15,8 +15,12 @@ WORKDIR ${FRESHRSS_ROOT}
COPY . ${FRESHRSS_ROOT}
COPY ./Docker/*.Apache.conf /etc/apache2/conf.d/
RUN echo "17,37 * * * * php ${FRESHRSS_ROOT}/app/actualize_script.php 2>&1 | tee /tmp/FreshRSS.log" >> \
/var/spool/cron/crontabs/root
ENV CRON_MIN ''
ENTRYPOINT ["./Docker/entrypoint.sh"]
EXPOSE 80
CMD php -f ./cli/prepare.php > /dev/null && \
chown -R :www-data ${FRESHRSS_ROOT} && \
chmod -R g+r ${FRESHRSS_ROOT} && chmod -R g+w ${FRESHRSS_ROOT}/data/ && \
CMD ([ -z "$CRON_MIN" ] || crond -d 6) && \
exec httpd -D FOREGROUND
+47 -9
View File
@@ -26,7 +26,7 @@ sudo docker build --tag freshrss/freshrss -f Docker/Dockerfile .
## Run FreshRSS
Example using SQLite, and exposing FreshRSS on port 8080. You may have to adapt the network parameters to fit your needs.
Example using SQLite, built-in cron, and exposing FreshRSS on port 8080. You may have to adapt the parameters to fit your needs.
```sh
# You can optionally run from the directory containing the FreshRSS source code:
@@ -35,8 +35,9 @@ cd ./FreshRSS/
# The data will be saved on the host in `./data/`
mkdir -p ./data/
sudo docker run -dit --restart unless-stopped --log-opt max-size=10m \
sudo docker run -d --restart unless-stopped --log-opt max-size=10m \
-v $(pwd)/data:/var/www/FreshRSS/data \
-e 'CRON_MIN=5,35' \
-p 8080:80 \
--name freshrss freshrss/freshrss
```
@@ -50,8 +51,9 @@ See https://hub.docker.com/_/mysql/
```sh
sudo docker run -d -v /path/to/mysql-data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=rootpass -e MYSQL_DATABASE=freshrss -e MYSQL_USER=freshrss -e MYSQL_PASSWORD=pass --name mysql mysql
sudo docker run -dit --restart unless-stopped --log-opt max-size=10m \
sudo docker run -d --restart unless-stopped --log-opt max-size=10m \
-v $(pwd)/data:/var/www/FreshRSS/data \
-e 'CRON_MIN=17,47' \
--link mysql -p 8080:80 \
--name freshrss freshrss/freshrss
```
@@ -61,8 +63,9 @@ See https://hub.docker.com/_/postgres/
```sh
sudo docker run -d -v /path/to/pgsql-data:/var/lib/postgresql/data -e POSTGRES_DB=freshrss -e POSTGRES_USER=freshrss -e POSTGRES_PASSWORD=pass --name postgres postgres
sudo docker run -dit --restart unless-stopped --log-opt max-size=10m \
sudo docker run -d --restart unless-stopped --log-opt max-size=10m \
-v $(pwd)/data:/var/www/FreshRSS/data \
-e 'CRON_MIN=23,53' \
--link postgres -p 8080:80 \
--name freshrss freshrss/freshrss
```
@@ -89,16 +92,50 @@ sudo docker exec --user apache -it freshrss php ./cli/list-users.php
See the [CLI documentation](../cli/) for all the other commands.
### Cron job to refresh feeds
Set a cron job up on your host machine, calling the `actualize_script.php` inside the FreshRSS Docker instance.
## Cron job to automatically refresh feeds
We recommend a refresh rate of about twice per hour (see *WebSub* / *PubSubHubbub* for real-time updates).
There is no less than 3 options. Pick a single one.
#### Example on Debian / Ubuntu
Create `/etc/cron.d/FreshRSS` with:
### Option 1) Cron inside the FreshRSS Docker image
Easiest, built-in solution, also used in the examples above
(but your Docker instance will have a second process in the background, without monitoring).
Just pass the environment variable `CRON_MIN` to your `docker run` command,
containing a valid cron minute definition such as `'13,43'` (recommended) or `'*/20'`.
Not passing the `CRON_MIN` environment variable – or setting it to empty string – will disable the cron daemon.
```sh
sudo docker run -d --restart unless-stopped --log-opt max-size=10m \
-v $(pwd)/data:/var/www/FreshRSS/data \
-e 'CRON_MIN=13,43' \
-p 8080:80 \
--name freshrss freshrss/freshrss
```
### Option 2) Cron on the host machine
Traditional solution.
Set a cron job up on your host machine, calling the `actualize_script.php` inside the FreshRSS Docker instance.
Remember not pass the `CRON_MIN` environment variable to your Docker run, to avoid running the built-in cron daemon of option 1.
Example on Debian / Ubuntu: Create `/etc/cron.d/FreshRSS` with:
```
7,37 * * * * root docker exec --user apache -it freshrss php ./app/actualize_script.php > /tmp/FreshRSS.log 2>&1
```
### Option 3) Cron as another instance of the same FreshRSS Docker image
For advanced users. Offers good logging and monitoring with auto-restart on failure.
Watch out to use the same run parameters than in your main FreshRSS instance, for database, networking, and file system.
See cron option 1 for customising the cron schedule.
```sh
sudo docker run -d --restart unless-stopped --log-opt max-size=10m \
-v $(pwd)/data:/var/www/FreshRSS/data \
-e 'CRON_MIN=17,37' \
--name freshrss_cron freshrss/freshrss \
crond -f -d 6
```
## Debugging
```sh
@@ -115,5 +152,6 @@ ls /var/www/FreshRSS/
## Deployment in production
Use a reverse proxy on your host server, such as [Træfik](https://traefik.io/) or [nginx](https://docs.nginx.com/nginx/admin-guide/web-server/reverse-proxy/),
Use a reverse proxy on your host server, such as [Træfik](https://traefik.io/)
or [nginx](https://docs.nginx.com/nginx/admin-guide/web-server/reverse-proxy/),
with HTTPS, for instance using [Let’s Encrypt](https://letsencrypt.org/).
+12
View File
@@ -0,0 +1,12 @@
#!/bin/sh
php -f ./cli/prepare.php > /dev/null
chown -R :www-data .
chmod -R g+r . && chmod -R g+w ./data/
if [ -n "$CRON_MIN" ]; then
sed -r -i "/FreshRSS/s/^[^ ]+ /$CRON_MIN /" /var/spool/cron/crontabs/root
fi
exec "$@"