Welcome to Centmin Mod Community
Become a Member

Beta Branch sitestatus maintenance mode

Discussion in 'Beta release code' started by eva2000, Jan 8, 2016.

Thread Status:
Not open for further replies.
  1. eva2000

    eva2000 Administrator Staff Member

    37,227
    8,132
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +12,520
    Local Time:
    10:52 AM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    I've been doing custom scripted maintenance modes for private paying clients for years. It's one of the cheapest ways to work around very large site's database and file backup schedules by just putting a site and/or entire server into maintenance mode for 5-15 minutes.

    This is as opposed to spending 100s to 1000s of dollars on high availability 99.9999% uptime solutions just so you don't want your site's visitors from not being able to reach your site for 5-15 minutes ! Which is crazy if you think about it when large multi-billion dollar banking and commercial online companies also have scheduled maintenance schedules. Usually, you'll run into these schedules around after midnight or on weekends when traffic is low. Don't be fooled, if those large companies can schedule maintenance periods, so can we :D ;)

    I've had scripts like this on some of my servers for a few years now. One is a simple /usr/bin/sitestatus script. This script also works with IP address whitelisting so you can still browse a site in maintenance mode to visitors but not to oneself :)

    The sitestatus command options, just 2 exist - on or off. Off means put site into maintenance mode :)
    Code (Text):
    sitestatus
    /usr/bin/sitestatus {on|off}
    

    Site on with maintenance mode disabled gives newdomain1.com site a 200 HTTP status code
    Code (Text):
    sitestatus on
    nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
    nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
    Stopping nginx:                                            [  OK  ]
    Starting nginx:                                            [  OK  ]
    HTTP/1.1 200 OK
    Date: Fri, 08 Jan 2016 04:37:10 GMT
    Content-Type: text/html; charset=utf-8
    Content-Length: 1368
    Last-Modified: Fri, 08 Jan 2016 00:32:34 GMT
    Connection: keep-alive
    ETag: "568f03a2-558"
    Server: nginx centminmod
    Expires: Sat, 09 Jan 2016 04:37:10 GMT
    Cache-Control: max-age=86400
    Cache-Control: public, must-revalidate, proxy-revalidate
    Accept-Ranges: bytes
    

    Site off with maintenance mode enabled gives newdomain1.com site a 503 HTTP status code
    Code (Text):
    sitestatus off
    nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
    nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
    Stopping nginx:                                            [  OK  ]
    Starting nginx:                                            [  OK  ]
    HTTP/1.1 503 Service Temporarily Unavailable
    Date: Fri, 08 Jan 2016 04:37:13 GMT
    Content-Type: text/html; charset=utf-8
    Content-Length: 2192
    Connection: keep-alive
    ETag: "568f03a2-890"
    Server: nginx centminmod


    Of course 503 maintenance page template would need work :D

    upload_2016-1-8_14-47-7.png

    Or more nicer template

    upload_2016-1-8_21-36-42.png

    contents of include file /usr/local/nginx/conf/maintenance.conf added to /usr/local/nginx/conf/nginx.conf. You can add your own ip to be whitelisted to bypass maintenance mode or even add specific urls that bypass maintenance mode, i.e. images you include in your maintenance.html page.
    Code (Text):
         # IPs you can whitelist from maintenance mode
         geo $maint_whitelist {
              include /usr/local/nginx/conf/sitestatus.conf;
              127.0.0.1 0;
              #YOURIPADDRESS 0;
         }
    
         map $http_host$uri $exclude_url {
              default                                                0;
              "~^newdomain1.com/js/jquery.fittext.js"                1;
              "~^newdomain1.com/blog/js/jquery.fittext.js"           1;
         }
    
         map $maint_whitelist$exclude_url $maintenance {
              default        1;
              10             1;
              11             1;
              00             0;
              01             0;
         }

    contents of inner include file /usr/local/nginx/conf/sitestatus.conf
    Code (Text):
    default 0;
    


    Verifying SiteStatus Maintenance Mode Setup



    To verify if Centmin Mod 123.09beta01 and your Nginx vhost has all requirements to use sitestatus maintenance mode. In 123.09beta01 the nginx vhost default template adds 2 includes files starting with 503include-*.conf
    /usr/local/nginx/conf/503include-main.conf under root directive and /usr/local/nginx/conf/503include-only.conf within location / context
    Code (Text):
      root /home/nginx/domains/testdomain.com/public;
      include /usr/local/nginx/conf/503include-main.conf;
    
      location / {
      include /usr/local/nginx/conf/503include-only.conf;
    

    and within /usr/local/nginx/conf/php.conf after location php line
    Code (Text):
    location ~ [^/]\.php(/|$) {
      include /usr/local/nginx/conf/503include-only.conf;
        fastcgi_split_path_info ^(.+?\.php)(/.*)$;
    

    and in /usr/local/nginx/conf/nginx.conf a /usr/local/nginx/conf/maintenance.conf include file
    Code (Text):
    # uncomment cloudflare.conf include if using cloudflare for
    # server and/or vhost site + setup cron job for command
    # /usr/local/src/centminmod/tools/csfcf.sh auto
    # run the auto command once to populate cloudflare ips
    #include /usr/local/nginx/conf/cloudflare.conf;
    # uncomment incapsula.conf include if using incapsula for
    # server and/or vhost site + setup cron job for command
    # /usr/local/src/centminmod/tools/csfincapsula.sh auto
    # run the auto command once to popular incapsula ips
    #include /usr/local/nginx/conf/incapsula.conf;
    include /usr/local/nginx/conf/maintenance.conf;
    #include /usr/local/nginx/conf/vts_http.conf;
    include /usr/local/nginx/conf/geoip.conf;
    include /usr/local/nginx/conf/webp.conf;
    


    contents of /usr/local/nginx/conf/maintenance.conf at centminmod/maintenance.conf at 123.09beta01 · centminmod/centminmod · GitHub

    and adds a /usr/local/nginx/conf/sitestatus.conf and the control file /usr/bin/sitestatus
     
    Last edited: Sep 30, 2016
    • Winner Winner x 4
    • Like Like x 3
  2. eva2000

    eva2000 Administrator Staff Member

    37,227
    8,132
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +12,520
    Local Time:
    10:52 AM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    For testing purposes setup sitestatus script on this forum with custom maintenance.html page at https://community.centminmod.com/maintenance.html which gets triggered one when I set sitestatus to off
    Code (Text):
    sitestatus off


    working nicely :D

    upload_2016-1-9_15-30-6.png
     
    Last edited: Sep 30, 2016
    • Like Like x 2
    • Winner Winner x 2
  3. eva2000

    eva2000 Administrator Staff Member

    37,227
    8,132
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +12,520
    Local Time:
    10:52 AM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    Not entirely intended side effect of implementing 503 maintenance page is that some uptime monitoring services will consider a 503 HTTP status as a downtime alert and trigger off alert emails. So you'll need to tweak your uptime monitoring if you have the option to do so from service side options.

    upload_2016-1-9_15-48-32.png
     
    • Like Like x 3
  4. eva2000

    eva2000 Administrator Staff Member

    37,227
    8,132
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +12,520
    Local Time:
    10:52 AM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    Testing a maintenance page with my Twitter timeline embedded Site Maintenance :)
     
    • Like Like x 2
  5. eva2000

    eva2000 Administrator Staff Member

    37,227
    8,132
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +12,520
    Local Time:
    10:52 AM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    Testing 503 maintenance mode added to latest Centmin Mod 123.09beta01 code base.

    centminmod-sitestatus-00.gif

    The actual maintenance.html page is the file already located in each nginx vhost public web root at /home/nginx/domains/domain.com/public/maintenance.html

    Added support for 3 new variables:
    Code (Text):
    NGINX_UPDATEMAINTENANCE=n
    PHP_UPDATEMAINTENANCE=n
    MARIADB_UPDATEMAINTENANCE=n
    


    If you set to yes in /etc/centminmod/custom_config.inc file. then whenever you run nginx, php or major mariadb upgrade, you put all sites on server into 503 maintenance mode first Beta Branch - sitestatus maintenance mode | Centmin Mod Community and once updated, disable 503 maintenance mod after.

    set in newly created or existing /etc/centminmod/custom_config.inc persistent config file
    Code (Text):
    NGINX_UPDATEMAINTENANCE=y
    PHP_UPDATEMAINTENANCE=y
    MARIADB_UPDATEMAINTENANCE=y
    


    Example of the new nginx vhost for new testdomain.com site created for vhost config file
    /usr/local/nginx/conf/conf.d/testdomain.com.conf
    Code (Text):
    # Centmin Mod Getting Started Guide
    # must read http://centminmod.com/getstarted.html
    
    # redirect from non-www to www
    # uncomment, save file and restart Nginx to enable
    # if unsure use return 302 before using return 301
    #server {
    #            listen   80;
    #            server_name testdomain.com;
    #            return 301 $scheme://www.testdomain.com$request_uri;
    #       }
    
    server {
      server_name testdomain.com www.testdomain.com;
    
    # ngx_pagespeed & ngx_pagespeed handler
    #include /usr/local/nginx/conf/pagespeed.conf;
    #include /usr/local/nginx/conf/pagespeedhandler.conf;
    #include /usr/local/nginx/conf/pagespeedstatslog.conf;
    
      #add_header X-Frame-Options SAMEORIGIN;
      #add_header X-Xss-Protection "1; mode=block" always;
      #add_header X-Content-Type-Options "nosniff" always;
    
      # limit_conn limit_per_ip 16;
      # ssi  on;
    
      access_log /home/nginx/domains/testdomain.com/log/access.log combined buffer=256k flush=60m;
      error_log /home/nginx/domains/testdomain.com/log/error.log;
    
      root /home/nginx/domains/testdomain.com/public;
      include /usr/local/nginx/conf/503include-main.conf;
    
      location / {
      include /usr/local/nginx/conf/503include-only.conf;
    
    # block common exploits, sql injections etc
    #include /usr/local/nginx/conf/block.conf;
    
      # Enables directory listings when index file not found
      #autoindex  on;
    
      # Shows file listing times as local time
      #autoindex_localtime on;
    
      # Enable for vBulletin usage WITHOUT vbSEO installed
      # More example Nginx vhost configurations at
      # http://centminmod.com/nginx_configure.html
      #try_files    $uri $uri/ /index.php;
    
      }
    
      include /usr/local/nginx/conf/staticfiles.conf;
      include /usr/local/nginx/conf/php.conf;
      include /usr/local/nginx/conf/drop.conf;
      #include /usr/local/nginx/conf/errorpage.conf;
      include /usr/local/nginx/conf/vts_server.conf;
    }
    
     
    Last edited: Sep 30, 2016
    • Winner Winner x 2
    • Like Like x 1
  6. eva2000

    eva2000 Administrator Staff Member

    37,227
    8,132
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +12,520
    Local Time:
    10:52 AM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    • Like Like x 1
..
Thread Status:
Not open for further replies.