Create a manual fallback recovery system if update fails during the Apply phase

Created on 3 May 2022, over 2 years ago
Updated 14 February 2023, almost 2 years ago

Problem/Motivation

If calls to Composer Stager fail your active site will be unaffected except if the fail happens during apply().
In that case you site will be in an unknown state. Some files could have been copied over but not all. Your site might load but still not be completely updated or you site might not load at all.

Proposed resolution

Create a manual way to recover after failed update that happens in apply()
This would require access to the command line but could be relatively simple process to follow

  1. before apply make a copy of the original composer files call composer.json.original composer.lock.original
  2. From a starter template file dynamically create a update-recovery.php that will be placed in the Drupal root and with the same file permissions as index.php

    This will file will need 2 dynamic aspects
    1. the path to composer as known to Package Manager
    2. a dynamically create security key as it will not be able to rely on Drupal permissions

  3. On the "Apply Update" form the user should be prompted to save a "Recovery link" which will be something like mysite.com/update-recovery.php?key=very-long-random-key
    This link could also be emailed to the site admin
  4. Post apply when the site is a known good state delete composer.json.original composer.lock.original, update-recovery.php
  5. If composer.json.original exist then apply failed
  6. Package Manager should check for those files if they are present inform admin that apply probably failed(in the case site loads at all)

    If the admin can still login in they should be presented with the mysite.com/update-recovery.php?key=very-long-random-key link. We might want to stop all other actions on the site because even if the user can login it will be in an undetermined state, likely insecure

  7. update-recovery.php

    would perform these steps to recover the site

    1. check for the correct random key in the request
    2. delete composer.lock and composer.json (this may pre or post update versions depending on when the Apply failed
    3. rename composer.lock.orignal and composer.json.original
    4. run composer install (with the composer at the path that was provide dynamically)
    5. Inform the user if the operation was successful and if so that site not pre-update state, We could dynamically set a message when we create this fail.

  8. update-recovery.php should also include in comment at the top instructions on how to fix the site manually
πŸ“Œ Task
Status

Active

Version

3.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States tedbow Ithaca, NY, USA

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024