migrate.sh 6.8 KB
Newer Older
1 2
#!/usr/bin/env bash

3 4 5
# Stop if any command fails
set -e

6
# defaults
7 8
CONFIGURATION="none"
TARGET="none"
9
INTERACTIVE=true
10
OPENEDX_ROOT="/edx"
11

12 13 14 15
show_help () {
  cat <<- EOM

Migrates your Open edX installation to a different release.
16 17

-c CONFIGURATION
18 19
    Use the given configuration. Either \"devstack\" or \"fullstack\". You
    must specify this.
20
-t TARGET
21 22
    Migrate to the given git ref. You must specify this.  Named releases are
    called \"named-release/cypress\", \"named-release/dogwood.rc2\", and so on.
23 24
-y
    Run in non-interactive mode (reply \"yes\" to all questions)
David Baumgold committed
25 26 27
-r OPENEDX_ROOT
    The root directory under which all Open edX applications are installed.
    Defaults to \"$OPENEDX_ROOT\"
28 29
-h
    Show this help and exit.
30

31
EOM
32
}
33 34 35 36 37

# override defaults with options
while getopts "hc:t:y" opt; do
  case "$opt" in
    h)
38
      show_help
39 40 41 42 43 44 45 46 47 48 49
      exit 0
      ;;
    c)
      CONFIGURATION=$OPTARG
      ;;
    t)
      TARGET=$OPTARG
      ;;
    y)
      INTERACTIVE=false
      ;;
50 51 52
    r)
      OPENEDX_ROOT=$OPTARG
      ;;
53 54 55
  esac
done

56 57 58 59
# Helper to ask to proceed.
confirm_proceed () {
  echo "Do you wish to proceed?"
  read input
60
  if [[ "$input" != "yes" && "$input" != "y" ]]; then
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
    echo "Quitting"
    exit 1
  fi
}

# Check we are in the right place, and have the info we need.

if [[ "`whoami`" != "vagrant" ]]; then
  echo "Run this from the vagrant account in your Open edX machine."
  exit 1
fi

if [[ ! -d /edx/app/edxapp ]]; then
  echo "Run this from the vagrant account in your Open edX machine."
  exit 1
fi

if [[ $TARGET == none ]]; then
  cat <<"EOM"
You must specify a target. This should be the next named release after the one
you are currently running.  This script can only move forward one release at
a time.
EOM
  show_help
  exit 1
fi

if [[ $CONFIGURATION == none ]]; then
  echo "You must specify a configuration, either fullstack or devstack."
  exit 1
fi

# Birch details

95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
if [[ $TARGET == *birch* && $INTERACTIVE == true ]] ; then
  cat <<"EOM"
          WARNING WARNING WARNING WARNING WARNING
The Birch release of Open edX depends on MySQL 5.6 and MongoDB 2.6.4.
The Aspen release of Open edX depended on MySQL 5.5 and MongoDB 2.4.7.
Please make sure that you have already upgraded MySQL and MongoDB
before continuing.

If MySQL or MongoDB are not at the correct version, this script will
attempt to automatically upgrade them for you. However, this process
can fail, and IT RUNS THE RISK OF CORRUPTING ALL YOUR DATA.
Here there be dragons.

         .>   )\;`a__
        (  _ _)/ /-." ~~
         `( )_ )/
          <_  <_

Once you have verified that your MySQL and MongoDB versions are correct,
or you have decided to risk the automatic upgrade process, type "yes"
followed by enter to continue. Otherwise, press ctrl-c to quit. You can
also run this script with the -y flag to skip this check.

EOM
119
  confirm_proceed
120 121
fi

122 123
# Cypress details

124 125 126
if [[ $TARGET == *cypress* && $INTERACTIVE == true ]] ; then
  cat <<"EOM"
          WARNING WARNING WARNING WARNING WARNING
127 128
Due to the changes introduced between Birch and Cypress, you may encounter
some problems in this migration. If so, check this webpage for solutions:
129

130
https://openedx.atlassian.net/wiki/display/OpenOPS/Potential+Problems+Migrating+from+Birch+to+Cypress
131

132
EOM
133
  confirm_proceed
134 135
fi

136
if [[ $TARGET == *cypress* ]] ; then
137
  # Needed if transitioning to Cypress.
138 139 140 141 142 143 144 145 146 147 148 149 150 151
  echo "Killing all celery worker processes."
  sudo ${OPENEDX_ROOT}/bin/supervisorctl stop edxapp_worker:* &
  sleep 3
  # Supervisor restarts the process a couple of times so we have to kill it multiple times.
  sudo pgrep -lf celery | grep worker | awk '{ print $1}' | sudo xargs -I {} kill -9 {}
  sleep 3
  sudo pgrep -lf celery | grep worker | awk '{ print $1}' | sudo xargs -I {} kill -9 {}
  sleep 3
  sudo pgrep -lf celery | grep worker | awk '{ print $1}' | sudo xargs -I {} kill -9 {}
  sleep 3
  sudo pgrep -lf celery | grep worker | awk '{ print $1}' | sudo xargs -I {} kill -9 {}
  sudo -u forum git -C ${OPENEDX_ROOT}/app/forum/.rbenv reset --hard
fi

152
if [[ -f /edx/app/edx_ansible/server-vars.yml ]]; then
David Baumgold committed
153
  SERVER_VARS="--extra-vars=\"@${OPENEDX_ROOT}/app/edx_ansible/server-vars.yml\""
154 155
fi

156 157 158 159 160 161 162
make_config_venv () {
  virtualenv venv
  source venv/bin/activate
  pip install -r configuration/pre-requirements.txt
  pip install -r configuration/requirements.txt
}

163
TEMPDIR=`mktemp -d`
164
echo "Working in $TEMPDIR"
165 166
chmod 777 $TEMPDIR
cd $TEMPDIR
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
# Set the CONFIGURATION_TARGET environment variable to use a different branch
# in the configuration repo, defaults to $TARGET.
git clone https://github.com/edx/configuration.git \
  --depth=1 --single-branch --branch=${CONFIGURATION_TARGET-$TARGET}
make_config_venv

# Dogwood details

if [[ $TARGET == *dogwood* ]] ; then
  # We are upgrading Python from 2.7.3 to 2.7.10, so remake the venvs.
  sudo rm -rf /edx/app/*/v*envs/*

  echo "Upgrading to the end of Django 1.4"
  cd configuration/playbooks/vagrant
  sudo ansible-playbook \
    --inventory-file=localhost, \
    --connection=local \
    $SERVER_VARS \
    --extra-vars="edx_platform_version=release-2015-11-09" \
    --extra-vars="xqueue_version=named-release/cypress" \
    --extra-vars="migrate_db=yes" \
    --skip-tags="edxapp-sandbox" \
    vagrant-$CONFIGURATION-delta.yml
  cd ../../..

  # Remake our own venv because of the Python 2.7.10 upgrade.
  rm -rf venv
  make_config_venv

  # Need to get rid of South from edx-platform, or things won't work.
  sudo -u edxapp /edx/app/edxapp/venvs/edxapp/bin/pip uninstall -y South

  echo "Upgrading to the beginning of Django 1.8"
  cd configuration/playbooks/vagrant
  sudo ansible-playbook \
    --inventory-file=localhost, \
    --connection=local \
    $SERVER_VARS \
205
    --extra-vars="edx_platform_version=dogwood-first-18" \
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230
    --extra-vars="xqueue_version=dogwood-first-18" \
    --extra-vars="migrate_db=no" \
    --skip-tags="edxapp-sandbox" \
    vagrant-$CONFIGURATION-delta.yml
  cd ../../..

  echo "Running the Django 1.8 faked migrations"
  for item in lms cms; do
    sudo -u edxapp \
      /edx/app/edxapp/venvs/edxapp/bin/python \
      /edx/app/edxapp/edx-platform/manage.py $item migrate \
      --settings=aws --noinput --fake-initial
  done

  if [[ $CONFIGURATION == fullstack ]] ; then
    sudo -u xqueue \
    SERVICE_VARIANT=xqueue \
    /edx/app/xqueue/venvs/xqueue/bin/python \
    /edx/app/xqueue/xqueue/manage.py migrate \
    --settings=xqueue.aws_settings --noinput --fake-initial
  fi
fi

cd configuration/playbooks
echo "edx_platform_version: $TARGET" > vars.yml
231 232 233 234
echo "ora2_version: $TARGET" >> vars.yml
echo "certs_version: $TARGET" >> vars.yml
echo "forum_version: $TARGET" >> vars.yml
echo "xqueue_version: $TARGET" >> vars.yml
235
sudo ansible-playbook \
236 237
    --inventory-file=localhost, \
    --connection=local \
238
    --extra-vars="@vars.yml" \
239 240
    $SERVER_VARS \
    vagrant-$CONFIGURATION.yml
241

242
cd /
243
sudo rm -rf $TEMPDIR
244
echo "Migration complete. Please reboot your machine."