Moodle maintenance mode cli in a script

Moodle maintenance mode cli in a script

by Conor Bradley -
Number of replies: 3

The command line admin option for putting moodle into maintenance mode is really useful

https://docs.moodle.org/25/en/Administration_via_command_line#Maintenance_mode


   $ sudo -u apache /usr/bin/php admin/cli/maintenance.php --enable


but does anyone know if it's possible to get this command to run inside a linux bash script so I can schedule it to happen later at night? My problem is that when I run it I get an error saying that its using 'unrecognized options' which suggests that the --enable option isn't being passed to the php script. Is there some way of getting this working?

Average of ratings: -
In reply to Conor Bradley

Re: Moodle maintenance mode cli in a script

by Bret Miller -
Picture of Particularly helpful Moodlers

Maybe it's not the fact that it's in a bash script, but that it's running under cron and not interactively? I say that because I use it in a bash script every time I upgrade Moodle, but I've never tried scheduling the upgrades--always run them from the command line. I have had other issues calling WordPress CLI stuff from bash under cron. The environment is different. I'd guess that sudo -u apache retains the current directory when used interactively, but perhaps it doesn't when run under cron in a bash script.

Maybe run a "sudo -u apache pwd" right before it to see if the current working directory is correct...

In reply to Conor Bradley

Re: Moodle maintenance mode cli in a script

by Ken Task -
Picture of Particularly helpful Moodlers

Run sites on git and use many of the scripts in admin/cli/ to either update or upgrade Moodles, but, I run those bash shell scripts as the root user ... not apache user and not under sudo .... and one should probably run them in the moodle code directory.   Scripts I have reside else where and cd /pathto/moodle/code/ before doing anything else.

Could be the environment of the apache user is the culprit ... server have some other protections running like seLinux or apparmor, etc.?   Running safe mode?

https://www.acunetix.com/websitesecurity/php-security-5/

'spirit of sharing', Ken




In reply to Ken Task

Re: Moodle maintenance mode cli in a script

by Conor Bradley -

Thanks for all the input on this one - in the end I gave up and just added a line in my script that changes the link from the apache 'sites-enabled' file to point to a 'sites-available' file that loads up a maintenance html page I made myself.