Commit d25a2f8ff4714fa4f252d1bdbe9653a7a9ec7c5f

Authored by Antonio Terceiro
1 parent b66e8d1e

Organizing components of the upgrade script

Showing 1 changed file with 65 additions and 42 deletions   Show diff stats
script/git-upgrade
@@ -4,6 +4,10 @@ set -e @@ -4,6 +4,10 @@ set -e
4 4
5 export RAILS_ENV=production 5 export RAILS_ENV=production
6 6
  7 +say(){
  8 + echo -e "\033[33;01m$0: $1\033[m"
  9 +}
  10 +
7 get_value(){ 11 get_value(){
8 ruby -ryaml -e "puts YAML.load_file('config/database.yml')['$RAILS_ENV']['$1']" 12 ruby -ryaml -e "puts YAML.load_file('config/database.yml')['$RAILS_ENV']['$1']"
9 } 13 }
@@ -29,6 +33,62 @@ version(){ @@ -29,6 +33,62 @@ version(){
29 exit 0 33 exit 0
30 } 34 }
31 35
  36 +backup(){
  37 + say "Making files backup"
  38 + rake backup
  39 +
  40 + database=$(get_value database)
  41 + adapter=$(get_value adapter)
  42 +
  43 + if [ "$adapter" = "postgresql" ]; then
  44 + mkdir -p backups/
  45 + dumpfile=backups/dump-$(date +%Y-%m-%d-%H-%M).sql
  46 + say "Making database backup"
  47 + pg_dump "$database" > "$dumpfile"
  48 + fi
  49 +}
  50 +
  51 +stop_service(){
  52 + say "Stopping service"
  53 + ./script/production stop || say "Stop failed, trying to continue anyway"
  54 + sudo /etc/init.d/memcached restart
  55 +}
  56 +
  57 +start_service(){
  58 + say "Starting service"
  59 + ./script/production start
  60 +}
  61 +
  62 +upgrade_code(){
  63 + say "Upgrading code"
  64 + git pull
  65 + for dir in public/designs/themes/*; do
  66 + (cd $dir && test -e .git/config && git pull)
  67 + done
  68 + rake makemo
  69 +}
  70 +
  71 +upgrade_database(){
  72 + say "Upgrading database"
  73 +
  74 + rake db:migrate
  75 +
  76 + if test "$shell" = "yes"; then
  77 + echo "################################################"
  78 + echo "# Noosfero upgrade shell #"
  79 + echo "################################################"
  80 + echo "# #"
  81 + echo "# If you need to do any manual steps during #"
  82 + echo "# this upgrade, now is the time. #"
  83 + echo "# #"
  84 + echo "# After you finish, just exit this shell and #"
  85 + echo "# the upgrade will proceed #"
  86 + echo "################################################"
  87 + export PS1="[Noosfero upgrade] $PS1"
  88 + bash --rcfile config/bashrc
  89 + fi
  90 +}
  91 +
32 shell=no 92 shell=no
33 while test $# -gt 0; do 93 while test $# -gt 0; do
34 case "$1" in 94 case "$1" in
@@ -48,45 +108,8 @@ while test $# -gt 0; do @@ -48,45 +108,8 @@ while test $# -gt 0; do
48 shift 108 shift
49 done 109 done
50 110
51 -  
52 -./script/production stop || echo "Stop failed, trying to continue anyway"  
53 -  
54 -sudo /etc/init.d/memcached restart  
55 -  
56 -rake backup  
57 -  
58 -database=$(get_value database)  
59 -adapter=$(get_value adapter)  
60 -  
61 -if [ "$adapter" = "postgresql" ]; then  
62 - mkdir -p backups/  
63 - backup=backups/dump-$(date +%Y-%m-%d-%H-%M).sql  
64 - pg_dump "$database" > "$backup"  
65 -fi  
66 -  
67 -git pull  
68 -  
69 -for dir in public/designs/themes/*; do  
70 - (cd $dir && test -e .git/config && git pull)  
71 -done  
72 -  
73 -rake db:migrate  
74 -  
75 -if test "$shell" = "yes"; then  
76 - echo "################################################"  
77 - echo "# Noosfero upgrade shell #"  
78 - echo "################################################"  
79 - echo "# #"  
80 - echo "# If you need to do any manual steps during #"  
81 - echo "# this upgrade, now is the time. #"  
82 - echo "# #"  
83 - echo "# After you finish, just exit this shell and #"  
84 - echo "# the upgrade will proceed #"  
85 - echo "################################################"  
86 - export PS1="[Noosfero upgrade] $PS1"  
87 - bash --rcfile config/bashrc  
88 -fi  
89 -  
90 -rake makemo  
91 -  
92 -./script/production start 111 +backup
  112 +stop_service
  113 +upgrade_code
  114 +upgrade_database
  115 +start_service