A unified way of putting a web application under maintenance using web server strategies. The maintenance mode will cut off all requests and it will replies with a static html file and a 503 header (Service Unavailable).
Those conditions will ensure that a load balancer cut an instance off during a maintenance
In composer.json add the requirement. The current version requires at least PHP 7.2 and a supported version of Symfony (3.4, 4.2, 4.3, 4.4 and 5.0).
"require": {
"corley/maintenance-bundle": "^0.3"
}To support earlier versions e.g. SF 2.x, 3.3, 4.1 etc or PHP less than 7.2 you will need to use:
"require": {
"corley/maintenance-bundle": "^0.2"
}This version can also be used for more recent Symfony versions, e.g. with 3.4 or 4.4 but is not compatible with Symfony 5 - only 0.3 can be used there because of changes to the event structure in Symfony 5.0.
For pre-Flex applications register the bundle in AppKernel.php
public function registerBundles()
{
...
$bundles = array(
...
new Corley\MaintenanceBundle\CorleyMaintenanceBundle(),
);
...
return $bundles;
}For projects built with recent versions of Flex, a default recipe will be generated which will add the bundle to your bundles.php. In older versions of Flex you may need to do this yourself
Corley\MaintenanceBundle\CorleyMaintenanceBundle::class => ['all' => true],When you want to put your web application under maintenance
bin/console corley:maintenance:lock onRestore the application status
bin/console corley:maintenance:lock offIf you use Apache2 you have to add a few lines to your .htaccess, for nginx just add dedicated
lines to web app configuration.
Make sure that those lines precede any other rewrite rule.
The mod_rewrite module in Apache2 has to be installed and enabled.
In order to obtain your configuration options use the console
bin/console corley:maintenance:dump-apachebin/console corley:maintenance:dump-nginxYou can configure the bundle in order to change the default behaviour (all options have a default value)
For projects not using Flex
# config.yml
corley_maintenance:
page: %kernel.root_dir%/../web/maintenance.dist.html
hard_lock: lock.html
symlink: falseFor Flex projects
# config/packages/corley.yml
corley_maintenance:
page: %kernel.project_dir%/templates/maintenance.dist.html
hard_lock: lock.html
symlink: falseOptions:
pageis the original maintenance page (default:vendor/corley/maintenance-bundle/Corley/MaintenanceBundle/Resources/views/maintenance.html)symlinkIf you want to use symlinks instead hardcopy strategy (default: hardcopy)hard_lockIs the name used in order to lock the website (default:hard.lock)webpublic folder (defaultwebfolder, for Flex projects you will need to configure this for your public folder, i.e.%kernel.project_dir%/public)soft_lockIs the name used in order to lock the website (using app layer)whitelistAuthorized connections [soft-lock only]pathsA list of paths that skip the maintenance lockipsA list of ips that skip the maintenance lock
The soft locking strategy uses the php layer in order to lock down the website. This means that the application must work in order to lock down the web site.
The soft lock runs at kernel.request and stops other event propagation.
When you want to put your web application under maintenance using a soft-locking strategy:
bin/console corley:maintenance:soft-lock onRestore the application status
bin/console corley:maintenance:soft-lock off