#!/bin/sh set -e INSTALL_PATH=/var/www/arvados-sso RELEASE_PATH=$INSTALL_PATH/current SHARED_PATH=$INSTALL_PATH/shared CONFIG_PATH=/etc/arvados/sso VERSION=`cat $RELEASE_PATH/git-commit.version` setup_ruby_environment() { if [ -s "$HOME/.rvm/scripts/rvm" ] ; then using_rvm="true" elif [ -s "/usr/local/rvm/scripts/rvm" ] ; then using_rvm="true" else using_rvm="false" fi if [ "$using_rvm" = "true" ]; then COMMAND_PREFIX="/usr/local/rvm/bin/rvm-exec default" else COMMAND_PREFIX= fi } # arguments: configure_version() { VERSION="$1" [ "$VERSION" ] || { echo "Error: configure_version: need version parameter" >&2; exit 1; } if [ -e /etc/redhat-release ]; then WWW_OWNER=nginx:nginx else # Assume we're on a Debian-based system for now. WWW_OWNER=www-data:www-data fi NGINX_SERVICE=${NGINX_SERVICE:-$(service --status-all 2>/dev/null \ | grep -Eo '\bnginx[^[:space:]]*' || true)} if [ -z "$NGINX_SERVICE" ]; then cat >&2 <&2 </dev/null` DB_MIGRATE_STATUS_CODE=$? set -e if echo $DB_MIGRATE_STATUS | grep 'Schema migrations table does not exist yet.' >/dev/null; then # The database exists, but the migrations table doesn't. echo -n "Setting up database ..." $COMMAND_PREFIX bundle exec rake db:schema:load db:seed || exit $? elif echo $DB_MIGRATE_STATUS | grep '^database: ' >/dev/null; then echo -n "Running db:migrate ..." $COMMAND_PREFIX bundle exec rake db:migrate || exit $? else echo "Error: Database is not ready to set up. Aborting." >&2 exit 1 fi echo "... done." echo -n "Precompiling assets ..." # precompile assets; thankfully this does not take long $COMMAND_PREFIX bundle exec rake assets:precompile -q -s || exit $? chown -R "$WWW_OWNER" $RELEASE_PATH/tmp echo "... done." echo -n "Restarting nginx ..." service "$NGINX_SERVICE" restart || exit $? echo "... done." echo } if [ "$1" = configure ]; then setup_ruby_environment configure_version $VERSION "$2" fi