Redirect to proper messages tab after bulk update
[gitorious.git] / script / upgrade_to
bloba7d0b5d49e643650d66f982a6435c7310bc6257d
1 #!/usr/bin/env ruby
3 # Standard upgrade command to upgrade the Gitorious installation to a
4 # newer tagged version.
6 # Usage:
7 # script/upgrade_to <VERSION_TAG_NAME>
9 # Example:
10 # script/upgrade_to v2.2.1
12 # You can determine your current version and the next version by running:
13 # bundle exec rake versioning:changelog
14 # This will tell you both your current version and what newer tagged versions exist.
16 # Note: an undo point is saved each time this command is run, so a
17 # failed run can be reversed by running script/undo_last_upgrade (note
18 # that each execution of /upgrade_to overwrites the undo point, so
19 # only do one upgrade at a time.)
21 # Assumptions:
22 # 1: If you are several versions behind, only upgrade one tagged version at a time.
23 # 2: Always perform a manual, extra backup (/script/snapshot) before attempting an upgrade
24 # 3: Take the Gitorious installation offline to prevent users from using it while upgrading
25 # 4: Before going through with the upgrade, check relevant release notes for any breaking changes,
26 # (particularly important for any major version upgrades)
29 if Process.uid != 0
30 puts "Please run the task as superuser/root!"
31 exit
32 end
34 if !ARGV[0]
35 puts "Usage:"
36 puts "script/upgrade_to <tag>"
37 exit
38 end
40 new_tag = ARGV[0]
42 def backup_db
43 require_relative '../lib/gitorious/configuration_reader'
44 conf = Gitorious::ConfigurationReader.read('config/database.yml')
45 db_name = conf['production']['database']
46 puts `mysqldump #{db_name} > /tmp/upgrade_db_backup.sql`
47 end
49 def backup_working_directory
50 puts `rm -f /tmp/upgrade_working_dir_backup.tar && tar -czf /tmp/upgrade_working_dir_backup.tar .`
51 end
53 def prepare_undo_data
54 backup_db
55 backup_working_directory
56 end
58 puts "UPGRADE: About to attempt Gitorious upgrade. Please backup first. Proceed with upgrade? (y/n)"
59 response = $stdin.gets.chomp
60 if response != "y"
61 puts "UPGRADE: Quit."
62 exit
63 end
65 puts "UPGRADE: Attempting upgrade to #{new_tag}..."
67 puts "UPGRADE: Fetching latest Gitorious code from the origin remote (should be gitorious.org)..."
68 puts `git fetch origin`
70 puts "UPGRADE: Preparing data needed by script/undo_last_upgrade..."
71 prepare_undo_data
73 puts "UPGRADE: Git checking out the '#{new_tag}' tag"
74 puts `git checkout #{new_tag}`
76 puts "UPGRADE: Updating submodules..."
77 puts `git submodule init`
79 puts "UPGRADE: Upgrading gem dependencies via Bundler..."
80 puts `bundle install`
82 puts "UPGRADE: Migrating database..."
83 puts `env RAILS_ENV=production bundle exec rake db:migrate`
85 puts "UPGRADE: Clearing asset pipeline..."
86 puts `env RAILS_ENV=production bundle exec rake assets:clear`
88 puts "UPGRADE: Restarting Gitorious..."
89 puts `script/restart`
91 puts "UPGRADE: Done, upgraded to #{new_tag}."
92 puts "\nATTENTION: Please test and verify that your site works as expected. If any errors occur, rollback to the pre-upgrade state with script/undo_last_upgrade"