Iâm running my nextclud instance via docker (compose file adopted from here). There is already a container running /cron.sh, which starts a busybox with cron, which starts cron.php every 5 minutes.
Now my question is: how to do i add additional tasks? (i.e. ./occ fulltextsearch:index)
I do not want to rebuild the nextcloud image just for adding a cron task. And i do not want to use the host for managing tasks in the container (host systemd oder host cron)
as far as i can tell the crontab entry is done here. So as you can see, inside the container the file /var/spool/cron/crontabs/www-data is used and it usually contains one line like */5 * * * * php -f /var/www/html/cron.php for executing the cron.php every 5 minutes. If you want to do any additional cron tasks you could mount a custom crontab file and add any desired lines. A snippet of the corresponding docker-compose file could look like this:
could you please show an example on how to add a task to this script?
I could not find any examples on how to use this cron.sh. It seems to be a normal bash script but then how do you add a task e.g. for preview generator (occ preview:pre-generate)? I do not understand the âexec busybox crondâ line already in that file, why do you need exec?
Thanks in advance!
use this script as cronjob. do not try to enable cron inside the contaier. inside any container.
so you just add docker exec --user www-data nextcloud php occ preview:pre-generate assuming that your container name is nextcloud and www-data the web server user.
just saying.
this is a way to enable crond inside a container.
exec executes everything you use as the first argument. e.g. a shell skript has no +x bit. exec that-skript is your friend. and busybox crond just starts the cron daemon inside the container.
nevertheless after i wrote the comment above i found this article in german Projekt Rootserver - geschlossen it says: donât do it with busybox. not a good idea. the authors advice: use the host cron + docker exec
I just migrated my nextcloud to a docker setup on a NAS as host system. First I used the second container solution but now switched to your proposal of using a script in the hostâs cron service.
Yet I have two questions that maybe you or s.o. else have answers to:
It is a tiny setup for max 5 users mainly using the cloud during daytime. So Iâd like to let my NAS sleep during nighttime. A 24/7 every-15-minutes cronjob would prevent this, right? Is there any risk if I pause the cronjob during night hours ?
yesterday I was fixing my cron job, cos my deployment is running in docker-compose statement, so yes, as you said, I created a cronjob into the host to call a simple:
in fact, from my beginner understanding from all about containers, It should be better run it on this mode. We should leaves each container running its own service.
Sorry to dig the topic up, but I recently had conflicts with cron tasks: can anyone please confirm that the above cronjob docker exec -t -u www-data nextcloud-app php -f /var/www/html/cron.php is created for the www-data user (crontab -u www-data -e) and not for the root user?
@jlgarnier: if you run cron from the host, you wonât have the cron log in the container, but the result of the command should be visible using docker logs, since cron.sh uses /dev/stdout.
But I donât understand why this isnât âfixedâ in some way:
The default is AJAX, which is the âleast reliableâ according to the documentation (why is this the default, then?)
In the basic settings I can select cron, but this wonât activate cron (why make it an option there? Does this do anything?)
The preferred solution, when using Docker, is to use crontab on the host (doesnât this defy the point of Docker? Whatâs the problem with using cron in a container?)
I fully agree and did the same analysis: why is Ajax the default setting and why doesnât the Cron option just set the appropriate crontab?
By the way, I think the cron working was disturbed by the âlistmanâ plugin, which was looking for an unknown file and crashed during the task⌠Iâve disabled the plugin, hope this will fix the whole stuff!
You can use the docker hostâs cron to invoke cron.php in the container every 5 minutes. Simple and effective. Iâve done this on several of my installations and never had a problem with it.
Iâve used the official supervisord setup too and that also works.