Upgrading my NextCloud to use Redis and fix Cron

I’ve had NextCloud installed for a while now and part of my core infrastructure, however it hasn’t been running well. I’ve always had issues getting the cron jobs to run and occasional problems with file locking in it. Recently the file locking problems got worse and I finally decided to fix both issues in one hopefully straightforward action.

My NextCloud is probably not the most common setup around, but these changes should be pretty easy to incorporate for anyone running it. My setup runs the official NextCloud container on Unraid with my mariadb instance running in a VM. I’ll be updating my NextCloud on Unraid to run a docker compose file to run a second NextCloud container for cron, and a redis container.

The volume paths and ports were determined by my previous NextCloud container settings in Unraid, I just moved them into the compose file, then added the cron and redis services. The cron service uses the same volume mounts as NextCloud (so if you have different mounts for your container, just use those same ones for this new cron container), while the redis container is just a default redis setup with basic configuration.

services:
cron:
image: nextcloud:apache
container_name: nextcloud-cron
restart: always
volumes:
- /mnt/user/Settings/NextCloud/html/:/var/www/html:rw
- /mnt/user/Settings/NextCloud/db/:/var/lib/mysql:rw
entrypoint: /cron.sh
nextcloud:
container_name: nextcloud-prime
image: nextcloud
volumes:
- /mnt/user/Settings/NextCloud/html/:/var/www/html/:rw
- /mnt/user/Settings/NextCloud/db/:/var/lib/mysql:rw
ports:
- 10001:80
redis:
container_name: nextcloud_redis
image: redis
restart: always

Once I had the docker compose file setup, I made the changes to the NextCloud configuration (config.php) to enable redis caching. I updated locking and distributed caching to use redis and left local caching to apcu (as suggested in the NextCloud guides.

  'memcache.local' => '\\OC\\Memcache\\APCu',
'memcache.locking' => '\\OC\\Memcache\\Redis',
'memcache.distributed' => '\\OC\\Memcache\\Redis',
'redis' =>
array (
'host' => 'redis',
'port' => 6379,
),

After that, I started up the stack and checked everything out. There were a few hiccups at the start, my first login attempt failed but my second one succeeded and then everything started looking good. I even got my first sign that the cron container was working!

Cron Jobs Running!

We’ll see with time if this fixes some of the issues I’ve had with my nextcloud install or if it causes other problems, but for now I’ll consider it a resounding win.

Leave a Reply