Updating MODx Revolution with zero* downtime

Introduction

I searched the web around for a comprehensive guide for updating a modx revolution installation possibly without much downtime within the 2.2.x branch.

In the end i found a good way to do so, even with more installations which need to be updated at once.

Basic structure

Our installations follow a simple but effective way. Our webserver (Apache2/Nginx) does not point to the modx directory directly but instead to a symlink, so youre able to easily switch between versions by invoking a shell one-liner.
Here is the classic and recommended structure which you should always use for all applications. It will make your life easier.

Classic:

Webserver --(DocumentRoot)>> /var/www/modx-2.2.8-pl

Recommended:

Webserver --(DocumentRoot)>> /var/www/modx-production --(Symlink)>> /var/www/modx-2.2.8-pl

Make a working copy for the Update

At first we will make a copy of the running installation. I assume you're doing all steps as root. Name the new folder like the new version which is going to be installed (as of today its 2.2.14-pl), so you always know which version you have! Also reapply the correct ownership.

cd /var/www && cp -r modx-2.2.8-pl modx-2.2.14-pl && chown -R www-data:www-data modx-2.2.14-pl

Do a backup and run the upgrade

MODX itself released two small PHP scripts you can use for backing up your database and files as well as updating to the latest modx installation. I copied those scripts and modified them a bit to work better directly from the commandline (php-cli!)

Copy both scripts into the modx-2.2.14-pl folder.

Backup-Script:

https://gist.github.com/martinseener/7a08e22c4b091e9286a7

Upgrade-Script:

https://gist.github.com/martinseener/63a9c1ec6ed0e451d3d7

Then run the backup script followed by the upgrade script. The Backup script will create the backups in ../backup by default and the upgrade script will download the latest stable modx and installs its files in the current folder.

php modx-revolution-backup.php && php modx-revolution-upgrade.php

Recreate the new Symlink and finish the setup

In this step a *super-minimal downtime occurs while deleting the old symlink and recreating the new one which is at most a millisecond.

Let us delete the old symlink and create the new one. After that you have to finish the setup/upgrade procedure by opening up your websites setup again.

Recreate Symlink:

cd /var/www && rm modx-production && ln -s modx-2.2.14-pl modx-production

Opening up Setup:

www.yourdomain.com/setup

There you just need to continue with your language and the upgrade option. All the default settings should be absolutely fine there, just finish it up and you're (almost) done.

Check the config and packages for hardcoded paths

It came quickly to my attention, that the update does not properly handle those hardcoded paths within core/config/config.inc.php and packages beneath core/packages/plugin-1.0.0-pl/preserved.php. Be sure you check those as well and update all the paths.

You can easily find old ones by searching for it using:

cd /path/to/modx && grep -r "2.2.8-pl" ./ | grep -v "code/cache"

Change all old paths and you're done.

Optional: Update MODX-Packages

As an optional step, login to your updated MODX Installation and go to System -> Packet Management and update all Packages there where Upates exist.

You're done now.