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
9 PACKAGE_NAME=arvados-sso-server
14 VERSION=`cat $RELEASE_PATH/git-commit.version`
16 setup_ruby_environment() {
17 if [ -s "$HOME/.rvm/scripts/rvm" ] ; then
19 elif [ -s "/usr/local/rvm/scripts/rvm" ] ; then
25 if [ "$using_rvm" = "true" ]; then
26 COMMAND_PREFIX="/usr/local/rvm/bin/rvm-exec default"
32 # arguments: <major version> <most recently configured package version>
36 [ "$VERSION" ] || { echo "Error: configure_version: need version parameter" >&2; exit 1; }
38 WEB_SERVICE=${WEB_SERVICE:-$(service --status-all 2>/dev/null \
39 | grep -Eo '\bnginx|httpd[^[:space:]]*' || true)}
40 if [ -z "$WEB_SERVICE" ]; then
43 Warning: web service (Nginx or Apache) not found.
45 To override, set the WEB_SERVICE environment variable to the name of the service
46 hosting the Rails server. Alternativey, install nginx.
48 For Debian-based systems, then reconfigure this package with dpkg-reconfigure.
50 For RPM-based systems, then reinstall this package.
53 elif [ "$WEB_SERVICE" != "$(echo "$WEB_SERVICE" | head -n 1)" ]; then
54 WEB_SERVICE=$(echo "$WEB_SERVICE" | head -n 1)
56 Warning: multiple web services found. Choosing the first one ($WEB_SERVICE).
58 To override, set the WEB_SERVICE environment variable to the name of the service
59 hosting the Rails server.
61 For Debian-based systems, then reconfigure this package with dpkg-reconfigure.
63 For RPM-based systems, then reinstall this package.
68 if [ -e /etc/redhat-release ]; then
69 if [ "$WEB_SERVICE" = "nginx" ]; then
72 WWW_OWNER=apache:apache
75 # Assume we're on a Debian-based system for now.
76 # Both Apache and Nginx run as www-data by default.
77 WWW_OWNER=www-data:www-data
81 echo "Assumption: $WEB_SERVICE is configured to serve your SSO server URL from"
83 echo "Assumption: configuration files are in $CONFIG_PATH"
84 echo "Assumption: $WEB_SERVICE and passenger run as $WWW_OWNER"
87 echo -n "Symlinking files from $CONFIG_PATH ..."
89 if [ ! -f $CONFIG_PATH/database.yml ]; then
91 cp $RELEASE_PATH/config/database.yml.example $CONFIG_PATH/database.yml
95 if [ ! -h $RELEASE_PATH/config/database.yml ]; then
96 ln -s $CONFIG_PATH/database.yml $RELEASE_PATH/config/database.yml
99 if [ ! -f $CONFIG_PATH/production.rb ]; then
100 mkdir -p $CONFIG_PATH
101 cp $RELEASE_PATH/config/environments/production.rb.example $CONFIG_PATH/production.rb
104 if [ ! -h $RELEASE_PATH/config/environments/production.rb ]; then
105 ln -s $CONFIG_PATH/production.rb $RELEASE_PATH/config/environments/production.rb
108 if [ ! -f $CONFIG_PATH/application.yml ]; then
109 mkdir -p $CONFIG_PATH
110 cp $RELEASE_PATH/config/application.yml.example $CONFIG_PATH/application.yml
114 if [ ! -h $RELEASE_PATH/config/application.yml ]; then
115 ln -s $CONFIG_PATH/application.yml $RELEASE_PATH/config/application.yml
120 # Before we do anything else, make sure some directories and files are in place
121 if [ ! -e $SHARED_PATH/log ]; then mkdir -p $SHARED_PATH/log; fi
122 if [ ! -e $RELEASE_PATH/tmp ]; then mkdir -p $RELEASE_PATH/tmp; fi
123 if [ ! -e $RELEASE_PATH/log ]; then ln -s $SHARED_PATH/log $RELEASE_PATH/log; fi
124 if [ ! -e $SHARED_PATH/log/production.log ]; then touch $SHARED_PATH/log/production.log; fi
127 export RAILS_ENV=production
129 echo -n "Running bundle install ..."
130 $COMMAND_PREFIX bundle install --path $SHARED_PATH/vendor_bundle --quiet || exit $?
133 echo -n "Ensuring directory and file permissions ..."
134 # Ensure correct ownership of a few files
135 chown "$WWW_OWNER" $RELEASE_PATH/config/environment.rb
136 chown "$WWW_OWNER" $RELEASE_PATH/config.ru
137 chown "$WWW_OWNER" $RELEASE_PATH/config/database.yml
138 chown "$WWW_OWNER" $RELEASE_PATH/Gemfile.lock
139 chown -R "$WWW_OWNER" $RELEASE_PATH/tmp
140 chown -R "$WWW_OWNER" $SHARED_PATH/log
141 chown "$WWW_OWNER" $RELEASE_PATH/db/schema.rb
142 chmod 644 $SHARED_PATH/log/*
146 DB_MIGRATE_STATUS=`$COMMAND_PREFIX bundle exec rake db:migrate:status 2>&1`
147 DB_MIGRATE_STATUS_CODE=$?
150 if echo $DB_MIGRATE_STATUS | grep 'Schema migrations table does not exist yet.' >/dev/null; then
151 # The database exists, but the migrations table doesn't.
152 echo -n "Setting up database ..."
153 $COMMAND_PREFIX bundle exec rake db:schema:load db:seed || exit $?
155 elif echo $DB_MIGRATE_STATUS | grep '^database: ' >/dev/null; then
156 echo -n "Running db:migrate ..."
157 $COMMAND_PREFIX bundle exec rake db:migrate || exit $?
159 elif echo $DB_MIGRATE_STATUS | grep 'database .* does not exist' >/dev/null; then
160 echo -n "Running db:setup ..."
162 $COMMAND_PREFIX bundle exec rake db:setup 2>/dev/null
163 if [ "$?" = "0" ]; then
167 echo "Warning: unable to set up database." >&2
172 echo "Warning: Database is not ready to set up. Skipping database setup." >&2
176 echo -n "Precompiling assets ..."
177 # precompile assets; thankfully this does not take long
178 if [ "$APPLICATION_READY" = "1" ]; then
180 $COMMAND_PREFIX bundle exec rake assets:precompile -q -s 2>/dev/null
181 if [ "$?" = "0" ]; then
191 chown -R "$WWW_OWNER" $RELEASE_PATH/tmp
193 if [ ! -z "$WEB_SERVICE" ]; then
194 echo -n "Restarting $WEB_SERVICE ..."
195 service "$WEB_SERVICE" restart >/dev/null || exit $?
200 if [ "$1" = configure ]; then
201 # This is a debian-based system
202 setup_ruby_environment
203 configure_version $VERSION "$2"
204 elif [ "$1" = "0" ] || [ "$1" = "1" ] || [ "$1" = "2" ]; then
205 # This is an rpm-based system
206 setup_ruby_environment
207 configure_version $VERSION
210 if [ "$DATABASE_READY" = "0" ]; then
215 The $PACKAGE_NAME package was not configured completely because
216 $CONFIG_PATH/database.yml needs some tweaking. Please refer to the
217 documentation at http://doc.arvados.org/install/install-sso.html#configure for
220 When database.yml has been modified, reconfigure or reinstall this package.
224 if [ "$APPLICATION_READY" = "0" ]; then
229 The $PACKAGE_NAME package was not configured completely because
230 $CONFIG_PATH/application.yml needs some tweaking. Please refer to the
231 documentation at http://doc.arvados.org/install/install-sso.html#configure for
234 When application.yml has been modified, reconfigure or reinstall this package.