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
13 VERSION=`cat $RELEASE_PATH/git-commit.version`
15 setup_ruby_environment() {
16 if [ -s "$HOME/.rvm/scripts/rvm" ] ; then
18 elif [ -s "/usr/local/rvm/scripts/rvm" ] ; then
24 if [ "$using_rvm" = "true" ]; then
25 COMMAND_PREFIX="/usr/local/rvm/bin/rvm-exec default"
31 # arguments: <major version> <most recently configured package version>
35 [ "$VERSION" ] || { echo "Error: configure_version: need version parameter" >&2; exit 1; }
37 WEB_SERVICE=${WEB_SERVICE:-$(service --status-all 2>/dev/null \
38 | grep -Eo '\bnginx|httpd[^[:space:]]*' || true)}
39 if [ -z "$WEB_SERVICE" ]; then
42 Warning: web service (Nginx or Apache) not found.
44 To override, set the WEB_SERVICE environment variable to the name of the service
45 hosting the Rails server. Alternativey, install nginx.
47 For Debian-based systems, then reconfigure this package with dpkg-reconfigure.
49 For RPM-based systems, then reinstall this package.
52 elif [ "$WEB_SERVICE" != "$(echo "$WEB_SERVICE" | head -n 1)" ]; then
53 WEB_SERVICE=$(echo "$WEB_SERVICE" | head -n 1)
55 Warning: multiple web services found. Choosing the first one ($WEB_SERVICE).
57 To override, set the WEB_SERVICE environment variable to the name of the service
58 hosting the Rails server.
60 For Debian-based systems, then reconfigure this package with dpkg-reconfigure.
62 For RPM-based systems, then reinstall this package.
67 if [ -e /etc/redhat-release ]; then
68 if [ "$WEB_SERVICE" = "nginx" ]; then
71 WWW_OWNER=apache:apache
74 # Assume we're on a Debian-based system for now.
75 # Both Apache and Nginx run as www-data by default.
76 WWW_OWNER=www-data:www-data
80 echo "Assumption: $WEB_SERVICE is configured to serve your SSO server URL from"
81 echo " /var/www/arvados-sso/current"
82 echo "Assumption: configuration files are in /etc/arvados/sso/"
83 echo "Assumption: $WEB_SERVICE and passenger run as $WWW_OWNER"
86 echo -n "Symlinking files from $CONFIG_PATH ..."
88 if [ ! -f $CONFIG_PATH/database.yml ]; then
90 cp $RELEASE_PATH/config/database.yml.example $CONFIG_PATH/database.yml
94 if [ ! -h $RELEASE_PATH/config/database.yml ]; then
95 ln -s $CONFIG_PATH/database.yml $RELEASE_PATH/config/database.yml
98 if [ ! -f $CONFIG_PATH/production.rb ]; then
100 cp $RELEASE_PATH/config/environments/production.rb.example $CONFIG_PATH/production.rb
103 if [ ! -h $RELEASE_PATH/config/environments/production.rb ]; then
104 ln -s $CONFIG_PATH/production.rb $RELEASE_PATH/config/environments/production.rb
107 if [ ! -f $CONFIG_PATH/application.yml ]; then
108 mkdir -p $CONFIG_PATH
109 cp $RELEASE_PATH/config/application.yml.example $CONFIG_PATH/application.yml
113 if [ ! -h $RELEASE_PATH/config/application.yml ]; then
114 ln -s $CONFIG_PATH/application.yml $RELEASE_PATH/config/application.yml
119 # Before we do anything else, make sure some directories and files are in place
120 if [ ! -e $SHARED_PATH/log ]; then mkdir -p $SHARED_PATH/log; fi
121 if [ ! -e $RELEASE_PATH/tmp ]; then mkdir -p $RELEASE_PATH/tmp; fi
122 if [ ! -e $RELEASE_PATH/log ]; then ln -s $SHARED_PATH/log $RELEASE_PATH/log; fi
123 if [ ! -e $SHARED_PATH/log/production.log ]; then touch $SHARED_PATH/log/production.log; fi
126 export RAILS_ENV=production
128 echo -n "Running bundle install ..."
129 $COMMAND_PREFIX bundle install --path $SHARED_PATH/vendor_bundle --quiet || exit $?
132 echo -n "Ensuring directory and file permissions ..."
133 # Ensure correct ownership of a few files
134 chown "$WWW_OWNER" $RELEASE_PATH/config/environment.rb
135 chown "$WWW_OWNER" $RELEASE_PATH/config.ru
136 chown "$WWW_OWNER" $RELEASE_PATH/config/database.yml
137 chown "$WWW_OWNER" $RELEASE_PATH/Gemfile.lock
138 chown -R "$WWW_OWNER" $RELEASE_PATH/tmp
139 chown -R "$WWW_OWNER" $SHARED_PATH/log
140 chown "$WWW_OWNER" $RELEASE_PATH/db/schema.rb
141 chmod 644 $SHARED_PATH/log/*
145 DB_MIGRATE_STATUS=`$COMMAND_PREFIX bundle exec rake db:migrate:status 2>&1`
146 DB_MIGRATE_STATUS_CODE=$?
149 if echo $DB_MIGRATE_STATUS | grep 'Schema migrations table does not exist yet.' >/dev/null; then
150 # The database exists, but the migrations table doesn't.
151 echo -n "Setting up database ..."
152 $COMMAND_PREFIX bundle exec rake db:schema:load db:seed || exit $?
154 elif echo $DB_MIGRATE_STATUS | grep '^database: ' >/dev/null; then
155 echo -n "Running db:migrate ..."
156 $COMMAND_PREFIX bundle exec rake db:migrate || exit $?
158 elif echo $DB_MIGRATE_STATUS | grep 'database .* does not exist' >/dev/null; then
159 echo -n "Running db:setup ..."
161 $COMMAND_PREFIX bundle exec rake db:setup 2>/dev/null
162 if [ "$?" = "0" ]; then
166 echo "Warning: unable to set up database." >&2
171 echo "Warning: Database is not ready to set up. Skipping database setup." >&2
175 echo -n "Precompiling assets ..."
176 # precompile assets; thankfully this does not take long
177 if [ "$APPLICATION_READY" = "1" ]; then
179 $COMMAND_PREFIX bundle exec rake assets:precompile -q -s 2>/dev/null
180 if [ "$?" = "0" ]; then
190 chown -R "$WWW_OWNER" $RELEASE_PATH/tmp
192 if [ ! -z "$WEB_SERVICE" ]; then
193 echo -n "Restarting $WEB_SERVICE ..."
194 service "$WEB_SERVICE" restart >/dev/null || exit $?
199 if [ "$1" = configure ]; then
200 # This is a debian-based system
201 setup_ruby_environment
202 configure_version $VERSION "$2"
203 elif [ "$1" = "0" ] || [ "$1" = "1" ] || [ "$1" = "2" ]; then
204 # This is an rpm-based system
205 setup_ruby_environment
206 configure_version $VERSION
209 if [ "$DATABASE_READY" = "0" ]; then
214 The arvados-sso package was not configured completely because
215 /etc/arvados/database.yml needs some tweaking. Please refer to the
216 documentation at http://doc.arvados.org/install/install-sso.html#configure for
219 When database.yml has been modified, reconfigure or reinstall this package.
223 if [ "$APPLICATION_READY" = "0" ]; then
228 The arvados-sso package was not configured completely because
229 /etc/arvados/application.yml needs some tweaking. Please refer to the
230 documentation at http://doc.arvados.org/install/install-sso.html#configure for
233 When application.yml has been modified, reconfigure or reinstall this package.