Merge branch '6263-go-coverage' refs #6263
[arvados-dev.git] / jenkins / arvados-workbench-extras / arvados-workbench-upgrade.sh
1 #!/bin/bash
2
3 set -e
4
5 if [ -e /etc/redhat-release ]; then
6     WWW_OWNER=nginx:nginx
7 else
8     # Assume we're on a Debian-based system for now.
9     WWW_OWNER=www-data:www-data
10 fi
11
12 NGINX_SERVICE=${NGINX_SERVICE:-$(service --status-all 2>/dev/null \
13     | grep -Eo '\bnginx[^[:space:]]*' || true)}
14 if [ -z "$NGINX_SERVICE" ]; then
15     cat >&2 <<EOF
16 Error: nginx service not found. Aborting.
17 Set NGINX_SERVICE to the name of the service hosting the Rails server.
18 EOF
19     exit 1
20 elif [ "$NGINX_SERVICE" != "$(echo "$NGINX_SERVICE" | head -n 1)" ]; then
21     cat >&2 <<EOF
22 Error: multiple nginx services found. Aborting.
23 Set NGINX_SERVICE to the name of the service hosting the Rails server.
24 EOF
25     exit 1
26 fi
27
28 RELEASE_PATH=/var/www/arvados-workbench/current
29 SHARED_PATH=/var/www/arvados-workbench/shared
30 CONFIG_PATH=/etc/arvados/workbench/
31
32 echo "Assumption: $NGINX_SERVICE is configured to serve your workbench URL from "
33 echo "            /var/www/arvados-workbench/current"
34 echo "Assumption: configuration files are in /etc/arvados/workbench/"
35 echo "Assumption: $NGINX_SERVICE and passenger run as $WWW_OWNER"
36 echo
37
38 echo "Copying files from $CONFIG_PATH"
39 cp -f $CONFIG_PATH/application.yml $RELEASE_PATH/config/application.yml
40 cp -f $RELEASE_PATH/config/environments/production.rb.example $RELEASE_PATH/config/environments/production.rb
41 echo "Done."
42
43 # Before we do anything else, make sure some directories and files are in place
44 if [[ ! -e $SHARED_PATH/log ]]; then mkdir -p $SHARED_PATH/log; fi
45 if [[ ! -e $RELEASE_PATH/tmp ]]; then mkdir -p $RELEASE_PATH/tmp; fi
46 if [[ ! -e $RELEASE_PATH/log ]]; then ln -s $SHARED_PATH/log $RELEASE_PATH/log; fi
47 if [[ ! -e $SHARED_PATH/log/production.log ]]; then touch $SHARED_PATH/log/production.log; fi
48
49 echo "Running bundle install"
50 (cd $RELEASE_PATH && RAILS_ENV=production bundle install --path $SHARED_PATH/vendor_bundle)
51 echo "Done."
52
53 # We do not need to precompile assets, they are already part of the package.
54
55 echo "Ensuring directory and file permissions"
56 chown "$WWW_OWNER" $RELEASE_PATH/config/environment.rb
57 chown "$WWW_OWNER" $RELEASE_PATH/config.ru
58 chown "$WWW_OWNER" $RELEASE_PATH/config/database.yml
59 chown "$WWW_OWNER" $RELEASE_PATH/Gemfile.lock
60 chown -R "$WWW_OWNER" $RELEASE_PATH/tmp
61 chown -R "$WWW_OWNER" $SHARED_PATH/log
62 chown "$WWW_OWNER" $RELEASE_PATH/db/schema.rb
63 chmod 644 $SHARED_PATH/log/*
64 echo "Done."
65
66 echo "Running sanity check"
67 (cd $RELEASE_PATH && RAILS_ENV=production bundle exec rake config:check)
68 SANITY_CHECK_EXIT_CODE=$?
69 echo "Done."
70
71 if [[ "$SANITY_CHECK_EXIT_CODE" != "0" ]]; then
72   echo "Sanity check failed, aborting. Please roll back to the previous version of the package."
73   exit $SANITY_CHECK_EXIT_CODE
74 fi
75
76 # We do not need to run db:migrate because Workbench is stateless
77
78 echo "Restarting nginx"
79 service "$NGINX_SERVICE" restart
80 echo "Done."
81