]> gitweb.fluxo.info Git - hydra.git/commitdiff
Implementing run stages to system-upgrade
authorSilvio Rhatto <rhatto@riseup.net>
Tue, 24 Dec 2013 21:16:45 +0000 (19:16 -0200)
committerSilvio Rhatto <rhatto@riseup.net>
Tue, 24 Dec 2013 21:16:45 +0000 (19:16 -0200)
share/hydractl/system-upgrade

index f7fc8516d4b2f3ee7c728fcc9a4e158a125cb594..bd40343544a934467408a6197331b0a88d9b5c8f 100755 (executable)
 source $APP_BASE/lib/hydra/functions || exit 1
 hydra_config_load
 
+# Parameters
+TMP="/tmp"
+STATE="$TMP/system-upgrade"
+
 # Command line arguments
 BASENAME="`basename $0`"
 NEXTRELEASE="$1"
 
+# Record current state of the upgrade
+function hydra_system_upgrade_stage {
+  STAGE="$1"
+  echo $STAGE > $STATE
+}
+
 # Prepare the environment for a system upgrade
 function hydra_system_upgrade_prepare {
+  # Set initial state
+  hydra_system_upgrade_stage prepare
+
   # Available releases
   #release="`facter lsbdistcodename`" # this doesn't work on squeeze
   release="`facter 2> /dev/null | grep lsbdistcodename | sed -e 's/lsbdistcodename => //'`"
@@ -64,6 +77,8 @@ function hydra_system_upgrade_prepare {
   # These will be generated by puppet and can be safely removed
   rm -f /etc/apt/sources.list.d/*
   rm -f /etc/apt/preferences.d/*
+
+  hydra_system_upgrade_stage download
 }
 
 # Update package listing and download new packages
@@ -74,40 +89,64 @@ function hydra_system_upgrade_download {
   echo ""
   echo "Downloading packages..."
   apt-get dist-upgrade -d -y
+  hydra_system_upgrade_stage upgrade
 }
 
 # Prepare for the upgrade
-hydra_system_upgrade_prepare $*
-hydra_system_upgrade_download
+if [ ! -e "$STATE" ]; then
+  hydra_system_upgrade_prepare $*
+else
+  # Resume from the previous state
+  STAGE="`cat $STATE`"
+fi
+
+# Download packages
+if [ "$STAGE" == "download" ]; then
+  hydra_system_upgrade_download
+fi
 
 # Upgrade the system
-echo ""
-echo "Upgrading the system..."
-DEBIAN_FRONTEND=noninteractive apt-get dist-upgrade
+if [ "$STAGE" == "upgrade" ]; then
+  echo ""
+  echo "Upgrading the system..."
+  DEBIAN_FRONTEND=noninteractive apt-get dist-upgrade
 
-if [ "$?" != "0" ]; then
-  echo "Upgrade failed. Please fix it manually and run this command again."
-  exit 1
-fi
+  if [ "$?" != "0" ]; then
+    echo "Upgrade failed. Please fix it manually and run this command again."
+    exit 1
+  fi
 
-# Remove unused packages
-apt-get autoremove
+  hydra_system_upgrade_stage cleanup
+fi
 
-# Cleanup package cache
-apt-get clean
+# Cleanup
+if [ "$STAGE" == "cleanup" ]; then
+  apt-get autoremove
+  apt-get clean
+  hydra_system_upgrade_stage custom
+fi
 
 # Custom procedures
-if [ "$nextrelease" == "wheezy" ]; then
-  # Old suhosin config
-  rm -f /etc/php5/conf.d/suhosin.ini
-
-  # This has to be manually installed again
-  if [ -f "/etc/php5/cli/conf.d/uploadprogress.ini" ]; then
-    pecl upgrade uploadprogress
+if [ "$STAGE" == "custom" ]; then
+  if [ "$nextrelease" == "wheezy" ]; then
+    # Old suhosin config
+    rm -f /etc/php5/conf.d/suhosin.ini
+
+    # This has to be manually installed again
+    if [ -f "/etc/php5/cli/conf.d/uploadprogress.ini" ]; then
+      pecl upgrade uploadprogress
+    fi
   fi
+
+  hydra_system_upgrade_stage puppet
 fi
 
 # Enable puppet again
-echo ""
-echo "Starting puppet again..."
-hydractl puppet-enable
+if [ "$STAGE" == "puppet" ]; then
+  echo ""
+  echo "Starting puppet again..."
+  hydractl puppet-enable
+fi
+
+# Teardown
+rm -f $STATE