5 INSTALL_PATH=/var/www/arvados-sso
6 RELEASE_PATH=$INSTALL_PATH/current
7 SHARED_PATH=$INSTALL_PATH/shared
8 CONFIG_PATH=/etc/arvados/sso
10 VERSION=`cat $RELEASE_PATH/git-commit.version`
12 setup_ruby_environment() {
13 if [ -s "$HOME/.rvm/scripts/rvm" ] ; then
15 elif [ -s "/usr/local/rvm/scripts/rvm" ] ; then
21 if [ "$using_rvm" = "true" ]; then
22 COMMAND_PREFIX="/usr/local/rvm/bin/rvm-exec default"
28 # arguments: <major version> <most recently configured package version>
32 [ "$VERSION" ] || { echo "Error: configure_version: need version parameter" >&2; exit 1; }
34 WEB_SERVICE=${WEB_SERVICE:-$(service --status-all 2>/dev/null \
35 | grep -Eo '\bnginx|httpd[^[:space:]]*' || true)}
36 if [ -z "$WEB_SERVICE" ]; then
39 Warning: web service (Nginx or Apache) not found.
41 To override, set the WEB_SERVICE environment variable to the name of the service
42 hosting the Rails server. Alternativey, install nginx.
44 For Debian-based systems, then reconfigure this package with dpkg-reconfigure.
46 For RPM-based systems, then reinstall this package.
49 elif [ "$WEB_SERVICE" != "$(echo "$WEB_SERVICE" | head -n 1)" ]; then
50 WEB_SERVICE=$(echo "$WEB_SERVICE" | head -n 1)
52 Warning: multiple web services found. Choosing the first one ($WEB_SERVICE).
54 To override, set the WEB_SERVICE environment variable to the name of the service
55 hosting the Rails server.
57 For Debian-based systems, then reconfigure this package with dpkg-reconfigure.
59 For RPM-based systems, then reinstall this package.
64 if [ -e /etc/redhat-release ]; then
65 if [ "$WEB_SERVICE" = "nginx" ]; then
68 WWW_OWNER=apache:apache
71 # Assume we're on a Debian-based system for now.
72 # Both Apache and Nginx run as www-data by default.
73 WWW_OWNER=www-data:www-data
77 echo "Assumption: $WEB_SERVICE is configured to serve your SSO server URL from"
78 echo " /var/www/arvados-sso/current"
79 echo "Assumption: configuration files are in /etc/arvados/sso/"
80 echo "Assumption: $WEB_SERVICE and passenger run as $WWW_OWNER"
83 echo -n "Symlinking files from $CONFIG_PATH ..."
85 if [ ! -h $RELEASE_PATH/config/database.yml ]; then
86 ln -s $CONFIG_PATH/database.yml $RELEASE_PATH/config/database.yml
88 if [ ! -h $RELEASE_PATH/config/environments/production.rb ]; then
89 if [ ! -f $CONFIG_PATH/production.rb ]; then
90 cp $RELEASE_PATH/config/environments/production.rb.example $CONFIG_PATH/production.rb
92 ln -s $CONFIG_PATH/production.rb $RELEASE_PATH/config/environments/production.rb
94 if [ ! -h $RELEASE_PATH/config/application.yml ]; then
95 ln -s $CONFIG_PATH/application.yml $RELEASE_PATH/config/application.yml
99 # Before we do anything else, make sure some directories and files are in place
100 if [ ! -e $SHARED_PATH/log ]; then mkdir -p $SHARED_PATH/log; fi
101 if [ ! -e $RELEASE_PATH/tmp ]; then mkdir -p $RELEASE_PATH/tmp; fi
102 if [ ! -e $RELEASE_PATH/log ]; then ln -s $SHARED_PATH/log $RELEASE_PATH/log; fi
103 if [ ! -e $SHARED_PATH/log/production.log ]; then touch $SHARED_PATH/log/production.log; fi
106 export RAILS_ENV=production
108 echo -n "Running bundle install ..."
109 $COMMAND_PREFIX bundle install --path $SHARED_PATH/vendor_bundle --quiet || exit $?
112 echo -n "Ensuring directory and file permissions ..."
113 # Ensure correct ownership of a few files
114 chown "$WWW_OWNER" $RELEASE_PATH/config/environment.rb
115 chown "$WWW_OWNER" $RELEASE_PATH/config.ru
116 chown "$WWW_OWNER" $RELEASE_PATH/config/database.yml
117 chown "$WWW_OWNER" $RELEASE_PATH/Gemfile.lock
118 chown -R "$WWW_OWNER" $RELEASE_PATH/tmp
119 chown -R "$WWW_OWNER" $SHARED_PATH/log
120 chown "$WWW_OWNER" $RELEASE_PATH/db/schema.rb
121 chmod 644 $SHARED_PATH/log/*
125 DB_MIGRATE_STATUS=`$COMMAND_PREFIX bundle exec rake db:migrate:status 2>/dev/null`
126 DB_MIGRATE_STATUS_CODE=$?
129 if echo $DB_MIGRATE_STATUS | grep 'Schema migrations table does not exist yet.' >/dev/null; then
130 # The database exists, but the migrations table doesn't.
131 echo -n "Setting up database ..."
132 $COMMAND_PREFIX bundle exec rake db:schema:load db:seed || exit $?
133 elif echo $DB_MIGRATE_STATUS | grep '^database: ' >/dev/null; then
134 echo -n "Running db:migrate ..."
135 $COMMAND_PREFIX bundle exec rake db:migrate || exit $?
137 echo "Error: Database is not ready to set up. Aborting." >&2
142 echo -n "Precompiling assets ..."
143 # precompile assets; thankfully this does not take long
144 $COMMAND_PREFIX bundle exec rake assets:precompile -q -s || exit $?
145 chown -R "$WWW_OWNER" $RELEASE_PATH/tmp
148 if [ ! -z "$WEB_SERVICE" ]; then
149 echo -n "Restarting $WEB_SERVICE ..."
150 service "$WEB_SERVICE" restart || exit $?
157 if [ "$1" = configure ]; then
158 # This is a debian-based system
159 setup_ruby_environment
160 configure_version $VERSION "$2"
161 elif [ "$1" = "0" ] || [ "$1" = "1" ] || [ "$1" = "2" ]; then
162 # This is an rpm-based system
163 setup_ruby_environment
164 configure_version $VERSION