5 if [ -e /etc/redhat-release ]; then
8 # Assume we're on a Debian-based system for now.
9 WWW_OWNER=www-data:www-data
12 NGINX_SERVICE=${NGINX_SERVICE:-$(service --status-all 2>/dev/null \
13 | grep -Eo '\bnginx[^[:space:]]*' || true)}
14 if [ -z "$NGINX_SERVICE" ]; then
16 Error: nginx service not found. Aborting.
17 Set NGINX_SERVICE to the name of the service hosting the Rails server.
20 elif [ "$NGINX_SERVICE" != "$(echo "$NGINX_SERVICE" | head -n 1)" ]; then
22 Error: multiple nginx services found. Aborting.
23 Set NGINX_SERVICE to the name of the service hosting the Rails server.
28 RELEASE_PATH=/var/www/arvados-api/current
29 SHARED_PATH=/var/www/arvados-api/shared
30 CONFIG_PATH=/etc/arvados/api/
32 echo "Assumption: $NGINX_SERVICE is configured to serve your API server URL from"
33 echo " /var/www/arvados-api/current"
34 echo "Assumption: configuration files are in /etc/arvados/api/"
35 echo "Assumption: $NGINX_SERVICE and passenger run as $WWW_OWNER"
38 echo "Copying files from $CONFIG_PATH"
39 cp -f $CONFIG_PATH/database.yml $RELEASE_PATH/config/database.yml
40 cp -f $RELEASE_PATH/config/environments/production.rb.example $RELEASE_PATH/config/environments/production.rb
41 cp -f $CONFIG_PATH/application.yml $RELEASE_PATH/config/application.yml
42 if [ -e $CONFIG_PATH/omniauth.rb ]; then
43 cp -f $CONFIG_PATH/omniauth.rb $RELEASE_PATH/config/initializers/omniauth.rb
47 # Before we do anything else, make sure some directories and files are in place
48 if [[ ! -e $SHARED_PATH/log ]]; then mkdir -p $SHARED_PATH/log; fi
49 if [[ ! -e $RELEASE_PATH/tmp ]]; then mkdir -p $RELEASE_PATH/tmp; fi
50 if [[ ! -e $RELEASE_PATH/log ]]; then ln -s $SHARED_PATH/log $RELEASE_PATH/log; fi
51 if [[ ! -e $SHARED_PATH/log/production.log ]]; then touch $SHARED_PATH/log/production.log; fi
54 export RAILS_ENV=production
56 echo "Making sure bundle is installed"
58 which bundle > /dev/null
59 if [[ "$?" != "0" ]]; then
65 echo "Running bundle install"
66 bundle install --path $SHARED_PATH/vendor_bundle
69 echo "Precompiling assets"
70 # precompile assets; thankfully this does not take long
71 bundle exec rake assets:precompile
74 echo "Ensuring directory and file permissions"
75 # Ensure correct ownership of a few files
76 chown "$WWW_OWNER" $RELEASE_PATH/config/environment.rb
77 chown "$WWW_OWNER" $RELEASE_PATH/config.ru
78 chown "$WWW_OWNER" $RELEASE_PATH/config/database.yml
79 chown "$WWW_OWNER" $RELEASE_PATH/Gemfile.lock
80 chown -R "$WWW_OWNER" $RELEASE_PATH/tmp
81 chown -R "$WWW_OWNER" $SHARED_PATH/log
82 chown "$WWW_OWNER" $RELEASE_PATH/db/structure.sql
83 chmod 644 $SHARED_PATH/log/*
84 # Rails creates the cache directory if it doesn't exist
85 if [[ -d $RELEASE_PATH/tmp/cache/ ]]; then
86 chmod -R 2775 $RELEASE_PATH/tmp/cache/
90 echo "Running sanity check"
91 bundle exec rake config:check
92 SANITY_CHECK_EXIT_CODE=$?
95 if [[ "$SANITY_CHECK_EXIT_CODE" != "0" ]]; then
96 echo "Sanity check failed, aborting. Please roll back to the previous version of the package."
97 echo "The database has not been migrated yet, so reinstalling the previous version is safe."
98 exit $SANITY_CHECK_EXIT_CODE
101 echo "Checking database status"
102 # If we use `grep -q`, rake will write a backtrace on EPIPE.
103 if bundle exec rake db:migrate:status | grep '^database: ' >/dev/null; then
104 echo "Starting db:migrate"
105 bundle exec rake db:migrate
106 elif [ 0 -eq ${PIPESTATUS[0]} ]; then
107 # The database exists, but the migrations table doesn't.
108 echo "Setting up database"
109 bundle exec rake db:structure:load db:seed
111 echo "Error: Database is not ready to set up. Aborting." >&2
116 echo "Restarting nginx"
117 service "$NGINX_SERVICE" restart