Cron task under windows: Fatal error: $CFG->dataroot is not configured properly, directory does not exist or is not accessible! Exiting.

Cron task under windows: Fatal error: $CFG->dataroot is not configured properly, directory does not exist or is not accessible! Exiting.

by Colin Santry -
Number of replies: 1

Hi again fellow Moodlers,

I'm hoping someone here can shed light on exactly the issue I'm experiencing here at the moment. Little background:

I migrated our INTERNAL Moodle site (v 3.6.2 (Build: 20190114)) to our LIVE load balanced servers with a single DB server & moodledata location, with a little help from you fine people I must add). At first i was receiving the same error as I am here:

Fatal error: $CFG->dataroot is not configured properly, directory does not exist or is not accessible! Exiting.

Which turned out to be permissions related in IIS.

Now that I have the site running successfully I noticed the message relating to 'cron jobs not being ran in last 24hrs' etc. After looking through the forums I found a few posts that helped me piece together a *.bat file to run under Task Scheduler in Windows.

I have successfully managed to get this running on the INTERNAL environment but  when I moved this to the LIVE environment, changed the paths/locations etc. I get the same error when setting up initially (above).

I am unsure where this is coming from? doesn't the cron.php scripts use the same config.php file? I am led to believe by my ISP that the credentials applied to the task in task scheduler is the same user applied to IIS when this issue occurred originally?!

Is this definitely an issue with the user running the cron task in scheduler or can it be something else? I thought I better ask before I tell my ISP they have setup the user/credentials incorrectly smile

Batch file used: 

@echo off


:: set folder path

set log_path=C:\inetpub\logs\moodle\cronlogs


:: Create a folder with today's date

cd %log_path%

set folder=logs-%date:~6,4%%date:~3,2%%date:~0,2%

if not exist %log_path%\%folder% (

    mkdir %log_path%\%folder%

)


for /f "tokens=1,2,3 delims=: " %%G in ('time/t') do (

  if /i "%%I"=="PM" (

    set /a _hr = %%G + 12

    if %%G==12 set _hr=12

    ) else (

        set _hr=0%%G

        if %%G==12 set _hr=00

  )

)


:: Now run the Moodle cron.php script and log the output to the current hours' log file.

C:\php\v7.2.13\php.exe -f C:\inetpub\moodle\admin\cli\cron.php >> %log_path%\%folder%\%date:~6,4%%date:~3,2%%date:~0,2%-%_hr:~-2%.log


:: set min age of files and folders to delete

set max_days=30

:: remove files from %log_path%

forfiles -p %log_path% -m *.* -d -%max_days% -c "cmd  /c del /q @path"

:: remove sub directories from %log_path%

forfiles -p %log_path% -d -%max_days% -c "cmd /c IF @isdir == TRUE rd /S /Q @path"


This is the same batch file used INTERNALLY, with the paths altered for LIVE. The error message stated is being appended to the logfile created so I'm assuming its an issue with the line executing the cron.php task??


Any help would be greatly appreciated.


Kind Regards,

Colin

Average of ratings: -
In reply to Colin Santry

Re: Cron task under windows: Fatal error: $CFG->dataroot is not configured properly, directory does not exist or is not accessible! Exiting.

by Leon Stringer -
Picture of Core developers Picture of Particularly helpful Moodlers

The first thing I'd check is whether the user the scheduled task is being run as has access to the Moodledata folder (the location defined in $CFG->dataroot) which I think is what you're suggesting.

For a single-node IIS server with local Moodledata I add a scheduled task and run this as the local system account NT AUTHORITY\SYSTEM.

But if you've got two nodes presumably the Moodledata storage is being presented as some sort of mapped drive? So you need a user for your scheduled task which can access this location. You could try a test with a batch file containing something like:

DIR path\to\moodledata > logfile.txt 2>&1

Then configure a scheduled task to run this batch file as the same user as the existing cron task and seeing if it can see the files in the Moodledata folder.

If the IIS user is being used to run the scheduled task it could be that the IIS site user is different from the IIS user used for the scheduled task. In a single site/single node environment this user is usually the local IUSR account but this could vary (this is how I'd determine the user in a single node environment).