Cron in nextcloud Scale Cobia Beta.1

sretalla

Powered by Neutrality
Moderator
Joined
Jan 1, 2016
Messages
9,700
So that's telling you why you can't run it... there's no PATH variable, so you need to specify the full path to php also.

But as is already mentioned by @sfatula the cron service isn't there in the container, so what you're trying to run won't work even when you get it to run.
 

Isma

Contributor
Joined
Apr 29, 2020
Messages
100
So that's telling you why you can't run it... there's no PATH variable, so you need to specify the full path to php also.

But as is already mentioned by @sfatula the cron service isn't there in the container, so what you're trying to run won't work even when you get it to run.


Could you help me with that? because before if I executed in the same path and it was when passing to kuber
 

sretalla

Powered by Neutrality
Moderator
Joined
Jan 1, 2016
Messages
9,700
You'll need to work out where php is in the container.

You can go to the shell of the container and type which php (assuming the shell gets a good path), or maybe you'll need to find it with find / -name php
 

Isma

Contributor
Joined
Apr 29, 2020
Messages
100
You'll need to work out where php is in the container.

You can go to the shell of the container and type which php (assuming the shell gets a good path), or maybe you'll need to find it with find / -name php
1692702313947.png



that works?


find / -name php
It didn't work, the shell stayed blank


-------------


1692702838209.png
 
Last edited:

sretalla

Powered by Neutrality
Moderator
Joined
Jan 1, 2016
Messages
9,700
So there you have it...

k3s kubectl get -o name -n ix-nextcloud pods | xargs -I{} k3s kubectl exec -n ix-nextcloud --stdin --tty {} -- /usr/local/bin/php /nextclouddatos/html/cron.php

But as mentioned, this is expected not to work since cron isn't in the container.
 
Last edited:

Isma

Contributor
Joined
Apr 29, 2020
Messages
100
Así que ahí lo tienes...

k3s kubectl get -o nombre -n ix-nextcloud pods | xargs -I{} k3s kubectl exec -n ix-nextcloud --stdin --tty {} -- /usr/local/bin/php /nextclouddatos/html/cron.php

Pero como se mencionó, se espera que esto no funcione ya que cron no está en el contenedor.

it is correct it gives error


So what I don't understand is having a cron call option inside the container that cannot be used
 

Isma

Contributor
Joined
Apr 29, 2020
Messages
100
this works


k3s kubectl get -o name -n ix-nextcloud pods | xargs -I{} k3s kubectl exec -n ix-nextcloud --stdin --tty {} -- /usr/local/bin/php cron.php
 

sfatula

Guru
Joined
Jul 5, 2022
Messages
608
So there you have it...

k3s kubectl get -o name -n ix-nextcloud pods | xargs -I{} k3s kubectl exec -n ix-nextcloud --stdin --tty {} -- /usr/local/bin/php /nextclouddatos/html/cron.php

But as mentioned, this is expected not to work since cron isn't in the container.
That is expected to work actually. What is not expected to work within the container is a an actual cron job to run that command. The php program named cron.php does not run or use cron. It is merely what one would normally run every few minutes in a cron job. Since nextcloud has no crond running, you have to run it somehow and one somehow is externally.

Just want to make it clear how nextcloud works.
 
Last edited:

sretalla

Powered by Neutrality
Moderator
Joined
Jan 1, 2016
Messages
9,700
OK that's clear, it seems that the final version of the command worked, so all good.
 

sfatula

Guru
Joined
Jul 5, 2022
Messages
608
But really I consider the nextcloud app as "broken". IX needs to either add cron to the container via supervisord as suggested in the examples section of nextcloud docker source, or, make a cron app. Leaving people to fend for themselves doesn't seem like the way to go. You really need to run the cron task to use nextcloud effectively. I guess one might consider it an "enhancement" request but really I consider it a bug myself.
 

sretalla

Powered by Neutrality
Moderator
Joined
Jan 1, 2016
Messages
9,700

sfatula

Guru
Joined
Jul 5, 2022
Messages
608
Issue created:


Thanks!

Edit, looks like this has already been handled in 23.10:

 

Isma

Contributor
Joined
Apr 29, 2020
Messages
100
Issue created:


Thanks!

Edit, looks like this has already been handled in 23.10:

thx
 
Joined
Oct 13, 2022
Messages
7
Hello, I understand that there were modifications and I don't know how to change docker to kuber but I would like to see how to configure the cron for nextcloud for this new version of scale beta.1

In scale 22 use this reference

But now... the command "docker ps | grep nextcloud" does not work for me, when updating I would like to know what the new one would be and how to configure the new cron for nextcloud

Scale 22
docker exec --user root `docker ps | grep "nextcloud_nextcloud" | awk '{ print $1; }'` php cron.php
View attachment 69459



Scale 23
?¿???
View attachment 69458
Upgrading TrueNAS Scale from 22.12.4.2 Bluefin to 23.10 Cobia gave me the same issue.

I was able to solve it. Maybe what I did can also help you and others.

My TrueNAS Scale cron command for Nextcloud Cron​

Bluefin:
Code:
docker exec --user www-data `docker ps | grep "nextcloud_nextcloud" | awk '{ print $1; }'` php -d memory_limit=-1 -f /var/www/html/cron.php


Cobia:
Code:
k3s kubectl exec -n ix-nextcloud -c nextcloud -i `k3s kubectl get -o wide -n ix-nextcloud pods | grep 'nextcloud-[0-9]' | awk '{ print $1; }'` -- su -s /bin/bash www-data -c 'php -d memory_limit=-1 -f /var/www/html/cron.php'


My TrueNAS Scale cron command for Nextcloud Preview generator​

Bluefin:
Code:
docker exec --user www-data `docker ps | grep "nextcloud_nextcloud" | awk '{ print $1; }'` php -d memory_limit=-1 -f /var/www/html/occ preview:pre-generate


Cobia:
Code:
k3s kubectl exec -n ix-nextcloud -c nextcloud -i `k3s kubectl get -o wide -n ix-nextcloud pods | grep 'nextcloud-[0-9]' | awk '{ print $1; }'` -- su -s /bin/bash www-data -c 'php -d memory_limit=-1 -f /var/www/html/occ preview:pre-generate'


Cobia only: When you want to test your cron command
If you want to test your cron command in the TrueNAS Scale console
change
Code:
-i

to
Code:
-it


The -t option instructs kubectrl exec to use your current TTY console as output. Since cron does not have a TTY console, you omit the -t option in the cron command. If you don't your command will execute but will show an error message "Unable to use a TTY - input is not a terminal or the right kind of file".

Johan
 

Isma

Contributor
Joined
Apr 29, 2020
Messages
100
La actualización de TrueNAS Scale de 22.12.4.2 Bluefin a 23.10 Cobia me dio el mismo problema.

Pude solucionarlo. Quizás lo que hice también pueda ayudarte a ti y a otros.

Mi comando cron TrueNAS Scale para Nextcloud Cron​

Atún rojo:
[CÓDIGO]docker exec --user www-data `docker ps | grep "nextcloud_nextcloud" | awk '{ imprimir $1; }'` php -d límite_memoria=-1 -f /var/www/html/cron.php[/CODE]

cobia:
[CÓDIGO]k3s kubectl exec -n ix-nextcloud -c nextcloud -i `k3s kubectl get -o wide -n ix-nextcloud pods | grep 'siguiente nube-[0-9]' | awk '{ imprimir $1; }'` -- su -s /bin/bash www-data -c 'php -d límite_memoria=-1 -f /var/www/html/cron.php'[/CODE]

Mi comando cron TrueNAS Scale para el generador de vista previa de Nextcloud​

Atún rojo:
[CÓDIGO]docker exec --user www-data `docker ps | grep "nextcloud_nextcloud" | awk '{ imprimir $1; }'` php -d Memory_limit=-1 -f /var/www/html/occ vista previa:pregenerar[/CODE]

cobia:
[CÓDIGO]k3s kubectl exec -n ix-nextcloud -c nextcloud -i `k3s kubectl get -o wide -n ix-nextcloud pods | grep 'siguiente nube-[0-9]' | awk '{ imprimir $1; }'` -- su -s /bin/bash www-data -c 'php -d Memory_limit=-1 -f /var/www/html/occ vista previa:pregenerar'[/CODE]

Solo Cobia: cuando quieras probar tu comando cron
Si desea probar su comando cron en la consola TrueNAS Scale
cambiar
[CÓDIGO]-i[/CÓDIGO]
a
[CÓDIGO]-it[/CÓDIGO]

La opción -t le indica a kubectrl exec que use su consola TTY actual como salida. Como cron no tiene una consola TTY, omite la opción -t en el comando cron. Si no lo hace, su comando se ejecutará pero mostrará un mensaje de error "No se puede usar un TTY: la entrada no es una terminal o el tipo de archivo correcto".

johan
perfect!! I will try it


Thx!
 

Isma

Contributor
Joined
Apr 29, 2020
Messages
100
Upgrading TrueNAS Scale from 22.12.4.2 Bluefin to 23.10 Cobia gave me the same issue.

I was able to solve it. Maybe what I did can also help you and others.

My TrueNAS Scale cron command for Nextcloud Cron​

Bluefin:
Code:
docker exec --user www-data `docker ps | grep "nextcloud_nextcloud" | awk '{ print $1; }'` php -d memory_limit=-1 -f /var/www/html/cron.php


Cobia:
Code:
k3s kubectl exec -n ix-nextcloud -c nextcloud -i `k3s kubectl get -o wide -n ix-nextcloud pods | grep 'nextcloud-[0-9]' | awk '{ print $1; }'` -- su -s /bin/bash www-data -c 'php -d memory_limit=-1 -f /var/www/html/cron.php'


My TrueNAS Scale cron command for Nextcloud Preview generator​

Bluefin:
Code:
docker exec --user www-data `docker ps | grep "nextcloud_nextcloud" | awk '{ print $1; }'` php -d memory_limit=-1 -f /var/www/html/occ preview:pre-generate


Cobia:
Code:
k3s kubectl exec -n ix-nextcloud -c nextcloud -i `k3s kubectl get -o wide -n ix-nextcloud pods | grep 'nextcloud-[0-9]' | awk '{ print $1; }'` -- su -s /bin/bash www-data -c 'php -d memory_limit=-1 -f /var/www/html/occ preview:pre-generate'


Cobia only: When you want to test your cron command
If you want to test your cron command in the TrueNAS Scale console
change
Code:
-i

to
Code:
-it


The -t option instructs kubectrl exec to use your current TTY console as output. Since cron does not have a TTY console, you omit the -t option in the cron command. If you don't your command will execute but will show an error message "Unable to use a TTY - input is not a terminal or the right kind of file".

Johan
Console has to be executed with the user that owns the file config/config.php
Current user id: 33
Owner id of config.php: 3001
command terminated with exit code 1


;(
 

sstruke

Dabbler
Joined
Feb 2, 2017
Messages
37
Upgrading TrueNAS Scale from 22.12.4.2 Bluefin to 23.10 Cobia gave me the same issue.

I was able to solve it. Maybe what I did can also help you and others.

My TrueNAS Scale cron command for Nextcloud Cron​

Bluefin:
Code:
docker exec --user www-data `docker ps | grep "nextcloud_nextcloud" | awk '{ print $1; }'` php -d memory_limit=-1 -f /var/www/html/cron.php


Cobia:
Code:
k3s kubectl exec -n ix-nextcloud -c nextcloud -i `k3s kubectl get -o wide -n ix-nextcloud pods | grep 'nextcloud-[0-9]' | awk '{ print $1; }'` -- su -s /bin/bash www-data -c 'php -d memory_limit=-1 -f /var/www/html/cron.php'


My TrueNAS Scale cron command for Nextcloud Preview generator​

Bluefin:
Code:
docker exec --user www-data `docker ps | grep "nextcloud_nextcloud" | awk '{ print $1; }'` php -d memory_limit=-1 -f /var/www/html/occ preview:pre-generate


Cobia:
Code:
k3s kubectl exec -n ix-nextcloud -c nextcloud -i `k3s kubectl get -o wide -n ix-nextcloud pods | grep 'nextcloud-[0-9]' | awk '{ print $1; }'` -- su -s /bin/bash www-data -c 'php -d memory_limit=-1 -f /var/www/html/occ preview:pre-generate'


Cobia only: When you want to test your cron command
If you want to test your cron command in the TrueNAS Scale console
change
Code:
-i

to
Code:
-it


The -t option instructs kubectrl exec to use your current TTY console as output. Since cron does not have a TTY console, you omit the -t option in the cron command. If you don't your command will execute but will show an error message "Unable to use a TTY - input is not a terminal or the right kind of file".

Johan
Thanks, that's exactly what I was looking for. It works great
 

Isma

Contributor
Joined
Apr 29, 2020
Messages
100
Console has to be executed with the user that owns the file config/config.php
Current user id: 33
Owner id of config.php: 3001
command terminated with exit code 1


;(
I can't run cron anymore, before with errors at least it worked
 
Joined
Dec 20, 2023
Messages
2
I suggest the following:
Code:
NEXTCLOUDPOD=$(k3s kubectl get -o wide -n ix-nextcloud --field-selector=status.phase==Running pods | grep 'nextcloud-[0-9]' | awk '{ print $1; }'); k3s kubectl exec -n ix-nextcloud -c nextcloud -i "$NEXTCLOUDPOD" -- su -s /bin/bash www-data -c 'php -d memory_limit=-1 -f /var/www/html/cron.php'

It will check for the running state, preventing exec on pods while upgrading or other states. The usage of variables prevent wordsplitting.
 

Shigure

Dabbler
Joined
Sep 1, 2022
Messages
39
I recently moved from truecharts to truenas nextcloud app, and it seems I just cannot get the cron task running correctly. But there is a cron job section in the settings which I missed...

However I'm having a issue that nextcloud is not that snappy and this warning.
  • The database is missing some indexes. Due to the fact that adding indexes on big tables could take some time they were not added automatically. By running "occ db:add-missing-indices" those missing indexes could be added manually while the instance keeps running. Once the indexes are added queries to those tables are usually much faster. Missing optional index "fs_storage_path_prefix" in table "filecache".
Now I'm stuck since I cannot switch to www-data user to run php occ db:add-missing-indices. Trying to figure out how to run the command through kubectl.

OK here's the command works for me.

First get the pod name
k3s kubectl get pods -A | grep nextcloud
Then run this to add the indices, where nextcloud-7c84b8bbf-m4k9r is the pod name got from last command.
k3s kubectl exec -n ix-nextcloud --stdin --tty nextcloud-7c84b8bbf-m4k9r -- su -s /bin/bash www-data -c 'php occ db:add-missing-indices'

I cannot say if the performance is really improved but at least that warning is gone...
 
Last edited:
Top