Clarity on the crontab settings for the preview generator app

So as of 11 we can do background thumbnail generation through this app:
https://apps.nextcloud.com/apps/previewgenerator

The app states the following cron entry is required under the web user:
./occ preview:pre-generate

Could I please request some clarity on how a cronjob should look? Hereā€™s my initial attempt, though I feel itā€™s wrong:
*/30 * * * * php ./occ preview:pre-generate

NC is installed under /var/www/html/ and normally I CD to the dir before running OCC commands, hence my query.

Ah nice, finally :smile:!

I just reviewed my crontab and found:
*/15 * * * * /usr/bin/php -f /var/www/owncloud/cron.php
for my cronjob. So as here I guess the path to your nextcloud instance is necessary, the one to php should be not in most cases ;).

Hmm I donā€™t know what the "-f" does. I just got it from admin manual here.

My preview cronjob now looks like this:
*/60 * * * * /usr/bin/php /var/www/owncloud/occ preview:pre-generate

Will see what happensā€¦

ā‚¬: Ah, i guess the "-f" stands for ā€œfileā€, so is necessary for the following path/file to be used with the php command as wanted.

1 Like

Perfect! PHP is an environmental variable on my system, so this in my www-data crontab works:

*/30 * * * * php /var/www/html/occ preview:pre-generate

Verified by first running sudo -u www-data php /var/www/html/occ preview:pre-generate

Thank you for that :slight_smile:

2 Likes

Just checked what the php command gives for help:

Usage: php [options] [-f] <file> [--] [args...]
   php [options] -r <code> [--] [args...]
   php [options] [-B <begin_code>] -R <code> [-E <end_code>] [--] [args...]
   php [options] [-B <begin_code>] -F <file> [-E <end_code>] [--] [args...]
   php [options] -S <addr>:<port> [-t docroot]
   php [options] -- [args...]
   php [options] -a

  -a               Run interactively
  -c <path>|<file> Look for php.ini file in this directory
  -n               No configuration (ini) files will be used
  -d foo[=bar]     Define INI entry foo with value 'bar'
  -e               Generate extended information for debugger/profiler
  -f <file>        Parse and execute <file>.
...

So "-f" should be necessary for the command to work properly. Or maybe it is smart enough to use the argument as file, if nothing else is given? Did you check if the preview generation worked for you without -f?

Without -f it works fine, similar to php /var/www/html/occ files:scan --all works fine without -f also.
Presumably -f is used in the above due to it being a php file rather than whatever occ is?

occ:

#!/usr/bin/env php
<?php
/**
 * Copyright (c) 2013 Thomas M  ller <thomas.mueller@tmit.eu>
 * This file is licensed under the Affero General Public License version 3 or
 * later.
 * See the COPYING-README file.
 */

//$argv = $_SERVER['argv'];
require_once __DIR__ . '/console.php';

Itā€™s also some kind of php file. I tried sudo -u www-data php /var/www/owncloud/cron.php to verify and the admin panel shows, that the nextcloud cron job was successfully done. So "-f" doesnā€™t seem to be needed or is applied automatically :smiley: .

Now preview/thumb generation for the gallery app would be nice to make the holiday slide show on my rpi a little more fun ;).

Gallery on the rpi was the leading driver for this app I think :stuck_out_tongue:
Good to know -f is redundant. Perhaps a relic from OC that wasnā€™t removed.

I cannot get over how fast NC is since 11, really like it.

I have installed this preview generator app, but it doesnā€™t seem to do anythingā€¦ and is poorly documented, if not at allā€¦ :grimacing:

My cron job
*/30 * * * * php -f /var/www/nextcloud/occ preview:pre-generate
runs without error under the user www-data. (checked in my syslog)

I have remarked that in the ā€œ/var/www/nextcloud/apps/previewgenerator/lib/Commandā€ directory, there is 3 possible command :
DeleteOld
Generate
PreGenerate

Is the differences in capital letters and writing of ā€œpre-generateā€ in the cron and ā€œPreGenerateā€ in the file could be the problem ?

Also, my /var/www/nextcloud/apps/previewgenerator/appinfo/database.xml seems not updated and the oc_preview_generation table in the nextcloud database emptyā€¦

I also recognized, that there are no new previews generated for my nextcloud, where the cronjob is done successfully every hour.

But the command is correct. If you try sudo -u www-data php /var/www/owncloud/oc preview:PreGenerate you will get

  [Symfony\Component\Console\Exception\CommandNotFoundException]
  Command "preview:PreGenerate" is not defined.
  Did you mean one of these?
      preview:pre-generate
      preview:generate-all
      preview:delete_old

I donā€™t know where these commands are defined, but they are. I try preview:generate-all at the moment. It takes time, so seems to be promising. Maybe pre-generate does only work for new files or something to not always need to scan the wohl data directories.

preview:generate-all is still working while i am typing. I will give you results, when itā€™s done :slight_smile: .

Hi @MichaIng !
Thank you for your kind respone :slight_smile:

I will try [quote=ā€œMichaIng, post:9, topic:6144ā€]
preview:generate-all
[/quote]

and report back here.

Ping @rullzer because I see his name all over git :slight_smile:

So the app clearly needs more documentation :wink:

Not really. More my wife sharing several gigabytes of family pictures and even on decent hardware redering this on demand is just suboptimal :stuck_out_tongue:

That are just the file names :slight_smile:

So to explain a bit what the commands do:

preview:delete_old - Will delete your old preview folder. This is no longer used. Note that there is a background job that will do it in time from the server. But this was just for me to quickly get it done.

preview:generate-all - Will loop over all files and try to generate previews. This can take a long time just to traverse if you have a lot of files. You should only have to run this once.

preview:pre-generate - As long as the app is enabled it will listen to new / edited files. It stores those files in a list and then when this command is run it will try to create previews for those files.

So long story short:

Run ./occ preview:generate-all once
Run ./occ preview:pre-generate in a cronjob after that.

5 Likes

O.K. Thanks !
(my /occ preview:generate-all is still runningā€¦ ) :slight_smile:

:joy: I stand corrected. The pi crowd were touting it as their answer to all our problems too mind :wink:

Thank you for clarifying :smiley:

Thanks for the explanation @rullzer.

As the app is just one week old, we will accept missing documentation :smiley: .

To get this clear:

  • This app is (just) for the preview generation of the files app/nextcloud itself, if 'enable_previews' => true, and has for the first nothing to do with the thumbnails of the gallery app, right?
  • There is some command planned for the gallery app, but not yet implemented: https://github.com/nextcloud/gallery/wiki/Create-Thumbnails
  • Or is there some merge of the previews and the thumbs system planned?

@preview:generate-all: Maybe there could be some hint after app installation to run this one, maybe even through the nc web interface and then just run in the background?

2 Likes

So I made the mistake of running the generate-all command on a putty session with 70GB of files before I read the old thumbnail directory is no longer being used. So much for it ignoring existing thumbnails then? :stuck_out_tongue:[quote=ā€œMichaIng, post:16, topic:6144ā€]
This app is (just) for the preview generation of the files app/nextcloud itself, if ā€˜enable_previewsā€™ => true, and has for the first nothing to do with the thumbnails of the gallery app, right?
[/quote]

Where did you see mention of 'enable_previews' => 'true'?

I copied the files into the app-folder and set the right credentials.
But when i try to execute:

sudo -u www-data php /var/www/html/occ preview:pre-generate

i get this error:

[Symfony\Component\Console\Exception\CommandNotFoundException]
There are no commands defined in the ā€œpreviewā€ namespace.
What is my mistake?

https://docs.nextcloud.com/server/11/admin_manual/configuration_server/config_sample_php_parameters.html#previews

But it is enabled by default, mentioned here.

Me too, but as I already had problems with broken ssh connections I use screen. This enables you to set sessions into the background and resume lost ones :slight_smile: .

I always usually use screen.

When I remember.

Sometimes.

:upside_down: