Guest post by @morph027
If you’re using the fantastic Nextcloud and like to feel comfortable browsing all your auto-uploaded photos like once upon a time you did in some proprietary Picasa or so, you can benefit from the Preview Generator, which will take care of pre-rendering the thumbnails. This means faster, smoother scrolling and previewing your images, both in your browser and on mobile devices!
As it states you must add some cron magic to get it working and the Nextcloud folks asked for a tutorial, here’s how to do it with cron or (my preference) with systemd timers.
- we need to setup the job as the system user running Nextcloud (e.g.
httpd, … – depends on your distribution). You can find out by looking at the owner of the nextcloud files using
- we need to use the absolut path to the
- we need to use the absolut path to Nextclouds
occfile, depends in which folder your Nextcloud has been installed (e.g.
Add or create a new cronjob for the Nextcloud user:
crontab -e -u www-data
Using your favourite editor, add something like this, which will run the job at 04:00:
0 4 * * * /usr/bin/php -f /var/www/nextcloud/occ preview:pre-generate
Systemd also has the possibility to run specific tasks at specific times or events. called Timers. You need to create 2 unit files:
[Unit] Description=Nextcloud Preview Generator [Service] Type=oneshot User=www-data ExecStart=/usr/bin/php -f /var/www/nextcloud/occ preview:pre-generate [Install] WantedBy=basic.target
[Unit] Description=Run Nextcloud Preview Generator daily at 04:00 [Timer] OnCalendar=*-*-* 4:00:00 Persistent=true [Install] WantedBy=timers.target
- systemd reload
- activate the timer
systemctl enable nextcloud-preview-generator.timer
- start the timer
systemctl start nextcloud-preview-generator.timer