Clarity on the crontab settings for the preview generator app


#1

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.


Error while generating thumbnails with previewgenerator
Nextcloud Box zu verkaufen
Why dl the images to device?
Nextcloud box [official snap] stops working when accessing huge directories!
#2

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.


#3

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:


#4

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?


#5

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?


#6

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 ;).


#7

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.


#8

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…


#9

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: .


#10

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.


#11

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


#12

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:


#13

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.


#14

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


#15

: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:


#16

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?


#17

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'?


#18

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?


#19

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: .


#20

I always usually use screen.

When I remember.

Sometimes.

:upside_down: