Although I know it's been recommended several times by SE Staff to only perform backups when the site is in Maintenance mode, I haven't been able to find anything about the ability to switch between Online/Offline modes automatically (such as before/after a scheduled backup).
Could someone please point me to any links that discuss this, or describe here an app/tool/whatever that you use to make this switch automatically. If there's nothing out there that does this, then I'll just create an FR for this because it doesn't make sense that this doesn't exist.
Thanks.
We just run a job to copy the general.php with maintenance enabled right before our maintenance run and to turn it off after.
Make two copies of /application/settings/general.php
We named our first copy "maint_disable" with the code below.
<?php defined('_ENGINE') or die('Access Denied'); return array (
'environment_mode' => 'production',
'maintenance' =>
array (
'enabled' => false,
'code' => 'changethispassword',
),
); ?>
The second copy of general.php is called "maint_enable"
<?php defined('_ENGINE') or die('Access Denied'); return array (
'environment_mode' => 'production',
'maintenance' =>
array (
'enabled' => true,
'code' => 'changethispassword',
),
); ?>
Now you can pick whatever method to copy "maint_disable" and "maint_enable" as general.php right before your backups begin.
We keep it really simple
To enable maintenance mode:
cp /var/www/html/application/settings/maint_enable /var/www/html/application/settings/general.php
To disable maintenance mode at end of backups:
cp /var/www/html/application/settings/maint_disable /var/www/html/application/settings/general.php
It only took about 2 minutes to setup. You just need to select a method of executing the file copy command before your backup window based on your server/hosting abilities.
I hope this help, if anyone does this better, we would love to know!
Nice tips!
Wow - thanks @Casey. Very helpful.
One more thing... what happens to Users when switching between modes?
Users should be locked out of the site and your maintenance message will be displayed. The ugly one with the access code message that needs a huge overhaul if you have not customized it yourself.
I use a Plugin by SES to display the Maint msg.
But what will happen to Users in the site when I switch to Maint Mode - is anythg (database) corrupted or is open work (in process msgs, postings, uploads, etc.) just not saved/stored?
Anything open and pending at the time will not be saved/stored after maintenance mode is enabled. This will not happen for people (staff) have maintenance cookie valid in their browser. The cookie is named en4_maint_code just FYI. So you should limit any maintenance involving any site backups where a staff member would be making changes to the DB and files to non backup maintenance time. Also, as a rule of good measure for your members, you should have some type of "Upcoming Maintenance" banner display across your site informing them they should finish any work because they are about to lose the ability to save.
Thx again @Casey for the helpful info.
Now I just have to find a Plugin that will display a message at a scheduled time and I'll be all set. Maybe this whole thing could be a Plugin, unless it's a Core mod which means it would become another FR for SE in the back corner
You do not need any "mod" or core edit to display a site wide announcement bar. Lots of free code snippets all over the web to show a simple message banner.
Add this CSS code to your website's theme customization.css if you have one.
#msgbar{
background: rgb(252, 70, 30);
color: #fff;
display: block;
position: fixed;
bottom: 0;
left: 0;
width: 100%;
padding: 10px 0px;
text-align: center;
}
#msgbar a{
color: #fff;
text-decoration:underline;
font-weight: normal;
}
Download the Web80's SE Core Plugin (if you do not already have it)
https://plugins.click/socialengine/core-plugin
Once installed, use the Advanced Control Container and add it as the last item in your site footer.
Add an HTML block (the standard SE one) inside the advanced control container and add the code below and change message to whatever you want:
<div id="msgbar">
<strong>SCHEDULED SITE MAINTENANCE STARTING AT 3:00AM EST</strong>
</div>
Now, access your site DB through a DB browser (phpmyadmin or whatever) and go to the engine4_core_content table. If you go to the last entry, you will probably see your advanced control container entry for your footer.
Use that table entry to build a nice SQL query to modify the entry to make the "disabled" change from 0 to 1 to hide the bar and the 1 back to 0 to show before your maint.
Message not hidden (your site message for backup about to happen) will be something like this under the params column
{"disable":"0","allow":["1","2","3","4","5","6","7","8","9","10","11"],"className":"","styles":"","content_id":"","title":"","nomobile":"0","name":"webcore.control-container"}
To hide bar, it should look something like this in your params column:
{"disable":"1","allow":["1","2","3","4","5","6","7","8","9","10","11"],"className":"","styles":"","content_id":"","title":"","nomobile":"0","name":"webcore.control-container"}
How you make this work to change the db entry back and forth all depends on your system and its abilities.
There is probably an easier way to do the last, but it works for us when automation is running from the command line.