Nextcloud Preview Generator Cron Job

Hello, based on previous things on the old forums, I modified a command to run as a Cron Job which can be added from the GUI to run as root and trigger the Preview Generator App for Nextcloud (from the official TrueNAS catalog):

k3s kubectl exec -n ix-nextcloud -c nextcloud -i $(k3s kubectl get -o wide -n ix-nextcloud pods | grep 'nextcloud-' | grep -vE '(cronjob|postgres)' | awk '{ print $1; }') -- su -s /bin/bash www-data -c 'php -d memory_limit=-1 -f /var/www/html/occ preview:pre-generate'

I am posting because I had this problem and I found no working solution so maybe this will help someone, if you have a more elegant solution, I’d be glad to see something smarter.

I was looking to somehow leverage the cronjob container that from what I noticed is used only to run var/www/html/cron.php

Maybe cron.php could be modified to also run Preview Generator.

Not sure if I’m getting what you’re putting down, but I just add this to the end of my config.php file


 'enable_previews' => true,
  'enabledPreviewProviders' => 
  array (
    0 => 'OC\\Preview\\Movie',
    1 => 'OC\\Preview\\PNG',
    2 => 'OC\\Preview\\JPEG',
    3 => 'OC\\Preview\\GIF',
    4 => 'OC\\Preview\\BMP',
    5 => 'OC\\Preview\\XBitmap',
    6 => 'OC\\Preview\\MP3',
    7 => 'OC\\Preview\\MP4',
    8 => 'OC\\Preview\\TXT',
    9 => 'OC\\Preview\\MarkDown',
    10 => 'OC\\Preview\\PDF',
  ),

Yes, indeed, I also have that. But Preview Generator is used to preemptively create thumbnails before you actually try to go look at the photos/videos so it does not stutter/fail to load thumbnails when you do.

If my own documentation is correct, I had used

sudo docker exec --user www-data -it nextcloud-app-1 php occ preview:generate-all -vvv

to generate all previews and then added

*/10 * * * * docker exec --user www-data --tty nextcloud-app-1 php occ preview:pre-generate 

as a cronjob.

Basically the same as victor had added to his config:

  'preview_max_x' => '1024',
  'preview_max_y' => '1024',
  'jpeg_quality' => '60',
  'enabledPreviewProviders' =>
  array (
    1 => 'OC\\Preview\\Image',
    2 => 'OC\\Preview\\MarkDown',
    3 => 'OC\\Preview\\MP3',
    4 => 'OC\\Preview\\TXT',
    5 => 'OC\\Preview\\OpenDocument',
    6 => 'OC\\Preview\\Movie',
    7 => 'OC\\Preview\\Krita',
    0 => 'OC\\Preview\\Imaginary',
  ),
  'enable_previews' => true,

I ran it as a docker container inside an ubuntu VM. Modify according to your deployment.

How do you add a cron job in Nextcloud? I’m just getting a “bash: crontab: command not found”

Not sure to which method you are replying. In my case you do not setup the cronjob inside the nextcloud VM but rather on the host.

Not sure what methods there are. So the cronjobs are ran by TrueNAS on behalf of Nextcloud and not by Nextcloud itself? How/where would I edit those?

Basically, in TrueNAS you go to System Settings - Advanced - Cron Jobs and you define a new cron job that issues a command inside the nextcloud pod as the user www-data every x minutes/hours. In the current version my command is:

k3s kubectl exec -n ix-nextcloud -c nextcloud -i $(k3s kubectl get -o wide -n ix-nextcloud pods | grep ‘nextcloud-’ | grep -vE ‘(redis|postgres|nginx)’ | awk ‘{ print $1; }’) – su -s /bin/bash www-data -c ‘php -d memory_limit=-1 -f /var/www/html/occ preview:pre-generate’

The problem I have is that I think this isn’t quite that elegant because to issue the command in the right pod, you need to exclude the others and the names of the pods can change from version to version and this nextcloud implementation already has cronjob functionality.

1 Like