[ARVADOS-DEV] created: 8e7691e8a2a278a797dd4a28c196f4243a7d592d

git at public.curoverse.com git at public.curoverse.com
Sat Jan 2 11:23:25 EST 2016


        at  8e7691e8a2a278a797dd4a28c196f4243a7d592d (commit)


commit 8e7691e8a2a278a797dd4a28c196f4243a7d592d
Author: Brett Smith <brett at curoverse.com>
Date:   Sat Jan 2 11:21:00 2016 -0500

    8014, 8059: Unify Rails package building.
    
    * Introduce a handle_rails_package function, and helpers, to build a
      Rails package.
    * Generalize all the support scripts into unified postinst, prerm, and
      postrm scripts.  handle_rails_package builds these into the
      packages.  See jenkins/rails-package-scripts/README.md for details.
    * More error checking throughout (e.g., check for failure when doing
      any prep work for Rails packages, or the Workbench packages
      specifically, using `set -e` in a subshell).
    
    One behavior change from this unification: before this,
    run-build-packages treated --build-bundle-packages to mean "*also*
    build bundle packages", while run-build-packages-sso treated the
    switch to mean "*only* build bundle packages".  This commit declares
    run-build-packages to be the winner, and makes run-build-packages-sso
    consistent with it.

diff --git a/jenkins/arvados-api-server-extras/arvados-api-server-upgrade.sh b/jenkins/arvados-api-server-extras/arvados-api-server-upgrade.sh
deleted file mode 100755
index 2fff1e7..0000000
--- a/jenkins/arvados-api-server-extras/arvados-api-server-upgrade.sh
+++ /dev/null
@@ -1,118 +0,0 @@
-#!/bin/bash
-
-set -e
-
-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 <<EOF
-Error: nginx service not found. Aborting.
-Set NGINX_SERVICE to the name of the service hosting the Rails server.
-EOF
-    exit 1
-elif [ "$NGINX_SERVICE" != "$(echo "$NGINX_SERVICE" | head -n 1)" ]; then
-    cat >&2 <<EOF
-Error: multiple nginx services found. Aborting.
-Set NGINX_SERVICE to the name of the service hosting the Rails server.
-EOF
-    exit 1
-fi
-
-RELEASE_PATH=/var/www/arvados-api/current
-SHARED_PATH=/var/www/arvados-api/shared
-CONFIG_PATH=/etc/arvados/api/
-
-echo "Assumption: $NGINX_SERVICE is configured to serve your API server URL from"
-echo "            /var/www/arvados-api/current"
-echo "Assumption: configuration files are in /etc/arvados/api/"
-echo "Assumption: $NGINX_SERVICE and passenger run as $WWW_OWNER"
-echo
-
-echo "Copying files from $CONFIG_PATH"
-cp -f $CONFIG_PATH/database.yml $RELEASE_PATH/config/database.yml
-cp -f $RELEASE_PATH/config/environments/production.rb.example $RELEASE_PATH/config/environments/production.rb
-cp -f $CONFIG_PATH/application.yml $RELEASE_PATH/config/application.yml
-if [ -e $CONFIG_PATH/omniauth.rb ]; then
-    cp -f $CONFIG_PATH/omniauth.rb $RELEASE_PATH/config/initializers/omniauth.rb
-fi
-echo "Done."
-
-# Before we do anything else, make sure some directories and files are in place
-if [[ ! -e $SHARED_PATH/log ]]; then mkdir -p $SHARED_PATH/log; fi
-if [[ ! -e $RELEASE_PATH/tmp ]]; then mkdir -p $RELEASE_PATH/tmp; fi
-if [[ ! -e $RELEASE_PATH/log ]]; then ln -s $SHARED_PATH/log $RELEASE_PATH/log; fi
-if [[ ! -e $SHARED_PATH/log/production.log ]]; then touch $SHARED_PATH/log/production.log; fi
-
-cd "$RELEASE_PATH"
-export RAILS_ENV=production
-
-echo "Making sure bundle is installed"
-set +e
-which bundle > /dev/null
-if [[ "$?" != "0" ]]; then
-  gem install bundle
-fi
-set -e
-echo "Done."
-
-echo "Running bundle install"
-bundle install --path $SHARED_PATH/vendor_bundle
-echo "Done."
-
-echo "Precompiling assets"
-# precompile assets; thankfully this does not take long
-bundle exec rake assets:precompile
-echo "Done."
-
-echo "Ensuring directory and file permissions"
-# Ensure correct ownership of a few files
-chown "$WWW_OWNER" $RELEASE_PATH/config/environment.rb
-chown "$WWW_OWNER" $RELEASE_PATH/config.ru
-chown "$WWW_OWNER" $RELEASE_PATH/config/database.yml
-chown "$WWW_OWNER" $RELEASE_PATH/Gemfile.lock
-chown -R "$WWW_OWNER" $RELEASE_PATH/tmp
-chown -R "$WWW_OWNER" $SHARED_PATH/log
-chown "$WWW_OWNER" $RELEASE_PATH/db/structure.sql
-chmod 644 $SHARED_PATH/log/*
-# Rails creates the cache directory if it doesn't exist
-if [[ -d $RELEASE_PATH/tmp/cache/ ]]; then
-  chmod -R 2775 $RELEASE_PATH/tmp/cache/
-fi
-echo "Done."
-
-echo "Running sanity check"
-bundle exec rake config:check
-SANITY_CHECK_EXIT_CODE=$?
-echo "Done."
-
-if [[ "$SANITY_CHECK_EXIT_CODE" != "0" ]]; then
-  echo "Sanity check failed, aborting. Please roll back to the previous version of the package."
-  echo "The database has not been migrated yet, so reinstalling the previous version is safe."
-  exit $SANITY_CHECK_EXIT_CODE
-fi
-
-echo "Checking database status"
-# If we use `grep -q`, rake will write a backtrace on EPIPE.
-if bundle exec rake db:migrate:status | grep '^database: ' >/dev/null; then
-    echo "Starting db:migrate"
-    bundle exec rake db:migrate
-elif [ 0 -eq ${PIPESTATUS[0]} ]; then
-    # The database exists, but the migrations table doesn't.
-    echo "Setting up database"
-    bundle exec rake db:structure:load db:seed
-else
-    echo "Error: Database is not ready to set up. Aborting." >&2
-    exit 1
-fi
-echo "Done."
-
-echo "Restarting nginx"
-service "$NGINX_SERVICE" restart
-echo "Done."
diff --git a/jenkins/arvados-api-server-extras/postinst.sh b/jenkins/arvados-api-server-extras/postinst.sh
deleted file mode 100644
index 1aeffe9..0000000
--- a/jenkins/arvados-api-server-extras/postinst.sh
+++ /dev/null
@@ -1,12 +0,0 @@
-#!/bin/bash
-
-cd /var/www/arvados-api
-
-chown -R www-data:www-data tmp >/dev/null 2>&1
-chown -R www-data:www-data log >/dev/null 2>&1
-chown www-data:www-data db/structure.sql >/dev/null 2>&1
-chmod 644 log/* >/dev/null 2>&1
-
-# Errors above are not serious
-exit 0
-
diff --git a/jenkins/arvados-workbench-extras/arvados-workbench-upgrade.sh b/jenkins/arvados-workbench-extras/arvados-workbench-upgrade.sh
deleted file mode 100755
index e981517..0000000
--- a/jenkins/arvados-workbench-extras/arvados-workbench-upgrade.sh
+++ /dev/null
@@ -1,90 +0,0 @@
-#!/bin/bash
-
-set -e
-
-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 <<EOF
-Error: nginx service not found. Aborting.
-Set NGINX_SERVICE to the name of the service hosting the Rails server.
-EOF
-    exit 1
-elif [ "$NGINX_SERVICE" != "$(echo "$NGINX_SERVICE" | head -n 1)" ]; then
-    cat >&2 <<EOF
-Error: multiple nginx services found. Aborting.
-Set NGINX_SERVICE to the name of the service hosting the Rails server.
-EOF
-    exit 1
-fi
-
-RELEASE_PATH=/var/www/arvados-workbench/current
-SHARED_PATH=/var/www/arvados-workbench/shared
-CONFIG_PATH=/etc/arvados/workbench/
-
-echo "Assumption: $NGINX_SERVICE is configured to serve your workbench URL from "
-echo "            /var/www/arvados-workbench/current"
-echo "Assumption: configuration files are in /etc/arvados/workbench/"
-echo "Assumption: $NGINX_SERVICE and passenger run as $WWW_OWNER"
-echo
-
-echo "Copying files from $CONFIG_PATH"
-cp -f $CONFIG_PATH/application.yml $RELEASE_PATH/config/application.yml
-cp -f $RELEASE_PATH/config/environments/production.rb.example $RELEASE_PATH/config/environments/production.rb
-echo "Done."
-
-# Before we do anything else, make sure some directories and files are in place
-if [[ ! -e $SHARED_PATH/log ]]; then mkdir -p $SHARED_PATH/log; fi
-if [[ ! -e $RELEASE_PATH/tmp ]]; then mkdir -p $RELEASE_PATH/tmp; fi
-if [[ ! -e $RELEASE_PATH/log ]]; then ln -s $SHARED_PATH/log $RELEASE_PATH/log; fi
-if [[ ! -e $SHARED_PATH/log/production.log ]]; then touch $SHARED_PATH/log/production.log; fi
-
-echo "Making sure bundle is installed"
-set +e
-which bundle > /dev/null
-if [[ "$?" != "0" ]]; then
-  gem install bundle
-fi
-set -e
-echo "Done."
-
-echo "Running bundle install"
-(cd $RELEASE_PATH && RAILS_ENV=production bundle install --path $SHARED_PATH/vendor_bundle)
-echo "Done."
-
-# We do not need to precompile assets, they are already part of the package.
-
-echo "Ensuring directory and file permissions"
-chown "$WWW_OWNER" $RELEASE_PATH/config/environment.rb
-chown "$WWW_OWNER" $RELEASE_PATH/config.ru
-chown "$WWW_OWNER" $RELEASE_PATH/config/database.yml
-chown "$WWW_OWNER" $RELEASE_PATH/Gemfile.lock
-chown -R "$WWW_OWNER" $RELEASE_PATH/tmp
-chown -R "$WWW_OWNER" $SHARED_PATH/log
-chown "$WWW_OWNER" $RELEASE_PATH/db/schema.rb
-chmod 644 $SHARED_PATH/log/*
-echo "Done."
-
-echo "Running sanity check"
-(cd $RELEASE_PATH && RAILS_ENV=production bundle exec rake config:check)
-SANITY_CHECK_EXIT_CODE=$?
-echo "Done."
-
-if [[ "$SANITY_CHECK_EXIT_CODE" != "0" ]]; then
-  echo "Sanity check failed, aborting. Please roll back to the previous version of the package."
-  exit $SANITY_CHECK_EXIT_CODE
-fi
-
-# We do not need to run db:migrate because Workbench is stateless
-
-echo "Restarting nginx"
-service "$NGINX_SERVICE" restart
-echo "Done."
-
diff --git a/jenkins/arvados-workbench-extras/postinst.sh b/jenkins/arvados-workbench-extras/postinst.sh
deleted file mode 100644
index d0aa9b0..0000000
--- a/jenkins/arvados-workbench-extras/postinst.sh
+++ /dev/null
@@ -1,12 +0,0 @@
-#!/bin/bash
-
-cd /var/www/arvados-workbench
-
-chown -R www-data:www-data tmp >/dev/null 2>&1
-chown -R www-data:www-data log >/dev/null 2>&1
-chown www-data:www-data db/schema.rb >/dev/null 2>&1
-chmod 644 log/* >/dev/null 2>&1
-
-# Errors above are not serious
-exit 0
-
diff --git a/jenkins/rails-package-scripts/README.md b/jenkins/rails-package-scripts/README.md
new file mode 100644
index 0000000..6779fb4
--- /dev/null
+++ b/jenkins/rails-package-scripts/README.md
@@ -0,0 +1,13 @@
+When run-build-packages.sh builds a Rails package, it generates the package's pre/post-inst/rm scripts by concatenating:
+
+1. package_name.sh, which defines variables about where package files live and some human-readable names about them.
+2. step2.sh, which uses those to define some utility variables and set defaults for things that aren't set.
+3. stepname.sh, like postinst.sh, prerm.sh, etc., which uses all this information to do the actual work.
+
+Since our build process is a tower of shell scripts, concatenating files seemed like the least worst option to share code between these files and packages.  More advanced code generation would've been too much trouble to integrate into our build process at this time.  Trying to inject portions of files into other files seemed error-prone and likely to introduce bugs to the end result.
+
+postinst.sh lets the early parts define a few hooks to control behavior:
+
+* After it installs the core configuration files (database.yml, application.yml, and production.rb) to /etc/arvados/server, it calls setup_extra_conffiles.  By default this is a noop function (in step2.sh).  API server defines this to set up the old omniauth.rb conffile.
+* $RAILSPKG_DATABASE_LOAD_TASK defines the Rake task to load the database.  API server uses db:structure:load.  SSO server uses db:schema:load.  Workbench doesn't set this, which causes the postinst to skip all database work.
+* If $RAILSPKG_SUPPORTS_CONFIG_CHECK != 1, it won't run the config:check rake task.  SSO clears this flag (it doesn't have that task code).
diff --git a/jenkins/rails-package-scripts/arvados-api-server.sh b/jenkins/rails-package-scripts/arvados-api-server.sh
new file mode 100644
index 0000000..4df87eb
--- /dev/null
+++ b/jenkins/rails-package-scripts/arvados-api-server.sh
@@ -0,0 +1,12 @@
+#!/bin/sh
+# This file declares variables common to all scripts for one Rails package.
+
+PACKAGE_NAME=arvados-api-server
+INSTALL_PATH=/var/www/arvados-api
+CONFIG_PATH=/etc/arvados/api
+DOC_URL="http://doc.arvados.org/install/install-api-server.html#configure"
+
+RAILSPKG_DATABASE_LOAD_TASK=db:structure:load
+setup_extra_conffiles() {
+    setup_conffile initializers/omniauth.rb
+}
diff --git a/jenkins/rails-package-scripts/arvados-sso-server.sh b/jenkins/rails-package-scripts/arvados-sso-server.sh
new file mode 100644
index 0000000..10b2ee2
--- /dev/null
+++ b/jenkins/rails-package-scripts/arvados-sso-server.sh
@@ -0,0 +1,9 @@
+#!/bin/sh
+# This file declares variables common to all scripts for one Rails package.
+
+PACKAGE_NAME=arvados-sso-server
+INSTALL_PATH=/var/www/arvados-sso
+CONFIG_PATH=/etc/arvados/sso
+DOC_URL="http://doc.arvados.org/install/install-sso.html#configure"
+RAILSPKG_DATABASE_LOAD_TASK=db:schema:load
+RAILSPKG_SUPPORTS_CONFIG_CHECK=0
diff --git a/jenkins/rails-package-scripts/arvados-workbench.sh b/jenkins/rails-package-scripts/arvados-workbench.sh
new file mode 100644
index 0000000..f2b8a56
--- /dev/null
+++ b/jenkins/rails-package-scripts/arvados-workbench.sh
@@ -0,0 +1,7 @@
+#!/bin/sh
+# This file declares variables common to all scripts for one Rails package.
+
+PACKAGE_NAME=arvados-workbench
+INSTALL_PATH=/var/www/arvados-workbench
+CONFIG_PATH=/etc/arvados/workbench
+DOC_URL="http://doc.arvados.org/install/install-workbench-app.html#configure"
diff --git a/jenkins/arvados-sso-server-extras/arvados-sso-server.postinst b/jenkins/rails-package-scripts/postinst.sh
old mode 100755
new mode 100644
similarity index 82%
rename from jenkins/arvados-sso-server-extras/arvados-sso-server.postinst
rename to jenkins/rails-package-scripts/postinst.sh
index e72d9b8..96e687c
--- a/jenkins/arvados-sso-server-extras/arvados-sso-server.postinst
+++ b/jenkins/rails-package-scripts/postinst.sh
@@ -1,15 +1,8 @@
-#!/bin/bash
+#!/bin/sh
+# This code runs after package variable definitions and step2.sh.
 
 set -e
 
-INSTALL_PATH=/var/www/arvados-sso
-RELEASE_PATH=$INSTALL_PATH/current
-RELEASE_CONFIG_PATH=$RELEASE_PATH/config
-SHARED_PATH=$INSTALL_PATH/shared
-CONFIG_PATH=/etc/arvados/sso
-PACKAGE_NAME=arvados-sso-server
-DOC_URL="http://doc.arvados.org/install/install-sso.html#configure"
-
 DATABASE_READY=1
 APPLICATION_READY=1
 
@@ -20,8 +13,8 @@ else
 fi
 
 report_not_ready() {
-    local ready_flag=$1; shift
-    local config_file=$1; shift
+    local ready_flag="$1"; shift
+    local config_file="$1"; shift
     if [ "1" != "$ready_flag" ]; then cat >&2 <<EOF
 
 PLEASE NOTE:
@@ -39,7 +32,7 @@ EOF
 }
 
 report_web_service_warning() {
-    local warning=$1; shift
+    local warning="$1"; shift
     cat >&2 <<EOF
 
 WARNING: $warning.
@@ -59,7 +52,7 @@ run_and_report() {
     # This is the usual wrapper that prints ACTION_MSG, runs CMD, then writes
     # a message about whether CMD succeeded or failed.  Returns the exit code
     # of CMD.
-    local action_message=$1; shift
+    local action_message="$1"; shift
     local retcode=0
     echo -n "$action_message..."
     if "$@"; then
@@ -79,10 +72,10 @@ setup_conffile() {
     # If SOURCE_PATH is given, this function will try to install that file as
     # the configuration file in CONFIG_PATH, and return 1 if the file in
     # CONFIG_PATH is unmodified from the source.
-    local conffile_relpath=$1; shift
-    local conffile_source=$1; shift
-    local release_conffile=$RELEASE_CONFIG_PATH/$conffile_relpath
-    local etc_conffile=$CONFIG_PATH/$(basename "$conffile_relpath")
+    local conffile_relpath="$1"; shift
+    local conffile_source="$1"
+    local release_conffile="$RELEASE_CONFIG_PATH/$conffile_relpath"
+    local etc_conffile="$CONFIG_PATH/$(basename "$conffile_relpath")"
 
     # Note that -h can return true and -e will return false simultaneously
     # when the target is a dangling symlink.  We're okay with that outcome,
@@ -109,6 +102,27 @@ setup_conffile() {
     fi
 }
 
+prepare_database() {
+  DB_MIGRATE_STATUS=`$COMMAND_PREFIX bundle exec rake db:migrate:status 2>&1 || true`
+  if echo $DB_MIGRATE_STATUS | grep -qF 'Schema migrations table does not exist yet.'; then
+      # The database exists, but the migrations table doesn't.
+      run_and_report "Setting up database" $COMMAND_PREFIX bundle exec \
+                     rake "$RAILSPKG_DATABASE_LOAD_TASK" db:seed
+  elif echo $DB_MIGRATE_STATUS | grep -q '^database: '; then
+      run_and_report "Running db:migrate" \
+                     $COMMAND_PREFIX bundle exec rake db:migrate
+  elif echo $DB_MIGRATE_STATUS | grep -q 'database .* does not exist'; then
+      if ! run_and_report "Running db:setup" \
+           $COMMAND_PREFIX bundle exec rake db:setup 2>/dev/null; then
+          echo "Warning: unable to set up database." >&2
+          DATABASE_READY=0
+      fi
+  else
+    echo "Warning: Database is not ready to set up. Skipping database setup." >&2
+    DATABASE_READY=0
+  fi
+}
+
 configure_version() {
   WEB_SERVICE=${WEB_SERVICE:-$(service --status-all 2>/dev/null \
       | grep -Eo '\bnginx|httpd[^[:space:]]*' || true)}
@@ -134,18 +148,20 @@ configure_version() {
   fi
 
   echo
-  echo "Assumption: $WEB_SERVICE is configured to serve your SSO server URL from"
+  echo "Assumption: $WEB_SERVICE is configured to serve Rails from"
   echo "            $RELEASE_PATH"
-  echo "Assumption: configuration files are in $CONFIG_PATH"
   echo "Assumption: $WEB_SERVICE and passenger run as $WWW_OWNER"
   echo
 
-  echo -n "Symlinking files from $CONFIG_PATH ..."
+  echo -n "Creating symlinks to configuration in $CONFIG_PATH ..."
   mkdir -p $CONFIG_PATH
-  setup_conffile database.yml database.yml.example || DATABASE_READY=0
   setup_conffile environments/production.rb environments/production.rb.example \
       || true
   setup_conffile application.yml application.yml.example || APPLICATION_READY=0
+  if [ -n "$RAILSPKG_DATABASE_LOAD_TASK" ]; then
+      setup_conffile database.yml database.yml.example || DATABASE_READY=0
+  fi
+  setup_extra_conffiles
   echo "... done."
 
   # Before we do anything else, make sure some directories and files are in place
@@ -168,31 +184,25 @@ configure_version() {
   # Ensure correct ownership of a few files
   chown "$WWW_OWNER" $RELEASE_PATH/config/environment.rb
   chown "$WWW_OWNER" $RELEASE_PATH/config.ru
-  chown "$WWW_OWNER" $RELEASE_PATH/config/database.yml
   chown "$WWW_OWNER" $RELEASE_PATH/Gemfile.lock
   chown -R "$WWW_OWNER" $RELEASE_PATH/tmp
   chown -R "$WWW_OWNER" $SHARED_PATH/log
-  chown "$WWW_OWNER" $RELEASE_PATH/db/schema.rb
+  case "$RAILSPKG_DATABASE_LOAD_TASK" in
+      db:schema:load) chown "$WWW_OWNER" $RELEASE_PATH/db/schema.rb ;;
+      db:structure:load) chown "$WWW_OWNER" $RELEASE_PATH/db/structure.sql ;;
+  esac
   chmod 644 $SHARED_PATH/log/*
+  chmod -R 2775 $RELEASE_PATH/tmp
   echo "... done."
 
-  DB_MIGRATE_STATUS=`$COMMAND_PREFIX bundle exec rake db:migrate:status 2>&1 || true`
-  if echo $DB_MIGRATE_STATUS | grep -qF 'Schema migrations table does not exist yet.'; then
-      # The database exists, but the migrations table doesn't.
-      run_and_report "Setting up database" \
-                     $COMMAND_PREFIX bundle exec rake db:schema:load db:seed
-  elif echo $DB_MIGRATE_STATUS | grep -q '^database: '; then
-      run_and_report "Running db:migrate" \
-                     $COMMAND_PREFIX bundle exec rake db:migrate
-  elif echo $DB_MIGRATE_STATUS | grep -q 'database .* does not exist'; then
-      if ! run_and_report "Running db:setup" \
-           $COMMAND_PREFIX bundle exec rake db:setup 2>/dev/null; then
-          echo "Warning: unable to set up database." >&2
-          DATABASE_READY=0
-      fi
-  else
-    echo "Warning: Database is not ready to set up. Skipping database setup." >&2
-    DATABASE_READY=0
+  if [ -n "$RAILSPKG_DATABASE_LOAD_TASK" ]; then
+      chown "$WWW_OWNER" $RELEASE_PATH/config/database.yml
+      prepare_database
+  fi
+
+  if [ 11 = "$RAILSPKG_SUPPORTS_CONFIG_CHECK$APPLICATION_READY" ]; then
+      run_and_report "Checking application.yml for completeness" \
+          $COMMAND_PREFIX bundle exec rake config:check || APPLICATION_READY=0
   fi
 
   # precompile assets; thankfully this does not take long
diff --git a/jenkins/arvados-sso-server-extras/arvados-sso-server.postrm b/jenkins/rails-package-scripts/postrm.sh
old mode 100755
new mode 100644
similarity index 79%
rename from jenkins/arvados-sso-server-extras/arvados-sso-server.postrm
rename to jenkins/rails-package-scripts/postrm.sh
index 070c90e..8c45d2f
--- a/jenkins/arvados-sso-server-extras/arvados-sso-server.postrm
+++ b/jenkins/rails-package-scripts/postrm.sh
@@ -1,15 +1,12 @@
 #!/bin/sh
+# This code runs after package variable definitions and step2.sh.
 
 set -e
 
-INSTALL_PATH=/var/www/arvados-sso
-RELEASE_PATH=$INSTALL_PATH/current
-SHARED_PATH=$INSTALL_PATH/shared
-CONFIG_PATH=/etc/arvados/sso
-
 purge () {
   rm -rf $SHARED_PATH/vendor_bundle
   rm -rf $SHARED_PATH/log
+  rm -rf $CONFIG_PATH
   rmdir $SHARED_PATH || true
   rmdir $INSTALL_PATH || true
 }
diff --git a/jenkins/arvados-sso-server-extras/arvados-sso-server.prerm b/jenkins/rails-package-scripts/prerm.sh
old mode 100755
new mode 100644
similarity index 71%
rename from jenkins/arvados-sso-server-extras/arvados-sso-server.prerm
rename to jenkins/rails-package-scripts/prerm.sh
index 1a43fa2..4ef5904
--- a/jenkins/arvados-sso-server-extras/arvados-sso-server.prerm
+++ b/jenkins/rails-package-scripts/prerm.sh
@@ -1,20 +1,16 @@
 #!/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
+# This code runs after package variable definitions and step2.sh.
 
 remove () {
   rm -f $RELEASE_PATH/config/database.yml
   rm -f $RELEASE_PATH/config/environments/production.rb
   rm -f $RELEASE_PATH/config/application.yml
+  # Old API server configuration file.
+  rm -f $RELEASE_PATH/config/initializers/omniauth.rb
   rm -rf $RELEASE_PATH/public/assets/
   rm -rf $RELEASE_PATH/tmp
   rm -rf $RELEASE_PATH/.bundle
-  rm $RELEASE_PATH/log || true
+  rm -rf $RELEASE_PATH/log
 }
 
 if [ "$1" = 'remove' ]; then
diff --git a/jenkins/rails-package-scripts/step2.sh b/jenkins/rails-package-scripts/step2.sh
new file mode 100644
index 0000000..6678d49
--- /dev/null
+++ b/jenkins/rails-package-scripts/step2.sh
@@ -0,0 +1,25 @@
+#!/bin/sh
+# This code runs after package variable definitions, before the actual
+# pre/post package work, to set some variable and function defaults.
+
+if [ -z "$INSTALL_PATH" ]; then
+    cat >&2 <<EOF
+
+PACKAGE BUILD ERROR: $0 is missing package metadata.
+
+This package is buggy.  Please mail <support at curoverse.com> to let
+us know the name and version number of the package you tried to
+install, and we'll get it fixed.
+
+EOF
+    exit 3
+fi
+
+RELEASE_PATH=$INSTALL_PATH/current
+RELEASE_CONFIG_PATH=$RELEASE_PATH/config
+SHARED_PATH=$INSTALL_PATH/shared
+
+RAILSPKG_SUPPORTS_CONFIG_CHECK=${RAILSPKG_SUPPORTS_CONFIG_CHECK:-1}
+if ! type setup_extra_conffiles >/dev/null 2>&1; then
+    setup_extra_conffiles() { return; }
+fi
diff --git a/jenkins/run-build-packages-sso.sh b/jenkins/run-build-packages-sso.sh
index 2cee17f..eedb77b 100755
--- a/jenkins/run-build-packages-sso.sh
+++ b/jenkins/run-build-packages-sso.sh
@@ -169,73 +169,9 @@ if [[ ! -d "$WORKSPACE/packages/$TARGET" ]]; then
 fi
 
 # Build the SSO server package
-
-cd "$WORKSPACE"
-
-SSO_VERSION=$(version_from_git)
-PACKAGE_NAME=arvados-sso-server
-
-if [[ ! -d "$WORKSPACE/tmp" ]]; then
-  mkdir $WORKSPACE/tmp
-fi
-
-if [[ "$BUILD_BUNDLE_PACKAGES" != 0 ]]; then
-  bundle install --path vendor/bundle >"$STDOUT_IF_DEBUG"
-fi
-
-/usr/bin/git rev-parse HEAD > git-commit.version
-
-cd $WORKSPACE/packages/$TARGET
-
-# Annoyingly, we require a database.yml file for rake assets:precompile to work.
-
-# TODO: add bogus database.yml file so we can precompile the assets and put them in the
-# package. Then remove that database.yml file again. It has to be a valid file though.
-#RAILS_ENV=production RAILS_GROUPS=assets bundle exec rake assets:precompile
-
-# There are just 2 excludes left here, all the others are pulled in via fpm-info.sh, which
-# takes .gitignore into account via a call to git status:
-#
-# 1. The .git directory is excluded by git implicitly, so we can't pick it up from .gitignore.
-# 2. The packages directory needs to be explictly excluded here because it will only be listed
-# if it exists at the time fpm-info.sh runs. If it does not exist at that time, this script
-# will create it and when fpm runs, it will include the directory. So we add it to the exclude
-# list explicitly here, just in case.
-declare -a COMMAND_ARR=("fpm" "--maintainer=Ward Vandewege <ward at curoverse.com>" "--vendor='Curoverse, Inc.'" "--url='https://arvados.org'" "--description='Arvados SSO server - Arvados is a free and open source platform for big data science.'" "--license='Expat License'" "-s" "dir" "-t" "$FORMAT" "-v" "$SSO_VERSION" "-x" "var/www/arvados-sso/current/.git" "-x" "var/www/arvados-sso/current/packages" "--after-install=$RUN_BUILD_PACKAGES_PATH/arvados-sso-server-extras/arvados-sso-server.postinst" "--before-remove=$RUN_BUILD_PACKAGES_PATH/arvados-sso-server-extras/arvados-sso-server.prerm" "--after-remove=$RUN_BUILD_PACKAGES_PATH/arvados-sso-server-extras/arvados-sso-server.postrm" )
-
-if [[ "$BUILD_BUNDLE_PACKAGES" != 0 ]]; then
-  # This is the complete package with vendor/bundle included.
-  # It's big, so we do not build it by default.
-  COMMAND_ARR+=("-n" "${PACKAGE_NAME}-with-bundle")
-else
-  # The default package excludes vendor/bundle
-  COMMAND_ARR+=("-n" "${PACKAGE_NAME}" "-x" "var/www/arvados-sso/current/vendor/bundle")
-fi
-
-# Append --depends X and other arguments specified by fpm-info.sh in
-# the package source dir. These are added last so they can override
-# the arguments added by this script.
-# `--iteration 2` accommodates a postinst change on 2015-12-10.
-declare -a fpm_args=(--iteration 2)
-declare -a fpm_depends=()
-FPM_INFO="$WORKSPACE/fpm-info.sh"
-if [[ -e "$FPM_INFO" ]]; then
-  debug_echo "Loading fpm overrides from $FPM_INFO"
-  source "$FPM_INFO"
-fi
-
-for i in "${fpm_depends[@]}"; do
-  COMMAND_ARR+=('--depends' "$i")
-done
-COMMAND_ARR+=("${fpm_args[@]}")
-COMMAND_ARR+=("$WORKSPACE/=/var/www/arvados-sso/current")
-debug_echo -e "\n${COMMAND_ARR[@]}\n"
-
-FPM_RESULTS=$("${COMMAND_ARR[@]}")
-FPM_EXIT_CODE=$?
-
-fpm_verify $FPM_EXIT_CODE $FPM_RESULTS
-
-# SSO server package build done
+handle_rails_package arvados-sso-server "$WORKSPACE" \
+    "$WORKSPACE/LICENCE" --url="https://arvados.org" \
+    --description="Arvados SSO server - Arvados is a free and open source platform for big data science." \
+    --license="Expat license"
 
 exit $EXITCODE
diff --git a/jenkins/run-build-packages.sh b/jenkins/run-build-packages.sh
index 6369087..768bec2 100755
--- a/jenkins/run-build-packages.sh
+++ b/jenkins/run-build-packages.sh
@@ -401,114 +401,47 @@ for deppkg in "${PYTHON3_BACKPORTS[@]}"; do
 done
 
 # Build the API server package
-
-cd "$WORKSPACE/services/api"
-
-API_VERSION=$(version_from_git)
-PACKAGE_NAME=arvados-api-server
-
-if [[ ! -d "$WORKSPACE/services/api/tmp" ]]; then
-  mkdir $WORKSPACE/services/api/tmp
-fi
-
-
-if [[ "$BUILD_BUNDLE_PACKAGES" != 0 ]]; then
-  bundle install --path vendor/bundle >"$STDOUT_IF_DEBUG"
-fi
-
-/usr/bin/git rev-parse HEAD > git-commit.version
-
-cd $WORKSPACE/packages/$TARGET
-
-# Annoyingly, we require a database.yml file for rake assets:precompile to work. So for now,
-# we do that in the upgrade script.
-# TODO: add bogus database.yml file so we can precompile the assets and put them in the
-# package. Then remove that database.yml file again. It has to be a valid file though.
-#RAILS_ENV=production RAILS_GROUPS=assets bundle exec rake assets:precompile
-
-# This is the complete package with vendor/bundle included.
-# It's big, so we do not build it by default.
-if [[ "$BUILD_BUNDLE_PACKAGES" != 0 ]]; then
-  declare -a COMMAND_ARR=("fpm" "--maintainer=Ward Vandewege <ward at curoverse.com>" "--vendor='Curoverse, Inc.'" "--url='https://arvados.org'" "--description='Arvados API server - Arvados is a free and open source platform for big data science.'" "--license='GNU Affero General Public License, version 3.0'" "-s" "dir" "-t" "$FORMAT" "-n" "${PACKAGE_NAME}-with-bundle" "-v" "$API_VERSION" "--iteration" "$(default_iteration "$PACKAGE_NAME" "$API_VERSION")" "-x" "var/www/arvados-api/current/tmp" "-x" "var/www/arvados-api/current/log" "-x" "var/www/arvados-api/current/vendor/cache/*" "-x" "var/www/arvados-api/current/coverage" "-x" "var/www/arvados-api/current/Capfile*" "-x" "var/www/arvados-api/current/config/deploy*" "--after-install=$RUN_BUILD_PACKAGES_PATH/arvados-api-server-extras/postinst.sh" "$WORKSPACE/services/api/=/var/www/arvados-api/current" "$RUN_BUILD_PACKAGES_PATH/arvados-api-server-extras/arvados-api-server-upgrade.sh=/usr/local/bin/arvados-api-server-upgrade.sh" "$WORKSPACE/agpl-3.0.txt=/var/www/arvados-api/current/agpl-3.0.txt")
-
-  debug_echo -e "\n${COMMAND_ARR[@]}\n"
-
-  FPM_RESULTS=$("${COMMAND_ARR[@]}")
-  FPM_EXIT_CODE=$?
-  fpm_verify $FPM_EXIT_CODE $FPM_RESULTS
-fi
-
-# Build the 'bare' package without vendor/bundle.
-declare -a COMMAND_ARR=("fpm" "--maintainer=Ward Vandewege <ward at curoverse.com>" "--vendor='Curoverse, Inc.'" "--url='https://arvados.org'" "--description='Arvados API server - Arvados is a free and open source platform for big data science.'" "--license='GNU Affero General Public License, version 3.0'" "-s" "dir" "-t" "$FORMAT" "-n" "${PACKAGE_NAME}" "-v" "$API_VERSION" "--iteration" "$(default_iteration "$PACKAGE_NAME" "$API_VERSION")" "-x" "var/www/arvados-api/current/tmp" "-x" "var/www/arvados-api/current/log" "-x" "var/www/arvados-api/current/vendor/bundle" "-x" "var/www/arvados-api/current/vendor/cache/*" "-x" "var/www/arvados-api/current/coverage" "-x" "var/www/arvados-api/current/Capfile*" "-x" "var/www/arvados-api/current/config/deploy*" "--after-install=$RUN_BUILD_PACKAGES_PATH/arvados-api-server-extras/postinst.sh" "$WORKSPACE/services/api/=/var/www/arvados-api/current" "$RUN_BUILD_PACKAGES_PATH/arvados-api-server-extras/arvados-api-server-upgrade.sh=/usr/local/bin/arvados-api-server-upgrade.sh" "$WORKSPACE/agpl-3.0.txt=/var/www/arvados-api/current/agpl-3.0.txt")
-
-debug_echo -e "\n${COMMAND_ARR[@]}\n"
-
-FPM_RESULTS=$("${COMMAND_ARR[@]}")
-FPM_EXIT_CODE=$?
-fpm_verify $FPM_EXIT_CODE $FPM_RESULTS
-
-# API server package build done
+handle_rails_package arvados-api-server "$WORKSPACE/services/api" \
+    "$WORKSPACE/agpl-3.0.txt" --url="https://arvados.org" \
+    --description="Arvados API server - Arvados is a free and open source platform for big data science." \
+    --license="GNU Affero General Public License, version 3.0"
 
 # Build the workbench server package
+(
+    set -e
+    cd "$WORKSPACE/apps/workbench"
 
-cd "$WORKSPACE/apps/workbench"
-
-WORKBENCH_VERSION=$(version_from_git)
-PACKAGE_NAME=arvados-workbench
-
-if [[ ! -d "$WORKSPACE/apps/workbench/tmp" ]]; then
-  mkdir $WORKSPACE/apps/workbench/tmp
-fi
-
-# We need to bundle to be ready even when we build a package without vendor directory
-# because asset compilation requires it.
-bundle install --path vendor/bundle >"$STDOUT_IF_DEBUG"
+    # We need to bundle to be ready even when we build a package without vendor directory
+    # because asset compilation requires it.
+    bundle install --path vendor/bundle >"$STDOUT_IF_DEBUG"
 
-/usr/bin/git rev-parse HEAD > git-commit.version
+    # clear the tmp directory; the asset generation step will recreate tmp/cache/assets,
+    # and we want that in the package, so it's easier to not exclude the tmp directory
+    # from the package - empty it instead.
+    rm -rf tmp
+    mkdir tmp
 
-# clear the tmp directory; the asset generation step will recreate tmp/cache/assets,
-# and we want that in the package, so it's easier to not exclude the tmp directory
-# from the package - empty it instead.
-rm -rf $WORKSPACE/apps/workbench/tmp/*
+    # Set up application.yml and production.rb so that asset precompilation works
+    \cp config/application.yml.example config/application.yml -f
+    \cp config/environments/production.rb.example config/environments/production.rb -f
+    sed -i 's/secret_token: ~/secret_token: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/' config/application.yml
 
-# Set up application.yml and production.rb so that asset precompilation works
-\cp config/application.yml.example config/application.yml -f
-\cp config/environments/production.rb.example config/environments/production.rb -f
-sed -i 's/secret_token: ~/secret_token: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/' config/application.yml
+    RAILS_ENV=production RAILS_GROUPS=assets bundle exec rake assets:precompile >/dev/null
 
-RAILS_ENV=production RAILS_GROUPS=assets bundle exec rake assets:precompile >/dev/null
+    # Remove generated configuration files so they don't go in the package.
+    rm config/application.yml config/environments/production.rb
+)
 
 if [[ "$?" != "0" ]]; then
   echo "ERROR: Asset precompilation failed"
   EXITCODE=1
+else
+  handle_rails_package arvados-workbench "$WORKSPACE/apps/workbench" \
+      "$WORKSPACE/agpl-3.0.txt" --url="https://arvados.org" \
+      --description="Arvados Workbench - Arvados is a free and open source platform for big data science." \
+      --license="GNU Affero General Public License, version 3.0"
 fi
 
-cd $WORKSPACE/packages/$TARGET
-
-# This is the complete package with vendor/bundle included.
-# It's big, so we do not build it by default.
-if [[ "$BUILD_BUNDLE_PACKAGES" != 0 ]]; then
-
-  declare -a COMMAND_ARR=("fpm" "--maintainer=Ward Vandewege <ward at curoverse.com>" "--vendor='Curoverse, Inc.'" "--url='https://arvados.org'" "--description='Arvados Workbench - Arvados is a free and open source platform for big data science.'" "--license='GNU Affero General Public License, version 3.0'" "-s" "dir" "-t" "$FORMAT" "-n" "${PACKAGE_NAME}-with-bundle" "-v" "$WORKBENCH_VERSION" "--iteration" "$(default_iteration "$PACKAGE_NAME" "$WORKBENCH_VERSION")" "-x" "var/www/arvados-workbench/current/log" "-x" "var/www/arvados-workbench/current/vendor/cache/*" "-x" "var/www/arvados-workbench/current/coverage" "-x" "var/www/arvados-workbench/current/Capfile*" "-x" "var/www/arvados-workbench/current/config/deploy*" "--after-install=$RUN_BUILD_PACKAGES_PATH/arvados-workbench-extras/postinst.sh" "$WORKSPACE/apps/workbench/=/var/www/arvados-workbench/current" "$RUN_BUILD_PACKAGES_PATH/arvados-workbench-extras/arvados-workbench-upgrade.sh=/usr/local/bin/arvados-workbench-upgrade.sh" "$WORKSPACE/agpl-3.0.txt=/var/www/arvados-workbench/current/agpl-3.0.txt")
-
-  debug_echo -e "\n${COMMAND_ARR[@]}\n"
-
-  FPM_RESULTS=$("${COMMAND_ARR[@]}")
-  FPM_EXIT_CODE=$?
-  fpm_verify $FPM_EXIT_CODE $FPM_RESULTS
-fi
-
-# Build the 'bare' package without vendor/bundle.
-
-declare -a COMMAND_ARR=("fpm" "--maintainer=Ward Vandewege <ward at curoverse.com>" "--vendor='Curoverse, Inc.'" "--url='https://arvados.org'" "--description='Arvados Workbench - Arvados is a free and open source platform for big data science.'" "--license='GNU Affero General Public License, version 3.0'" "-s" "dir" "-t" "$FORMAT" "-n" "${PACKAGE_NAME}" "-v" "$WORKBENCH_VERSION" "--iteration" "$(default_iteration "$PACKAGE_NAME" "$WORKBENCH_VERSION")" "-x" "var/www/arvados-workbench/current/log" "-x" "var/www/arvados-workbench/current/vendor/bundle" "-x" "var/www/arvados-workbench/current/vendor/cache/*" "-x" "var/www/arvados-workbench/current/coverage" "-x" "var/www/arvados-workbench/current/Capfile*" "-x" "var/www/arvados-workbench/current/config/deploy*" "--after-install=$RUN_BUILD_PACKAGES_PATH/arvados-workbench-extras/postinst.sh" "$WORKSPACE/apps/workbench/=/var/www/arvados-workbench/current" "$RUN_BUILD_PACKAGES_PATH/arvados-workbench-extras/arvados-workbench-upgrade.sh=/usr/local/bin/arvados-workbench-upgrade.sh" "$WORKSPACE/agpl-3.0.txt=/var/www/arvados-workbench/current/agpl-3.0.txt")
-
-debug_echo -e "\n${COMMAND_ARR[@]}\n"
-
-FPM_RESULTS=$("${COMMAND_ARR[@]}")
-FPM_EXIT_CODE=$?
-fpm_verify $FPM_EXIT_CODE $FPM_RESULTS
-
-# Workbench package build done
 # clean up temporary GOPATH
 rm -rf "$GOPATH"
 
diff --git a/jenkins/run-library.sh b/jenkins/run-library.sh
index 32a6099..08ffc29 100755
--- a/jenkins/run-library.sh
+++ b/jenkins/run-library.sh
@@ -114,6 +114,53 @@ default_iteration() {
     echo $iteration
 }
 
+_build_rails_package_scripts() {
+    local pkgname="$1"; shift
+    local destdir="$1"; shift
+    local srcdir="$RUN_BUILD_PACKAGES_PATH/rails-package-scripts"
+    for scriptname in postinst prerm postrm; do
+        cat "$srcdir/$pkgname.sh" "$srcdir/step2.sh" "$srcdir/$scriptname.sh" \
+            >"$destdir/$scriptname" || return $?
+    done
+}
+
+handle_rails_package() {
+    local pkgname="$1"; shift
+    local srcdir="$1"; shift
+    local license_path="$1"; shift
+    local scripts_dir="$(mktemp --tmpdir -d "$pkgname-XXXXXXXX.scripts")" && \
+    local version_file="$(mktemp --tmpdir "$pkgname-XXXXXXXX.version")" && (
+        set -e
+        _build_rails_package_scripts "$pkgname" "$scripts_dir"
+        cd "$srcdir"
+        mkdir -p tmp
+        version_from_git >"$version_file"
+        git rev-parse HEAD >git-commit.version
+        if [[ "$BUILD_BUNDLE_PACKAGES" != 0 ]]; then
+            bundle install --path vendor/bundle >"$STDOUT_IF_DEBUG"
+        fi
+    )
+    if [[ 0 != "$?" ]] || ! cd "$WORKSPACE/packages/$TARGET"; then
+        echo "ERROR: $pkgname package prep failed" >&2
+        rm -rf "$scripts_dir" "$version_file"
+        EXITCODE=1
+        return 1
+    fi
+    local -a pos_args=("$srcdir" "$pkgname" "Curoverse, Inc." rails
+                       "$(cat "$version_file")" "$license_path")
+    # --iteration=3 accommodates the package scripts change from #8014.
+    local -a switches=(--iteration=3
+                       --after-install "$scripts_dir/postinst"
+                       --before-remove "$scripts_dir/prerm"
+                       --after-remove "$scripts_dir/postrm")
+    fpm_build "${pos_args[@]}" "${switches[@]}" "$@"
+    if [[ "$BUILD_BUNDLE_PACKAGES" != 0 ]]; then
+        posargs[1]="$pkgname-with-bundle"
+        fpm_build "${pos_args[@]}" --include-bundle "${switches[@]}" "$@"
+    fi
+    rm -rf "$scripts_dir" "$version_file"
+}
+
 # Build packages for everything
 fpm_build () {
   # The package source.  Depending on the source type, this can be a
@@ -134,6 +181,8 @@ fpm_build () {
   # Optional: the package version number.  Passed to fpm -v.
   VERSION=$1
   shift
+  # Specific package types can take additional arguments,
+  # inside the case block below.
 
   case "$PACKAGE_TYPE" in
       python)
@@ -155,6 +204,24 @@ fpm_build () {
               --python-package-name-prefix "$PYTHON3_PKG_PREFIX" \
               --depends "$PYTHON3_PACKAGE"
           ;;
+      rails)
+          # This is also a virtual type, like python3.
+          local railsdir="/var/www/${PACKAGE_NAME%-server}/current"
+          local license_path="$1"; shift
+          if [ "$1" = "--include-bundle" ]; then
+              shift
+          else
+              set -- -x "$railsdir/vendor/bundle" "$@"
+          fi
+          PACKAGE_TYPE=dir
+          PACKAGE="$PACKAGE/=$railsdir"
+          set -- -x "$railsdir/tmp" -x "$railsdir/log" \
+              -x "$railsdir/vendor/cache/*" \
+              -x "$railsdir/current/coverage" \
+              -x "$railsdir/current/Capfile*" \
+              -x "$railsdir/current/config/deploy*" \
+              "$@" "$license_path=$railsdir/$(basename "$license_path")"
+          ;;
   esac
 
   declare -a COMMAND_ARR=("fpm" "--maintainer=Ward Vandewege <ward at curoverse.com>" "-s" "$PACKAGE_TYPE" "-t" "$FORMAT")

commit 4f5773ea1bbb602a29d1ec2164c100051a89d6c6
Author: Brett Smith <brett at curoverse.com>
Date:   Fri Jan 1 19:09:08 2016 -0500

    Fix quoting of local variable assignments throughout.
    
    When you assign a variable directly (e.g., `FOO=bar`), you don't need
    to quote the RHS, because the shell doesn't do expansion in that
    case.  But when you declare and assign a variable (e.g., `local
    foo=bar`), you *do* potentially need to quote it, because `local` is a
    command and all the normal expansion rules for running commands
    applies.

diff --git a/jenkins/run-library.sh b/jenkins/run-library.sh
index 69ebb08..32a6099 100755
--- a/jenkins/run-library.sh
+++ b/jenkins/run-library.sh
@@ -28,7 +28,7 @@ EOF
 }
 
 format_last_commit_here() {
-    local format=$1; shift
+    local format="$1"; shift
     TZ=UTC git log -n1 --first-parent "--format=format:$format" .
 }
 
@@ -59,8 +59,8 @@ handle_python_package () {
 }
 
 handle_ruby_gem() {
-    local gem_name=$1; shift
-    local gem_version=$(nohash_version_from_git)
+    local gem_name="$1"; shift
+    local gem_version="$(nohash_version_from_git)"
     local gem_src_dir="$(pwd)"
 
     if ! [[ -e "${gem_name}-${gem_version}.gem" ]]; then
@@ -76,7 +76,7 @@ package_go_binary() {
     local src_path="$1"; shift
     local prog="$1"; shift
     local description="$1"; shift
-    local license_file=${1:-agpl-3.0.txt}; shift
+    local license_file="${1:-agpl-3.0.txt}"; shift
 
     debug_echo "package_go_binary $src_path as $prog"
 
@@ -86,8 +86,8 @@ package_go_binary() {
     ln -sfn "$WORKSPACE" "$GOPATH/src/git.curoverse.com/arvados.git"
 
     cd "$GOPATH/src/git.curoverse.com/arvados.git/$src_path"
-    local version=$(version_from_git)
-    local timestamp=$(timestamp_from_git)
+    local version="$(version_from_git)"
+    local timestamp="$(timestamp_from_git)"
 
     # If the command imports anything from the Arvados SDK, bump the
     # version number and build a new package whenever the SDK changes.
@@ -104,8 +104,8 @@ package_go_binary() {
 }
 
 default_iteration() {
-    local package_name=$1; shift
-    local package_version=$1; shift
+    local package_name="$1"; shift
+    local package_version="$1"; shift
     local iteration=1
     if [[ $package_version =~ ^0\.1\.([0-9]{14})(\.|$) ]] && \
            [[ ${BASH_REMATCH[1]} -le $LICENSE_PACKAGE_TS ]]; then
diff --git a/jenkins/run-tests.sh b/jenkins/run-tests.sh
index a7b5fda..bdf541a 100755
--- a/jenkins/run-tests.sh
+++ b/jenkins/run-tests.sh
@@ -393,7 +393,7 @@ gem_uninstall_if_exists() {
 }
 
 setup_virtualenv() {
-    local venvdest=$1; shift
+    local venvdest="$1"; shift
     if ! [[ -e "$venvdest/bin/activate" ]] || ! [[ -e "$venvdest/bin/pip" ]]; then
         virtualenv --setuptools "$@" "$venvdest" || fatal "virtualenv $venvdest failed"
     fi

commit 752e6d858d588177b49cadf00f867c8ad8c5af30
Author: Brett Smith <brett at curoverse.com>
Date:   Fri Jan 1 13:38:00 2016 -0500

    8014: Clean database state detection in arvados-sso postinst.
    
    * Remove unused status code capture.
    * Use `grep -q`.  Previous versions of the script avoided it because
      they piped directly from rake tasks, which would get upset when the
      pipe broke.  Now that we capture all the output, that's no longer a
      concern.

diff --git a/jenkins/arvados-sso-server-extras/arvados-sso-server.postinst b/jenkins/arvados-sso-server-extras/arvados-sso-server.postinst
index 1ada186..e72d9b8 100755
--- a/jenkins/arvados-sso-server-extras/arvados-sso-server.postinst
+++ b/jenkins/arvados-sso-server-extras/arvados-sso-server.postinst
@@ -176,19 +176,15 @@ configure_version() {
   chmod 644 $SHARED_PATH/log/*
   echo "... done."
 
-  set +e
-  DB_MIGRATE_STATUS=`$COMMAND_PREFIX bundle exec rake db:migrate:status 2>&1`
-  DB_MIGRATE_STATUS_CODE=$?
-  set -e
-
-  if echo $DB_MIGRATE_STATUS | grep 'Schema migrations table does not exist yet.' >/dev/null; then
+  DB_MIGRATE_STATUS=`$COMMAND_PREFIX bundle exec rake db:migrate:status 2>&1 || true`
+  if echo $DB_MIGRATE_STATUS | grep -qF 'Schema migrations table does not exist yet.'; then
       # The database exists, but the migrations table doesn't.
       run_and_report "Setting up database" \
                      $COMMAND_PREFIX bundle exec rake db:schema:load db:seed
-  elif echo $DB_MIGRATE_STATUS | grep '^database: ' >/dev/null; then
+  elif echo $DB_MIGRATE_STATUS | grep -q '^database: '; then
       run_and_report "Running db:migrate" \
                      $COMMAND_PREFIX bundle exec rake db:migrate
-  elif echo $DB_MIGRATE_STATUS | grep 'database .* does not exist' >/dev/null; then
+  elif echo $DB_MIGRATE_STATUS | grep -q 'database .* does not exist'; then
       if ! run_and_report "Running db:setup" \
            $COMMAND_PREFIX bundle exec rake db:setup 2>/dev/null; then
           echo "Warning: unable to set up database." >&2

commit 22e7d0b5f113d25266f8316d4865b046cea34715
Author: Brett Smith <brett at curoverse.com>
Date:   Fri Jan 1 12:26:20 2016 -0500

    8014: Introduce run_and_report function to arvados-sso postinst.
    
    Use this to DRY up code that says "Doing something... done."
    This commit removes some `|| exit $?` that's redundant with `set -e`.

diff --git a/jenkins/arvados-sso-server-extras/arvados-sso-server.postinst b/jenkins/arvados-sso-server-extras/arvados-sso-server.postinst
index 530de46..1ada186 100755
--- a/jenkins/arvados-sso-server-extras/arvados-sso-server.postinst
+++ b/jenkins/arvados-sso-server-extras/arvados-sso-server.postinst
@@ -54,6 +54,23 @@ For RPM-based systems, then reinstall this package.
 EOF
 }
 
+run_and_report() {
+    # Usage: run_and_report ACTION_MSG CMD
+    # This is the usual wrapper that prints ACTION_MSG, runs CMD, then writes
+    # a message about whether CMD succeeded or failed.  Returns the exit code
+    # of CMD.
+    local action_message=$1; shift
+    local retcode=0
+    echo -n "$action_message..."
+    if "$@"; then
+        echo " done."
+    else
+        retcode=$?
+        echo " failed."
+    fi
+    return $retcode
+}
+
 setup_conffile() {
     # Usage: setup_conffile CONFFILE_PATH [SOURCE_PATH]
     # Both paths are relative to RELEASE_CONFIG_PATH.
@@ -140,18 +157,12 @@ configure_version() {
   cd "$RELEASE_PATH"
   export RAILS_ENV=production
 
-  echo "Making sure bundle is installed ..."
-  set +e
-  which bundle > /dev/null
-  if [[ "$?" != "0" ]]; then
-    $COMMAND_PREFIX gem install bundle
+  if ! $COMMAND_PREFIX bundle --version >/dev/null; then
+      run_and_report "Installing bundle" $COMMAND_PREFIX gem install bundle
   fi
-  set -e
-  echo "... done."
 
-  echo -n "Running bundle install ..."
-  $COMMAND_PREFIX bundle install --path $SHARED_PATH/vendor_bundle --quiet || exit $?
-  echo "... done."
+  run_and_report "Running bundle install" \
+      $COMMAND_PREFIX bundle install --path $SHARED_PATH/vendor_bundle --quiet
 
   echo -n "Ensuring directory and file permissions ..."
   # Ensure correct ownership of a few files
@@ -171,52 +182,35 @@ configure_version() {
   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 $?
-    echo "... done."
+      # The database exists, but the migrations table doesn't.
+      run_and_report "Setting up database" \
+                     $COMMAND_PREFIX bundle exec rake db:schema:load db:seed
   elif echo $DB_MIGRATE_STATUS | grep '^database: ' >/dev/null; then
-    echo -n "Running db:migrate ..."
-    $COMMAND_PREFIX bundle exec rake db:migrate || exit $?
-    echo "... done."
+      run_and_report "Running db:migrate" \
+                     $COMMAND_PREFIX bundle exec rake db:migrate
   elif echo $DB_MIGRATE_STATUS | grep 'database .* does not exist' >/dev/null; then
-    echo -n "Running db:setup ..."
-    set +e
-    $COMMAND_PREFIX bundle exec rake db:setup 2>/dev/null
-    if [ "$?" = "0" ]; then
-      echo "... done."
-    else
-      echo "... failed."
-      echo "Warning: unable to set up database." >&2
-      DATABASE_READY=0
-    fi
-    set -e
+      if ! run_and_report "Running db:setup" \
+           $COMMAND_PREFIX bundle exec rake db:setup 2>/dev/null; then
+          echo "Warning: unable to set up database." >&2
+          DATABASE_READY=0
+      fi
   else
     echo "Warning: Database is not ready to set up. Skipping database setup." >&2
     DATABASE_READY=0
   fi
 
-  echo -n "Precompiling assets ..."
   # precompile assets; thankfully this does not take long
   if [ "$APPLICATION_READY" = "1" ]; then
-    set +e
-    $COMMAND_PREFIX bundle exec rake assets:precompile -q -s 2>/dev/null
-    if [ "$?" = "0" ]; then
-      echo "... done."
-    else
-      echo "... failed."
-      APPLICATION_READY=0
-    fi
-    set -e
+      run_and_report "Precompiling assets" \
+          $COMMAND_PREFIX bundle exec rake assets:precompile -q -s 2>/dev/null \
+          || APPLICATION_READY=0
   else
-    echo "... skipped."
+      echo "Precompiling assets... skipped."
   fi
   chown -R "$WWW_OWNER" $RELEASE_PATH/tmp
 
   if [ ! -z "$WEB_SERVICE" ]; then
-    echo -n "Restarting $WEB_SERVICE ..."
-    service "$WEB_SERVICE" restart >/dev/null || exit $?
-    echo "... done."
+      service "$WEB_SERVICE" restart
   fi
 }
 

commit 12db554ba60b0d2e76d54bb67b6386088a8f3a2a
Author: Brett Smith <brett at curoverse.com>
Date:   Fri Jan 1 12:17:01 2016 -0500

    8014: Improve conffile handling in arvados-sso postinst.
    
    * DRY it up into a function.
    * DATABASE_READY and APPLICATION_READY care about whether the
      corresponding .yml file is usable.  Always detect when it is
      unmodified from the .yml.example file.
    * Build symlinks from /var/www to /etc in more cases where it's safe.

diff --git a/jenkins/arvados-sso-server-extras/arvados-sso-server.postinst b/jenkins/arvados-sso-server-extras/arvados-sso-server.postinst
index 3631bbe..530de46 100755
--- a/jenkins/arvados-sso-server-extras/arvados-sso-server.postinst
+++ b/jenkins/arvados-sso-server-extras/arvados-sso-server.postinst
@@ -4,6 +4,7 @@ set -e
 
 INSTALL_PATH=/var/www/arvados-sso
 RELEASE_PATH=$INSTALL_PATH/current
+RELEASE_CONFIG_PATH=$RELEASE_PATH/config
 SHARED_PATH=$INSTALL_PATH/shared
 CONFIG_PATH=/etc/arvados/sso
 PACKAGE_NAME=arvados-sso-server
@@ -53,6 +54,44 @@ For RPM-based systems, then reinstall this package.
 EOF
 }
 
+setup_conffile() {
+    # Usage: setup_conffile CONFFILE_PATH [SOURCE_PATH]
+    # Both paths are relative to RELEASE_CONFIG_PATH.
+    # This function will try to safely ensure that a symbolic link for
+    # the configuration file points from RELEASE_CONFIG_PATH to CONFIG_PATH.
+    # If SOURCE_PATH is given, this function will try to install that file as
+    # the configuration file in CONFIG_PATH, and return 1 if the file in
+    # CONFIG_PATH is unmodified from the source.
+    local conffile_relpath=$1; shift
+    local conffile_source=$1; shift
+    local release_conffile=$RELEASE_CONFIG_PATH/$conffile_relpath
+    local etc_conffile=$CONFIG_PATH/$(basename "$conffile_relpath")
+
+    # Note that -h can return true and -e will return false simultaneously
+    # when the target is a dangling symlink.  We're okay with that outcome,
+    # so check -h first.
+    if [ ! -h "$release_conffile" ]; then
+        if [ ! -e "$release_conffile" ]; then
+            ln -s "$etc_conffile" "$release_conffile"
+        # If there's a config file in /var/www identical to the one in /etc,
+        # overwrite it with a symlink.
+        elif cmp --quiet "$release_conffile" "$etc_conffile"; then
+            ln --force -s "$etc_conffile" "$release_conffile"
+        fi
+    fi
+
+    if [ -n "$conffile_source" ]; then
+        cp --no-clobber "$RELEASE_CONFIG_PATH/$conffile_source" "$etc_conffile"
+        # Even if $etc_conffile already existed, it might be unmodified from
+        # the source.  This is especially likely when a user installs, updates
+        # database.yml, then reconfigures before they update application.yml.
+        # Use cmp to be sure whether $etc_conffile is modified.
+        if cmp --quiet "$RELEASE_CONFIG_PATH/$conffile_source" "$etc_conffile"; then
+            return 1
+        fi
+    fi
+}
+
 configure_version() {
   WEB_SERVICE=${WEB_SERVICE:-$(service --status-all 2>/dev/null \
       | grep -Eo '\bnginx|httpd[^[:space:]]*' || true)}
@@ -85,36 +124,11 @@ configure_version() {
   echo
 
   echo -n "Symlinking files from $CONFIG_PATH ..."
-
-  if [ ! -f $CONFIG_PATH/database.yml ]; then
-    mkdir -p $CONFIG_PATH
-    cp $RELEASE_PATH/config/database.yml.example $CONFIG_PATH/database.yml
-    DATABASE_READY=0
-  fi
-
-  if [ ! -h $RELEASE_PATH/config/database.yml ]; then
-    ln -s $CONFIG_PATH/database.yml $RELEASE_PATH/config/database.yml
-  fi
-
-  if [ ! -f $CONFIG_PATH/production.rb ]; then
-    mkdir -p $CONFIG_PATH
-    cp $RELEASE_PATH/config/environments/production.rb.example $CONFIG_PATH/production.rb
-  fi
-
-  if [ ! -h $RELEASE_PATH/config/environments/production.rb ]; then
-    ln -s $CONFIG_PATH/production.rb $RELEASE_PATH/config/environments/production.rb
-  fi
-
-  if [ ! -f $CONFIG_PATH/application.yml ]; then
-    mkdir -p $CONFIG_PATH
-    cp $RELEASE_PATH/config/application.yml.example $CONFIG_PATH/application.yml
-    APPLICATION_READY=0
-  fi
-
-  if [ ! -h $RELEASE_PATH/config/application.yml ]; then
-    ln -s $CONFIG_PATH/application.yml $RELEASE_PATH/config/application.yml
-  fi
-
+  mkdir -p $CONFIG_PATH
+  setup_conffile database.yml database.yml.example || DATABASE_READY=0
+  setup_conffile environments/production.rb environments/production.rb.example \
+      || true
+  setup_conffile application.yml application.yml.example || APPLICATION_READY=0
   echo "... done."
 
   # Before we do anything else, make sure some directories and files are in place

commit 9dc65796e2f8b7b4342590ebd81ba5adaba8cc2f
Author: Brett Smith <brett at curoverse.com>
Date:   Fri Jan 1 11:10:05 2016 -0500

    8014: arvados-sso postinst recognizes versioned Nginx service names.

diff --git a/jenkins/arvados-sso-server-extras/arvados-sso-server.postinst b/jenkins/arvados-sso-server-extras/arvados-sso-server.postinst
index 05b331e..3631bbe 100755
--- a/jenkins/arvados-sso-server-extras/arvados-sso-server.postinst
+++ b/jenkins/arvados-sso-server-extras/arvados-sso-server.postinst
@@ -65,7 +65,8 @@ configure_version() {
   fi
 
   if [ -e /etc/redhat-release ]; then
-      if [ "$WEB_SERVICE" = "nginx" ]; then
+      # Recognize any service that starts with "nginx"; e.g., nginx16.
+      if [ "$WEB_SERVICE" != "${WEB_SERVICE#nginx}" ]; then
         WWW_OWNER=nginx:nginx
       else
         WWW_OWNER=apache:apache

commit 0fda88f571e51c3b437722c753380f231cbe14bb
Author: Brett Smith <brett at curoverse.com>
Date:   Fri Jan 1 11:02:46 2016 -0500

    8014: Refactor web service detection warnings in arvados-sso postinst.

diff --git a/jenkins/arvados-sso-server-extras/arvados-sso-server.postinst b/jenkins/arvados-sso-server-extras/arvados-sso-server.postinst
index ce15782..05b331e 100755
--- a/jenkins/arvados-sso-server-extras/arvados-sso-server.postinst
+++ b/jenkins/arvados-sso-server-extras/arvados-sso-server.postinst
@@ -37,35 +37,31 @@ EOF
     fi
 }
 
-configure_version() {
-  WEB_SERVICE=${WEB_SERVICE:-$(service --status-all 2>/dev/null \
-      | grep -Eo '\bnginx|httpd[^[:space:]]*' || true)}
-  if [ -z "$WEB_SERVICE" ]; then
+report_web_service_warning() {
+    local warning=$1; shift
     cat >&2 <<EOF
 
-Warning: web service (Nginx or Apache) not found.
+WARNING: $warning.
 
 To override, set the WEB_SERVICE environment variable to the name of the service
-hosting the Rails server. Alternativey, install nginx.
+hosting the Rails server.
 
 For Debian-based systems, then reconfigure this package with dpkg-reconfigure.
 
 For RPM-based systems, then reinstall this package.
 
 EOF
+}
+
+configure_version() {
+  WEB_SERVICE=${WEB_SERVICE:-$(service --status-all 2>/dev/null \
+      | grep -Eo '\bnginx|httpd[^[:space:]]*' || true)}
+  if [ -z "$WEB_SERVICE" ]; then
+    report_web_service_warning "Web service (Nginx or Apache) not found"
   elif [ "$WEB_SERVICE" != "$(echo "$WEB_SERVICE" | head -n 1)" ]; then
     WEB_SERVICE=$(echo "$WEB_SERVICE" | head -n 1)
-    cat >&2 <<EOF
-Warning: multiple web services found. Choosing the first one ($WEB_SERVICE).
-
-To override, set the WEB_SERVICE environment variable to the name of the service
-hosting the Rails server.
-
-For Debian-based systems, then reconfigure this package with dpkg-reconfigure.
-
-For RPM-based systems, then reinstall this package.
-
-EOF
+    report_web_service_warning \
+        "Multiple web services found.  Choosing the first one ($WEB_SERVICE)"
   fi
 
   if [ -e /etc/redhat-release ]; then

commit d916c778b0ceb07555998433dcdcde8b9e98d5d8
Author: Brett Smith <brett at curoverse.com>
Date:   Fri Jan 1 10:54:00 2016 -0500

    8014: Simplify COMMAND_PREFIX-setting code.

diff --git a/jenkins/arvados-sso-server-extras/arvados-sso-server.postinst b/jenkins/arvados-sso-server-extras/arvados-sso-server.postinst
index f7f1ee4..ce15782 100755
--- a/jenkins/arvados-sso-server-extras/arvados-sso-server.postinst
+++ b/jenkins/arvados-sso-server-extras/arvados-sso-server.postinst
@@ -12,6 +12,12 @@ DOC_URL="http://doc.arvados.org/install/install-sso.html#configure"
 DATABASE_READY=1
 APPLICATION_READY=1
 
+if [ -s "$HOME/.rvm/scripts/rvm" ] || [ -s "/usr/local/rvm/scripts/rvm" ]; then
+    COMMAND_PREFIX="/usr/local/rvm/bin/rvm-exec default"
+else
+    COMMAND_PREFIX=
+fi
+
 report_not_ready() {
     local ready_flag=$1; shift
     local config_file=$1; shift
@@ -31,22 +37,6 @@ EOF
     fi
 }
 
-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
-}
-
 configure_version() {
   WEB_SERVICE=${WEB_SERVICE:-$(service --status-all 2>/dev/null \
       | grep -Eo '\bnginx|httpd[^[:space:]]*' || true)}
@@ -221,11 +211,9 @@ EOF
 
 if [ "$1" = configure ]; then
   # This is a debian-based system
-  setup_ruby_environment
   configure_version
 elif [ "$1" = "0" ] || [ "$1" = "1" ] || [ "$1" = "2" ]; then
   # This is an rpm-based system
-  setup_ruby_environment
   configure_version
 fi
 

commit a977e885a73f18e484cd1b0d0d6051b145c3445e
Author: Brett Smith <brett at curoverse.com>
Date:   Fri Jan 1 10:51:01 2016 -0500

    8014: Refactor "not fully configured" messages in arvados-sso postinst.

diff --git a/jenkins/arvados-sso-server-extras/arvados-sso-server.postinst b/jenkins/arvados-sso-server-extras/arvados-sso-server.postinst
index 070796e..f7f1ee4 100755
--- a/jenkins/arvados-sso-server-extras/arvados-sso-server.postinst
+++ b/jenkins/arvados-sso-server-extras/arvados-sso-server.postinst
@@ -7,10 +7,30 @@ RELEASE_PATH=$INSTALL_PATH/current
 SHARED_PATH=$INSTALL_PATH/shared
 CONFIG_PATH=/etc/arvados/sso
 PACKAGE_NAME=arvados-sso-server
+DOC_URL="http://doc.arvados.org/install/install-sso.html#configure"
 
 DATABASE_READY=1
 APPLICATION_READY=1
 
+report_not_ready() {
+    local ready_flag=$1; shift
+    local config_file=$1; shift
+    if [ "1" != "$ready_flag" ]; then cat >&2 <<EOF
+
+PLEASE NOTE:
+
+The $PACKAGE_NAME package was not configured completely because
+$config_file needs some tweaking.
+Please refer to the documentation at
+<$DOC_URL> for more details.
+
+When $(basename "$config_file") has been modified,
+reconfigure or reinstall this package.
+
+EOF
+    fi
+}
+
 setup_ruby_environment() {
   if [ -s "$HOME/.rvm/scripts/rvm" ] ; then
     using_rvm="true"
@@ -209,32 +229,5 @@ elif [ "$1" = "0" ] || [ "$1" = "1" ] || [ "$1" = "2" ]; then
   configure_version
 fi
 
-if [ "$DATABASE_READY" = "0" ]; then
-  cat <<EOF
-
-PLEASE NOTE:
-
-The $PACKAGE_NAME package was not configured completely because
-$CONFIG_PATH/database.yml needs some tweaking. Please refer to the
-documentation at http://doc.arvados.org/install/install-sso.html#configure for
-more details.
-
-When database.yml has been modified, reconfigure or reinstall this package.
-EOF
-fi
-
-if [ "$APPLICATION_READY" = "0" ]; then
-  cat <<EOF
-
-PLEASE NOTE:
-
-The $PACKAGE_NAME package was not configured completely because
-$CONFIG_PATH/application.yml needs some tweaking. Please refer to the
-documentation at http://doc.arvados.org/install/install-sso.html#configure for
-more details.
-
-When application.yml has been modified, reconfigure or reinstall this package.
-EOF
-fi
-
-echo
+report_not_ready "$DATABASE_READY" "$CONFIG_PATH/database.yml"
+report_not_ready "$APPLICATION_READY" "$CONFIG_PATH/application.yml"

commit 31886f0d0fa271f9d7a5c8dadd553d2f95ba1318
Author: Brett Smith <brett at curoverse.com>
Date:   Fri Jan 1 10:41:23 2016 -0500

    8014: Remove unused $VERSION tracking from arvados-sso postinst.

diff --git a/jenkins/arvados-sso-server-extras/arvados-sso-server.postinst b/jenkins/arvados-sso-server-extras/arvados-sso-server.postinst
index 7423e5b..070796e 100755
--- a/jenkins/arvados-sso-server-extras/arvados-sso-server.postinst
+++ b/jenkins/arvados-sso-server-extras/arvados-sso-server.postinst
@@ -11,8 +11,6 @@ PACKAGE_NAME=arvados-sso-server
 DATABASE_READY=1
 APPLICATION_READY=1
 
-VERSION=`cat $RELEASE_PATH/git-commit.version`
-
 setup_ruby_environment() {
   if [ -s "$HOME/.rvm/scripts/rvm" ] ; then
     using_rvm="true"
@@ -29,12 +27,7 @@ setup_ruby_environment() {
   fi
 }
 
-# arguments: <major version> <most recently configured package version>
 configure_version() {
-  VERSION="$1"
-
-  [ "$VERSION" ] || { echo "Error: configure_version: need version parameter" >&2; exit 1; }
-
   WEB_SERVICE=${WEB_SERVICE:-$(service --status-all 2>/dev/null \
       | grep -Eo '\bnginx|httpd[^[:space:]]*' || true)}
   if [ -z "$WEB_SERVICE" ]; then
@@ -209,11 +202,11 @@ EOF
 if [ "$1" = configure ]; then
   # This is a debian-based system
   setup_ruby_environment
-  configure_version $VERSION "$2"
+  configure_version
 elif [ "$1" = "0" ] || [ "$1" = "1" ] || [ "$1" = "2" ]; then
   # This is an rpm-based system
   setup_ruby_environment
-  configure_version $VERSION
+  configure_version
 fi
 
 if [ "$DATABASE_READY" = "0" ]; then

commit 951eeb0cbc385704dea95eafa5c34e2bd294d29c
Author: Brett Smith <brett at curoverse.com>
Date:   Thu Dec 31 15:58:18 2015 -0500

    8014: Remove unused sso-server-upgrade.sh script.

diff --git a/jenkins/arvados-sso-server-extras/arvados-sso-server-upgrade.sh b/jenkins/arvados-sso-server-extras/arvados-sso-server-upgrade.sh
deleted file mode 100755
index 1a377dc..0000000
--- a/jenkins/arvados-sso-server-extras/arvados-sso-server-upgrade.sh
+++ /dev/null
@@ -1,91 +0,0 @@
-#!/bin/bash
-
-set -e
-
-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 <<EOF
-Error: nginx service not found. Aborting.
-Set NGINX_SERVICE to the name of the service hosting the Rails server.
-EOF
-    exit 1
-elif [ "$NGINX_SERVICE" != "$(echo "$NGINX_SERVICE" | head -n 1)" ]; then
-    cat >&2 <<EOF
-Error: multiple nginx services found. Aborting.
-Set NGINX_SERVICE to the name of the service hosting the Rails server.
-EOF
-    exit 1
-fi
-
-RELEASE_PATH=/var/www/arvados-sso/current
-SHARED_PATH=/var/www/arvados-sso/shared
-CONFIG_PATH=/etc/arvados/sso/
-
-echo
-echo "Assumption: $NGINX_SERVICE is configured to serve your SSO server URL from"
-echo "            /var/www/arvados-sso/current"
-echo "Assumption: configuration files are in /etc/arvados/sso/"
-echo "Assumption: $NGINX_SERVICE and passenger run as $WWW_OWNER"
-echo
-
-echo "Copying files from $CONFIG_PATH ..."
-cp -f $CONFIG_PATH/database.yml $RELEASE_PATH/config/database.yml
-cp -f $RELEASE_PATH/config/environments/production.rb.example $RELEASE_PATH/config/environments/production.rb
-cp -f $CONFIG_PATH/application.yml $RELEASE_PATH/config/application.yml
-echo "... done."
-
-# Before we do anything else, make sure some directories and files are in place
-if [[ ! -e $SHARED_PATH/log ]]; then mkdir -p $SHARED_PATH/log; fi
-if [[ ! -e $RELEASE_PATH/tmp ]]; then mkdir -p $RELEASE_PATH/tmp; fi
-if [[ ! -e $RELEASE_PATH/log ]]; then ln -s $SHARED_PATH/log $RELEASE_PATH/log; fi
-if [[ ! -e $SHARED_PATH/log/production.log ]]; then touch $SHARED_PATH/log/production.log; fi
-
-cd "$RELEASE_PATH"
-export RAILS_ENV=production
-
-echo "Running bundle install ..."
-bundle install --path $SHARED_PATH/vendor_bundle --quiet
-echo "... done."
-
-echo "Ensuring directory and file permissions ..."
-# Ensure correct ownership of a few files
-chown "$WWW_OWNER" $RELEASE_PATH/config/environment.rb
-chown "$WWW_OWNER" $RELEASE_PATH/config.ru
-chown "$WWW_OWNER" $RELEASE_PATH/config/database.yml
-chown "$WWW_OWNER" $RELEASE_PATH/Gemfile.lock
-chown -R "$WWW_OWNER" $RELEASE_PATH/tmp
-chown -R "$WWW_OWNER" $SHARED_PATH/log
-chown "$WWW_OWNER" $RELEASE_PATH/db/schema.rb
-chmod 644 $SHARED_PATH/log/*
-echo "... done."
-
-# If we use `grep -q`, rake will write a backtrace on EPIPE.
-if bundle exec rake db:migrate:status | grep '^database: ' >/dev/null; then
-    echo "Starting db:migrate ..."
-    bundle exec rake db:migrate
-elif [ 0 -eq ${PIPESTATUS[0]} ]; then
-    # The database exists, but the migrations table doesn't.
-    echo "Setting up database ..."
-    bundle exec rake db:schema:load db:seed
-else
-    echo "Error: Database is not ready to set up. Aborting." >&2
-    exit 1
-fi
-echo "... done."
-
-echo "Precompiling assets ..."
-# precompile assets; thankfully this does not take long
-bundle exec rake assets:precompile -q -s
-echo "... done."
-
-echo "Restarting nginx ..."
-service "$NGINX_SERVICE" restart
-echo "... done."

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list