Automatically switch between Online/Offline (Maint) modes

  • gs
    • 857 posts
    July 7, 2018 5:17 PM EDT

    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. 



    • 66 posts
    July 9, 2018 9:22 AM EDT

    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!


    • Moderator
    • 6650 posts
    July 9, 2018 1:44 PM EDT

    Nice tips! 

  • gs
    • 857 posts
    July 9, 2018 5:43 PM EDT

    Wow - thanks @Casey.  Very helpful.


    One more thing... what happens to Users when switching between modes?  

    • 66 posts
    July 9, 2018 10:05 PM EDT

    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.

  • gs
    • 857 posts
    July 9, 2018 11:38 PM EDT

    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?

    • 66 posts
    July 10, 2018 1:02 AM EDT

    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.

    This post was edited by Casey at July 10, 2018 3:10 AM EDT
  • gs
    • 857 posts
    July 10, 2018 1:44 AM EDT

    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

    • 66 posts
    July 10, 2018 1:50 AM EDT

    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.

  • gs
    • 857 posts
    July 10, 2018 2:17 AM EDT
    Thx again (wish there was an icon reward thg here in the Forum).

    None of the bars I've used allow scheduling, but I'll search again so a message could be displayed from start-to-end time (or start time for X minutes) so it's gone when Maint Mode begins.

    By Plugin, I meant for the whole process. I'd like to schedule a start/end time for Maint Mode, along with X mins prior to start to display a msg. I'd also like this to allow schedules for each day. Then my JetBackup will kick in as usual to do its thing.

    This post was edited by gs at July 10, 2018 2:19 AM EDT
    • 66 posts
    July 10, 2018 3:54 AM EDT

    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)


    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




    To hide bar, it should look something like this in your params column:


    How you make this work to change the db entry back and forth all depends on your system and its abilities.



    • 66 posts
    July 10, 2018 3:58 AM EDT

    There is probably an easier way to do the last, but it works for us when automation is running from the command line.

    This post was edited by Casey at July 10, 2018 4:00 AM EDT
  • gs
    • 857 posts
    July 10, 2018 9:28 AM EDT
    @Casey- thx again.