December 28, 2021 | 21:25

Updating Feeds for Nextcloud News app on rootless Docker

I recently installed the News app on my Nextcloud instance. This turned out to be a bit tricky, since my Nextcloud installation runs on rootless Docker. However, here are the steps I went through.

I found a command that successfully calls the cron.php script, when executed on the host system in the context of the (non-root) docker user:

$ docker exec -u www-data nextcloud-app php -f /var/www/html/cron.php

You can verify that the background jobs have been executed, by checking the green patch and the time of last run next to the Background Jobs heading of the following URL:

<YOUR_NEXTCLOUD_URL>/settings/admin

By now, we know, that we can trigger the run of Nextcloud’s cron.php script from the host system. The next step, of course, is to set up a cron job on the host system by running crontab -e as the docker user, which executes our command periodically. This could look like the following for every five minutes:

*/5  *  *  *  * docker exec -u www-data nextcloud-app php -f /var/www/html/cron.php

However, this didn’t work for me and a few short tests showed, that no docker command was executed at all. Some googling revealed, that cron jobs run in its own environment, hence the important DOCKER_HOST environment variable wasn’t set as is needed for rootless docker. Knowing that, I created a script cron.sh (replace 1001 by the uid of the docker user):

#!/bin/bash
export DOCKER_HOST=unix:///run/user/1001/docker.sock
docker exec -u www-data nextcloud-app php -f /var/www/html/cron.php

And inserted the following in crontab:

*/5  *  *  *  * /path/to/cron.sh

That did the trick for me.

In order to test subscriptions within the News app, I subscribed to http://lorem-rss.herokuapp.com/feed (one new feed every minute) and changed the default update interval from 3600 to 60 seconds (something below 5 minutes to hit the next cron run) within the administration settings of the News app (<YOUR_NEXTCLOUD_URL>/settings/admin/news).

© Pavel Pi 2021

Powered by Hugo & Kiss'Em.