Install/Upgrade Scripts - Can they run multiple times when multiple users are hitting the site before they are done?

magento.stackexchange https://magento.stackexchange.com/questions/3078

  •  16-10-2019
  •  | 
  •  

Question

We have a couple of updates that we'd like to run by way of a module's upgrade script. One of them takes about 5 minutes to complete.

The problem here that we are not sure about is that the site is very active.

So when we push the upgrade script to production, how will it behave?

Will the upgrade script continually be run multiple times when people are hitting the site until one instance of it is finally complete?

Is Magento smart enough to only run one instance of it (even if it is not completed yet and other people are hitting the site)?

We are on Magento EE 1.9.

Was it helpful?

Solution

In theory, yes. I have seen upgrade scripts run multiple times - which is why any upgrade script I create that loads CMS, EAV or other Attribute information typically is coded to safeguard against multiple insertion.

Best Practice:

Using SSH, run the following from your Magento document root:

touch maintenance.flag

This will create a file called 'maintenance.flag' in your Magento root that will effectively pull your store offline during this upgrade. 5 minutes of downtime should be relatively safe if you run in your off-peak or overnight hours.

Upgrade your Magento Store by running an update/pull from your source control checkout or via your preferred method of deployment. To execute your upgrade you can issue:

php index.php - again from the document root. This will kick off your upgrade.

You can allow yourself access to the CMS portion (if you rather not run the upgrade script yourself via SSH) by implementing an index.php workaround (read: hack) that allows specific IP addresses access by skipping the check of the maintenance.flag file:

$ip = $_SERVER['REMOTE_ADDR'];

$allowed = array('1.1.1.1','2.2.2.2'); // these are the IP's allowed

And replace this line:

if (file_exists($maintenanceFile)) {

with this line:

if (file_exists($maintenanceFile) && !in_array($ip, $allowed)) { 

Source: http://inchoo.net/ecommerce/magento/maintenance-mode-in-magento/

In short, recovery to clean up multiple executions of the upgrade will potentially result in longer downtime than if you had just taken the store down to begin with. Plan your maintenance and practice it in your staging environment many times before executing your upgrade.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top