So I found the variable that holds the maintenance mode information in the Drupal MySQL DB. It is located in the table named "variable", and the field name is "site_offline". When the site is in maintenance mode (offline) the value = s:1:"1"; when the site is NOT in maintenance mode (online) the value = s:1:"0";.
So I built a little bash script that will change this value from shell:

#!/bin/sh

# Begin User Modifiable Variables
MYSQLHOST="mysql.drupalsite.com"  #could also be "localhost" if using on a local machine
MYSQLDB="drupalmysqldbname"
MYSQLUSER="user"
MYSQLPASS="pass"
MYSQLOPTS="--user=${MYSQLUSER} --password=${MYSQLPASS} --host=${MYSQLHOST} --database=${MYSQLDB}"
LOG=test.log
### MORE VARIABLES End

echo "Would you like the site to be online of offline: " 
select MAINTENANCEMODE in "Online" "Offline"; do
	case ${MAINTENANCEMODE} in
		Online ) echo "Set status to Online (Maintenance Mode=False)" >> ${LOG}; break;;

		Offline ) echo "Set status to Offline (Maintenance Mode=True)" >> ${LOG}; break;;
	esac
done

if [ ${MAINTENANCEMODE} = "Online" ]; then
	echo "Turn site Online (Maintenance Mode=FALSE) START: $(date)" >> ${LOG}
	#mysql variables table - site_offline=s:1:"0";
	mysql ${MYSQLOPTS} --execute="UPDATE variable SET value='s:1:\"0\";' WHERE name='site_offline'"
	echo "Turn site Online (Maintenance Mode=FALSE) END: $(date)" >> ${LOG}
else
	echo "Turn site Offline (Maintenance Mode=True) START: $(date)" >> ${LOG}
	#mysql variables table - site_offline=s:1:"1";
	mysql ${MYSQLOPTS} --execute="UPDATE variable SET value='s:1:\"1\";' WHERE name='site_offline'"
	echo "Turn site Offline (Maintenance Mode=True) END: $(date)" >> ${LOG}
fi

The script simply changes the setting of site_offline's value to the value required for the site to be online or offline (respectively) based upon the user's response to the question. and while the script does work (it changes the value as it should) the site does not go into offline or online mode based upon that change alone. So this leads me to believe there is something else at play here, possibly another variable stored somewhere else. So, what is it? What am I missing? Can someone point me in the right direction?
Thanks in advance,
-Chris

Comments

ChrisRut’s picture

Nevermind, I figured it out... I needed to clear the cache (drush cache clear) in order to see the changes.
It works ;-)
Hope the above script helps others who want to set maintenance mode manually from shell.

johnbarclay’s picture

Using drush you can do this sort of thing fairly easily. Its worth the time to install and read about. Since its the standard for drupal command line work, you will be able to leverage a larger body of scripts and support. It leverages the drupal code base and a sites settings.php file.

After installing drush, from the command line you can accomplish taking a site offline with:

drush eval "variable_set("site_offline", TRUE)

drush even comes with an example command template to make your own commands.

ChrisRut’s picture

Thanks for the tip... I am going to look into using "drush eval" more often.
Thanks again

SamLerner’s picture

An easier method instead of drush eval is to use drush vset, which sets variables directly.

So to put a site in maintenance mode, you would run this:

(in D6) drush vset site_offline 1

(in D7) drush vset maintenance_mode 1

savedario’s picture

Thanks for posting this, even several years later. I've found myself in a tight corner, without drush and phpMyAdmin, and the script really helped.
Just in case someone else bumps into this, indeed one needs to clear the cache, but the script itself does not really work without changing the two mysql calls so that the shell does not gobble-up the inner double quotes.
Instead of:
mysql ${MYSQLOPTS} --execute="UPDATE variable SET value='s:1:"0";' WHERE name='site_offline'"
it should be:
mysql ${MYSQLOPTS} --execute="UPDATE variable SET value='s:1:\\\"0\\\";' WHERE name='site_offline'"
and of course:
mysql ${MYSQLOPTS} --execute="UPDATE variable SET value='s:1:\\\"1\\\";' WHERE name='site_offline'"