From bbe9efecdf2033fc76e4f00121c387460412110b Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Thu, 19 Mar 2015 16:12:55 -0400 Subject: [PATCH] eg-updater chown/restart improvements * Navigate NFS shares when chowning /openils after an install. * Add -o option for performing restart only (no code updates). * Add -f option to modify service startup sleep time. Some servers take a lot longer than others for all services to start up. Signed-off-by: Bill Erickson --- KCLS/admin-scripts/eg-updater.sh | 110 +++++++++++++++++++++++++++++++++------ 1 file changed, 94 insertions(+), 16 deletions(-) diff --git a/KCLS/admin-scripts/eg-updater.sh b/KCLS/admin-scripts/eg-updater.sh index fcc8b9da77..260280550f 100755 --- a/KCLS/admin-scripts/eg-updater.sh +++ b/KCLS/admin-scripts/eg-updater.sh @@ -35,6 +35,7 @@ SKIP_APACHE="" WEB_ONLY="" REBUILD="" BUILD_XUL="" +RESTART_ONLY="" # if the script exits early, SUCCESS will be left as 0, # which is our sign to warn the user. @@ -62,6 +63,10 @@ function usage { $0 -d -w -p Options: + + -o + Restart Evergreen/Apache services only. No code is + updated or installed. -p 'git pull' the currently checked out branch. @@ -122,6 +127,11 @@ function usage { Build a XUL client and place it in the published "builds" directory. + -f + Service startup sleep time in seconds. Defaults to + $START_SLEEP. Increase this value if autogen regularly + fails. + USAGE trap - EXIT exit; @@ -346,6 +356,59 @@ function copy_custom_files { } +function recover_opensrf_file_ownership { + # opensrf always owns /openils, but /openils has NFS shares in + # multi-box environments. Using find + chown to skip NFS dirs still + # turns out to be a slow process, since it results in a lot of + # individual file chowns instead of recursive chowns. + # This approach ensures all non-NFS shares are modified and runs quickly. + set +e # chown returns non-zero on various failures we can ignore + + fstype=$(stat --file-system -c %T /openils/var/data/offline) + + if [ "$fstype" != "nfs" ]; then + # if the offline directory is not an NFS share, assume this + # server has no NFS shares under /openils. + announce "Assuming no NFS shares present" + sudo chown -R opensrf:opensf /openils 2> /dev/null + return + fi + + # otherwise recursively chown where possible, safely avoid + # the typical /openils NFS shares. + + announce "Navigating NFS shares" + + for dir in /openils/*; do + if [ $(basename $dir) != 'var' ]; then + sudo chown -R opensrf:opensrf $dir 2> /dev/null + fi + done + + for dir in /openils/var/*; do + if [ $(basename $dir) != "web" \ + -a $(basename $dir) != "data" ]; then + sudo chown -R opensrf:opensrf $dir 2> /dev/null + fi + done + + # /openils/var/data/vandelay is staging only + for dir in /openils/var/data/*; do + if [ $(basename $dir) != "offline" \ + -a $(basename $dir) != "vandelay" ]; then + sudo chown -R opensrf:opensrf $dir 2> /dev/null + fi + done + + for dir in /openils/var/web/*; do + if [ $(basename $dir) != "reporter" ]; then + sudo chown -R opensrf:opensrf $dir 2> /dev/null + fi + done + set -e +} + + function deploy_code { announce "Building and installing Evergreen" @@ -382,16 +445,19 @@ function deploy_code { # recover ownership of repo files after sudo/install sudo chown -R $OWNER:$OWNER $EVERGREEN_BASE - announce "Running post-install steps" + announce "Chowning /openils" - # opensrf always owns /openils - set +e # chown returns non-zero on R/O NFS shares - sudo chown -R opensrf:opensrf /openils > /dev/null 2>&1; - set -e + recover_opensrf_file_ownership + + announce "Publishing staff client build" publish_staff_client_build; copy_custom_files; +} + +function start_services { + announce "Starting services" if [ -n "$OSRF" ]; then @@ -406,22 +472,20 @@ function deploy_code { # give services a chance to start up announce "Giving services $START_SLEEP seconds to start up" sleep $START_SLEEP; - - announce "Running autogen" - $OSRF /openils/bin/autogen.sh > /dev/null } # -- script starts here -- trap on_exit EXIT; -while getopts "t:b:r:s:i:pdanwchx" opt; do +while getopts "t:b:r:s:i:f:pdanwchxo" opt; do case $opt in t) GIT_TAG="$OPTARG";; b) GIT_BRANCH="$OPTARG";; r) GIT_REMOTE="$OPTARG";; s) CLIENT_BUILD_ID="$OPTARG";; i) CLIENT_SERIES_ID="$OPTARG";; + f) START_SLEEP="$OPTARG";; p) GIT_PULL="YES";; d) SKIP_DETACH="YES";; a) REATTACH="YES";; @@ -429,12 +493,16 @@ while getopts "t:b:r:s:i:pdanwchx" opt; do w) WEB_ONLY="YES";; c) REBUILD="YES";; x) BUILD_XUL="YES";; + o) RESTART_ONLY="YES";; h|*) usage; esac done; set_builder; -inspect_params; +if [ -z "$RESTART_ONLY" ]; then + # restart trumps all other commands. + inspect_params; +fi if [ -z "$SKIP_DETACH" ]; then @@ -457,6 +525,11 @@ if [ -n "$WEB_ONLY" ]; then deploy_web else + if [ -z "$SKIP_APACHE" ]; then + announce "Stopping Apache" + sudo service apache2 stop > /dev/null + fi + # Note the use of --fast-shutdown-all, which is faster than the # default graceful shutdown. We don't need graceful shutdown, # since we will not be stopping potentially active services. @@ -464,13 +537,18 @@ else $OSRF /openils/bin/osrf_control --localhost \ --fast-shutdown-all > /dev/null - if [ -z "$SKIP_APACHE" ]; then - announce "Stopping Apache" - sudo service apache2 stop > /dev/null - fi + if [ -n "$RESTART_ONLY" ]; then + sleep 1; + start_services; + + else + fetch_code; + deploy_code; + start_services; - fetch_code; - deploy_code; + announce "Running autogen" + $OSRF /openils/bin/autogen.sh > /dev/null + fi if [ -z "$SKIP_APACHE" ]; then announce "Starting Apache" -- 2.11.0