Nextcloud Docker - Cron intervals


i host multiple nextcloud instances on a docker swarm cluster. All cron services are constrained to a single node. I’m looking for a way to have them run at different intervals, because it hits the CPU of the node pretty hard as they all run at the same time.

Is there an option to do so? Or any other way to do it in larger deployments?

This is an example how i am using it currently:

    image: nextcloud:28
      - /nfs/12/nextcloud:/var/www/html
    entrypoint: /
      - swarm_net

AFAIK this is not possible with cron, respectively you would have to set up 12*24 induvidual cron jobs…

01 00 * * * ...
06 00 * * * ...
11 00 * * * ...


Maybe with systemd timers…? Not sure…

Well i don’t think that is a scalable and realiable way in a docker swarm enovirenment. I hoped for some envoirenment variable for the container that may can affect the interval. But yea it does not seem like there is any feature like that

You could change the cron entry within the Dockerfile if you wish to customize it: docker/28/apache/Dockerfile at 747a3f8414e3fad96c44df47b4539d2131523cc9 · nextcloud/docker · GitHub

Or, perhaps easier, you could mount a replacement crontab in /var/spool/cron/crontabs/www-data.

A couple other ideas:

All cron services are constrained to a single node.

Is there a reason you have all your cron for different Nextcloud instances limited to a single one of your nodes?

Intresting ideas! Thank you i’ll have a look into it.

I encountered the issue that when by chance to many are running on one node it affects all other containers aswell, which makes the instances unusuable for the time cron is running if on the same node a db or app container is running. Constraning them to one node resulted in huge load avgs. when the cron jobs run all at once, but it does not affect the instances themself

Yeah there are probably ways to set up multiple/induvidual crontabs for each container/cluster node, see the suggestions made by @jtr for that, but this does not solve the more fundamental issue with Cron, which is that it can’t stagger intervals.

However, now that I think about it again, it should be possible to overcome this limitation with the following simple trick:

node 1:

*/5 * * * * php -f /var/www/html/nextcloud/cron.php

node 2:

*/5 * * * * sleep 60 && php -f /var/www/html/nextcloud/cron.php

node 3:

*/5 * * * * sleep 120 && php -f /var/www/html/nextcloud/cron.php


The following should work as well:

1,6,11,16,21,26,31,36,41,46,51,56 * * * *

You could also try the following, but it seems to be a non-standard one, so it’s not guaranteed to work:

1/5 * * * *

Source: - The cron schedule expression generator :wink:

1 Like