getgrav / grav-premium-issues

Official Grav Premium Issues repository to report problems or ask questions regarding the Premium products offered.
https://getgrav.org/premium
7 stars 2 forks source link

[site-toolbox] Warm-cache cron issue #447

Closed Grayches closed 2 weeks ago

Grayches commented 3 weeks ago

I have warm-cache premium plugin, I can run it fine from command line with the below commands:

cd /home/USER/public_html bin/plugin warm-cache warm https://example.com/sitemap.json or

/home/user/public_html/bin/plugin warm-cache warm https://example.com/sitemap.json

both esentially the same thing. However, when I save this as a shell script as per the docs, in root/bin:

!/bin/sh

cd /home/USER/public_html bin/plugin warm-cache warm https://example.com/sitemap.json I get the following error when run with cron:

2024-06-15T08:23:02+01:00 Content-type: text/html; charset=UTF-8 FATAL: Must be run from ROOT directory of Grav

Aside from the above Ive tried

cd … cd “/…/” .bin/plugin warm-cache warm https://example.com/sitemap.json cd /home/USER/public_html cd “/home/USER/public_html/”

I cant see what Im missing?

The alternative is “if onCacheClear Event” is enabled in the plugin settings does this still trigger from the cache-clear cron job? If so I dont need any of the above as this is set up and working.

rhukster commented 3 weeks ago

can you run the script without cron successfully?

#!/bin/sh
cd /home/USER/public_html
bin/plugin warm-cache warm https://example.com/sitemap.json

with: ./your-script.sh ???

??

Grayches commented 3 weeks ago

Hi,

I move the script into the root directory yes it runs ok with ./warm-cache.sh. The docs say to put this script into the bin file.

I copied this to the root and changed the cron to point at it with home/user/public_html/warm-cache.sh and “FATAL: Must be run from ROOT directory of Grav!”

With ./warm-cache.sh in the cronjob it says file not found.

I took out the middle line from the script (cd /home/USER/public_html) and tried to run again by pointing to the script from cron and says “FATAL: Must be run from ROOT directory of Grav!”

From: Andy Miller @.> Sent: Monday, June 17, 2024 6:42 PM To: getgrav/grav-premium-issues @.> Cc: Grayches @.>; Author @.> Subject: Re: [getgrav/grav-premium-issues] [site-toolbox] Warm-cache cron issue (Issue #447)

can you run the script without cron successfully?

!/bin/sh

cd /home/USER/public_html bin/plugin warm-cache warm https://example.com/sitemap.json

with: ./your-script.sh ???

??

— Reply to this email directly, view it on GitHub https://github.com/getgrav/grav-premium-issues/issues/447#issuecomment-2173976392 , or unsubscribe https://github.com/notifications/unsubscribe-auth/BIQBEBGJ6SX5C2EU2XTHOW3ZH4NWZAVCNFSM6AAAAABJMQ4ITWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNZTHE3TMMZZGI . You are receiving this because you authored the thread.Message ID: @.***>

rhukster commented 3 weeks ago

The script file itself can be anywhere, so a good place is in a bin/ folder in your user's root (e.g. ~/bin same as /home/USER/bin/). you really don't have to put it in the public_html folder, that is for your web files. Update your cron to point to the /home/USER/bin/warm-cache.sh file and i don't see why that would not work for you.

Did you not update the USER to your Actual user? for example, mine is /home/rhuk/... USER is just a placeholder.

Grayches commented 3 weeks ago

Yes I changed the name to my username. It finds the script otherwise it returns “no file or dir” but then keeps returning the from ROOT error.

The script is:

!/bin/sh

cd /home/MYUSER/public_html/

bin/plugin warm-cache warm https://MYSITE.com/sitemap.json

returned: Output from Job ID: warm-cache

Command: /home/ MYUSER /bin/warm-cache.sh

Content-type: text/html; charset=UTF-8

FATAL: Must be run from ROOT directory of Grav!

With scheduler set up as below:

From: Andy Miller @.> Sent: Monday, June 17, 2024 9:55 PM To: getgrav/grav-premium-issues @.> Cc: Grayches @.>; Author @.> Subject: Re: [getgrav/grav-premium-issues] [site-toolbox] Warm-cache cron issue (Issue #447)

The script file itself can be anywhere, so a good place is in a bin/ folder in your user's root (e.g. ~/bin same as /home/USER/bin/). you really don't have to put it in the public_html folder, that is for your web files. Update your cron to point to the /home/USER/bin/warm-cache.sh file and i don't see why that would not work for you.

Did you not update the USER to your Actual user? for example, mine is /home/rhuk/... USER is just a placeholder.

— Reply to this email directly, view it on GitHub https://github.com/getgrav/grav-premium-issues/issues/447#issuecomment-2174406086 , or unsubscribe https://github.com/notifications/unsubscribe-auth/BIQBEBHOXNQYBWVP6UTBS23ZH5EJVAVCNFSM6AAAAABJMQ4ITWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNZUGQYDMMBYGY . You are receiving this because you authored the thread.Message ID: @.***>

rhukster commented 3 weeks ago

Could please post the screenshot via Github and not email. It gets lost and I can't see it.

Grayches commented 3 weeks ago

image

Grayches commented 3 weeks ago

Ive tried ammending the script to

!/bin/sh

bin/plugin warm-cache warm https://example.com/sitemap.json

putting it in the root folder of grav public_html then calling that from dron and still get FATAL: Must be run from ROOT directory of Grav!

Grayches commented 3 weeks ago

Ive tried running cron from cpanel: image

same output:

Content-type: text/html; charset=UTF-8 FATAL: Must be run from ROOT directory of Grav!

Grayches commented 2 weeks ago

Ive tried again this morning by putting the warm-cahce.sh script into the root folder and pointg the cron directly to it and to output the dir to log file to prove it is running from the root of grav, it is but still displays the same error: LICENSE.txt assets
backup logs bin now.json cache README.md CHANGELOG.md robots.txt CODE_OF_CONDUCT.md SECURITY.md composer.json system composer.lock tmp CONTRIBUTING.md user error_log vendor warm-cache.sh images webserver-configs index.php Content-type: text/html; charset=UTF-8

FATAL: Must be run from ROOT directory of Grav!

Grayches commented 2 weeks ago

prefixing the command with "php-cli" resolved the issue:

!/bin/sh

php-cli bin/plugin warm-cache warm https://example.com/sitemap.json

I thought I had already tried this but must of had something else wrong at the time from the prior attempts.

Grayches commented 2 weeks ago

ok, I got that wrong. That gives php-cli: command not found

I tried with php -C -f bin/plugin warm-cache warm https://example.com/sitemap.json

and got:

Usage: [slug] [command] [arguments]

Example: error log -l 1 --trace

Plugins with CLI available:

  1. devtools devtools list
  2. email email list
  3. error error list
  4. flex-objects flex-objects list
  5. git-sync git-sync list
  6. license-manager license-manager list
  7. login login list
  8. precache precache list
  9. problems problems list
  10. shortcode-core shortcode-core list
  11. warm-cache warm-cache list 2024-06-19T08:39:03+01:00

so still not running from cron but works fine from CLI

Grayches commented 2 weeks ago

OK this time it is fixed. I had to use the below:

/opt/alt/php74/usr/bin/php bin/plugin warm-cache warm https://example.com/sitemap.json

I took this prefix from the scheduler cron for anyone else with this issue.