Need help directing Cron Job to an app

quintman

Cadet
Joined
Aug 13, 2023
Messages
5
Hi all, fairly new Truenas SCALE user, looking for some Cron help!

I have an app, Photoprism, that I would like to run a Cron job on each night. I've found some examples online which do what I'd like:

"docker exec -ti photoprism photoprism index —cleanup"

However this command doesn't work when I try to setup a Cron job through the GUI. I'm guessing it's something to do with Scale not actually using docker but Kubernetes? from what I can gather, I may need to edit the first photoprism to point to the correct app (or container?) but I just don't know what I'm looking for.

For reference, if I go to Apps, open the photoprism App Shell and type "photoprism index --cleanup" it does exactly what I want.

Thank you!
 

sretalla

Powered by Neutrality
Moderator
Joined
Jan 1, 2016
Messages
9,703
Maybe you need some information like this:
 

quintman

Cadet
Joined
Aug 13, 2023
Messages
5
Maybe you need some information like this:
Hi thanks for this. I read an understood. came up with the following:
"k3s kubectl exec -n ix-photoprism --stdin --tty photoprism-66976f989b-4b6tr -- /bin/sh"

if I enter this in Truenas she'll, I can then enter my command "photoprism index --cleanup" it runs perfectly. I however still cannot figure out how to enter this into the Cron GUI? Is there any further guidance?
I tried this as my Cron command: "k3s kubectl exec -n ix-photoprism --stdin --tty photoprism-66976f989b-4b6tr -- /bin/sh | photoprism index --cleanup" but get the attached error.
 

Attachments

  • Screenshot_20230815-081529.png
    Screenshot_20230815-081529.png
    67.3 KB · Views: 84

quintman

Cadet
Joined
Aug 13, 2023
Messages
5
Maybe you need some information like this:
Ah please disregard my last post! some further reading, I just needed to remove the /bin/sh | from my line and all working. thank you!
 

quintman

Cadet
Joined
Aug 13, 2023
Messages
5
Maybe you need some information like this:
Sorry have one further question. I have the following command that can run successfully as a Truenas cronjob:
"k3s kubectl exec -n ix-photoprism --stdin --tty photoprism-66976f989b-4b6tr -- photoprism index --cleanup"

However, I didn't realise that the pod name with kubernetes changes every time you stop and start an app (eg. a server restart). I had a restart, then my job failed. Then I noticed the string photoprism-66976f989b-4b6tr had changed. Is there anyway around this? It seems all the docker examples i can find only go to the container, not the specific pod, so its hard to find comparison. Some search has led that there is no way to fix a pod name.
 

sretalla

Powered by Neutrality
Moderator
Joined
Jan 1, 2016
Messages
9,703
This will probably do it... you may need to mess with it a bit to get the right namespace with the first grep if you have multiple photoprism apps:

k3s kubectl get namespaces -o name | grep photoprism | sed -r "s/namespace\///g" | xargs -I{} k3s kubectl get -o name -n {} pods | sed -r "s/pod\///g" | xargs -I{} k3s kubectl exec -n ix-photoprism --stdin --tty {} -- photoprism index --cleanup
 

sretalla

Powered by Neutrality
Moderator
Joined
Jan 1, 2016
Messages
9,703
Actually I see you're already fixed on the namespace, so we can shorten it a lot:

k3s kubectl get -o name -n ix-photoprism pods | sed -r "s/pod\///g" | xargs -I{} k3s kubectl exec -n ix-photoprism --stdin --tty {} -- photoprism index --cleanup
 

Isma

Contributor
Joined
Apr 29, 2020
Messages
100
Actually I see you're already fixed on the namespace, so we can shorten it a lot:

k3s kubectl get -o name -n ix-photoprism pods | sed -r "s/pod\///g" | xargs -I{} k3s kubectl exec -n ix-photoprism --stdin --tty {} -- photoprism index --cleanup

Could this command be adapted to the nextcloud cron? we have a discussion for cobia beta.1

 

quintman

Cadet
Joined
Aug 13, 2023
Messages
5
Could this command be adapted to the nextcloud cron? we have a discussion for cobia beta.1

Just read your thread. In my case, i had to remove the "/bin/bash" (and maybe in your case "root -c" as well) to get rid of the error you are seeing.
 

dain

Cadet
Joined
Jun 29, 2023
Messages
5
A much simpler way to get the running pod name is using `kubectl` itself like:

Code:
k3s kubectl exec -n ix-photoprism `k3s kubectl -n ix-photoprism get pod -o name --field-selector=status.phase==Running` -- photoprism index --cleanup
 

sretalla

Powered by Neutrality
Moderator
Joined
Jan 1, 2016
Messages
9,703
A much simpler way to get the running pod name is using `kubectl` itself
I don't know if I'd say simpler, but I'll certainly agree better.
 
Top