[ARVADOS-DEV] created: 656b5e388467792f437caf1afa032dd4d36b2eb1

git at public.curoverse.com git at public.curoverse.com
Fri Sep 25 21:42:48 EDT 2015


        at  656b5e388467792f437caf1afa032dd4d36b2eb1 (commit)


commit 656b5e388467792f437caf1afa032dd4d36b2eb1
Author: Ward Vandewege <ward at curoverse.com>
Date:   Fri Sep 25 21:42:29 2015 -0400

    First commit.
    
    refs #7330

diff --git a/jenkins/arvados-sso-server-extras/arvados-sso-server.postinst b/jenkins/arvados-sso-server-extras/arvados-sso-server.postinst
new file mode 100755
index 0000000..383d25c
--- /dev/null
+++ b/jenkins/arvados-sso-server-extras/arvados-sso-server.postinst
@@ -0,0 +1,148 @@
+#!/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: <major version> <most recently configured package version>
+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 <<EOF
+Error: nginx service not found. Aborting.
+
+Set NGINX_SERVICE to the name of the service hosting the Rails server
+and reconfigure this package with dpkg-reconfigure.
+
+EOF
+      exit 0
+  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
+and reconfigure this package with dpkg-reconfigure.
+
+EOF
+      exit 0
+  fi
+
+  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 -n "Symlinking files from $CONFIG_PATH ..."
+
+  if [ ! -h $RELEASE_PATH/config/database.yml ]; then
+    ln -s $CONFIG_PATH/database.yml $RELEASE_PATH/config/database.yml
+  fi
+  if [ ! -h $RELEASE_PATH/config/environments/production.rb ]; then
+    if [ ! -f $CONFIG_PATH/production.rb ]; then
+      cp $RELEASE_PATH/config/environments/production.rb.example $CONFIG_PATH/production.rb
+    fi
+    ln -s $CONFIG_PATH/production.rb $RELEASE_PATH/config/environments/production.rb
+  fi
+  if [ ! -h $RELEASE_PATH/config/application.yml ]; then
+    ln -s $CONFIG_PATH/application.yml $RELEASE_PATH/config/application.yml
+  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 -n "Running bundle install ..."
+  $COMMAND_PREFIX bundle install --path $SHARED_PATH/vendor_bundle --quiet || exit $?
+  echo "... done."
+
+  echo -n "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."
+
+  ls -laF $RELEASE_PATH/tmp
+
+  # If we use `grep -q`, rake will write a backtrace on EPIPE.
+  if $COMMAND_PREFIX bundle exec rake db:migrate:status | grep '^database: ' >/dev/null; then
+      echo -n "Running db:migrate ..."
+      $COMMAND_PREFIX bundle exec rake db:migrate || exit $?
+  elif [ 0 -eq ${PIPESTATUS[0]} ]; 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 $?
+  else
+      echo "Error: Database is not ready to set up. Aborting." >&2
+      exit 1
+  fi
+  echo "... done."
+
+  ls -laF $RELEASE_PATH/tmp
+
+  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."
+
+  ls -laF $RELEASE_PATH/tmp
+
+  echo -n "Restarting nginx ..."
+  service "$NGINX_SERVICE" restart || exit $?
+  echo "... done."
+  echo
+}
+
+if [ "$1" = configure ]; then
+  setup_ruby_environment
+  configure_version $VERSION "$2"
+fi
+
+
diff --git a/jenkins/arvados-sso-server-extras/postinst.sh b/jenkins/arvados-sso-server-extras/postinst.sh
deleted file mode 100755
index ffd9b14..0000000
--- a/jenkins/arvados-sso-server-extras/postinst.sh
+++ /dev/null
@@ -1,12 +0,0 @@
-#!/bin/bash
-
-cd /var/www/arvados-sso
-
-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/run-build-packages-sso.sh b/jenkins/run-build-packages-sso.sh
index f985882..6c3c03b 100755
--- a/jenkins/run-build-packages-sso.sh
+++ b/jenkins/run-build-packages-sso.sh
@@ -173,19 +173,21 @@ fi
 
 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.
+# 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.
-# The .git directory is excluded by git implicitly, so we can't pick it up from .gitignore.
-# The packages directory needs to be explictly excluded here because it will only be listed
+# 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/postinst.sh")
+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")
 
 if [[ "$BUILD_BUNDLE_PACKAGES" != 0 ]]; then
   # This is the complete package with vendor/bundle included.
@@ -211,7 +213,7 @@ for i in "${fpm_depends[@]}"; do
   COMMAND_ARR+=('--depends' "$i")
 done
 COMMAND_ARR+=("${fpm_args[@]}")
-COMMAND_ARR+=("$WORKSPACE/=/var/www/arvados-sso/current" "$RUN_BUILD_PACKAGES_PATH/arvados-sso-server-extras/arvados-sso-server-upgrade.sh=/usr/local/bin/arvados-sso-server-upgrade.sh")
+COMMAND_ARR+=("$WORKSPACE/=/var/www/arvados-sso/current")
 debug_echo -e "\n${COMMAND_ARR[@]}\n"
 
 FPM_RESULTS=$("${COMMAND_ARR[@]}")

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


hooks/post-receive
-- 




More information about the arvados-commits mailing list