From 25b0f35ef2c06021e23cedd156306c16f25389c5 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Thu, 30 Jul 2015 18:10:45 -0400 Subject: [PATCH] Refactor eg-updater for flexibility/simplicity Replace the various "don't perform X" commands with a simpler set of "do perform X" commands. This simpliefies the logic and gives us more control over the behaviour. eg-brick-manager.sh is updated to reflect eg-updater.sh changes. Signed-off-by: Bill Erickson --- KCLS/admin-scripts/eg-brick-manager.sh | 72 ++------- KCLS/admin-scripts/eg-updater.sh | 269 +++++++++++---------------------- 2 files changed, 100 insertions(+), 241 deletions(-) diff --git a/KCLS/admin-scripts/eg-brick-manager.sh b/KCLS/admin-scripts/eg-brick-manager.sh index d41030af34..d95aff8ae9 100755 --- a/KCLS/admin-scripts/eg-brick-manager.sh +++ b/KCLS/admin-scripts/eg-brick-manager.sh @@ -47,16 +47,16 @@ function usage { Roll all testing bricks and leave detached: - $0 -c testing -a roll + $0 -c testing -a stop-all,start-all Roll all testing bricks and attach: - $0 -c testing -a roll-attach + $0 -c testing -a stop-all,start-all,attach - Deploy the 'kcls-2.5.001' git tag to all bricks by - passing arguments via -e: + Deploy the 'kcls-2.5.001' git tag to all bricks and leave + services stopped. - $0 -c testing -e "-t kcls-2.5.001 -i kcls-2.5" + $0 -c testing -a stop-all,deploy-all -e "-t kcls-2.5.001 -i kcls-2.5" Options: -c @@ -72,35 +72,14 @@ function usage { for full list of supported options. -a - Short-cut for commonly used operations. - - Note: "fast" options take bricks out of rotation - immediately, which could interrupt active transactions. - Avoid use of "fast" options in production. - - Supported actions: - - roll - detach, restart services + apache - roll-fast - detach w/o wait, restart services + apache - roll-attach - detach, restart services + apache, attach - roll-attach-fast - detach w/o wait, restart services + apache, attach - stop - detach, stop services, stop apache - stop-fast - detach without wait, stop services, stop apache - start - start services, start apache - start-attach - start services, start apache, attach. - detach - detach only - attach - attach only - -l + See eg-updater.sh actions. This is a direct pass-through. + + -l List servers for the requested cluster -p Prompt to continue or exit between each server - -g - Prompt to continue or exit before attaching a server. - This is useful for testing a server before putting it - back into rotation. - USAGE exit } @@ -127,39 +106,7 @@ function inspect_args { fi if [ -n "$ACTION" ]; then - if [ "$ACTION" = "roll" ]; then - EG_UPDATER_OPS="-o" - elif [ "$ACTION" = "roll-fast" ]; then - EG_UPDATER_OPS="-do" - elif [ "$ACTION" = "roll-attach" ]; then - if [ -n "$PROMPT_ATTACH" ]; then - EG_UPDATER_OPS="-og" - else - EG_UPDATER_OPS="-oa" - fi; - elif [ "$ACTION" = "roll-attach-fast" ]; then - if [ -n "$PROMPT_ATTACH" ]; then - EG_UPDATER_OPS="-dog" - else - EG_UPDATER_OPS="-doa" - fi; - elif [ "$ACTION" = "stop" ]; then - EG_UPDATER_OPS="-l" - elif [ "$ACTION" = "stop-fast" ]; then - EG_UPDATER_OPS="-ld" - elif [ "$ACTION" = "start" ]; then - EG_UPDATER_OPS="-m" - elif [ "$ACTION" = "start-attach" ]; then - if [ -n "$PROMPT_ATTACH" ]; then - EG_UPDATER_OPS="-mg" - else - EG_UPDATER_OPS="-ma" - fi; - elif [ "$ACTION" = "detach" ]; then - EG_UPDATER_OPS="-u" - elif [ "$ACTION" = "attach" ]; then - EG_UPDATER_OPS="-v" - fi + EG_UPDATER_OPS="$EG_UPDATER_OPS -a $ACTION" fi if [ -z "$LIST_SERVERS" -a -z "$EG_UPDATER_OPS" ]; then @@ -174,7 +121,6 @@ while getopts "c:e:a:s:lpg" opt; do a) ACTION="$OPTARG";; l) LIST_SERVERS="1";; p) PROMPT="1";; - g) PROMPT_ATTACH="1";; s) SERVER="$OPTARG";; h|*) usage; esac diff --git a/KCLS/admin-scripts/eg-updater.sh b/KCLS/admin-scripts/eg-updater.sh index 6a8fa7638d..ca11098f45 100755 --- a/KCLS/admin-scripts/eg-updater.sh +++ b/KCLS/admin-scripts/eg-updater.sh @@ -20,8 +20,6 @@ OWNER=$(stat -c %U $EVERGREEN_BASE); BUILDER="" OSRF="" GIT="git" -DETACH_NEEDED="YES" - # command line arguments GIT_TAG="" @@ -30,19 +28,8 @@ GIT_PULL="" CLIENT_BUILD_ID="" CLIENT_SERIES_ID="" GIT_REMOTE="kcls" -REATTACH="" -SKIP_APACHE="" -WEB_ONLY="" REBUILD="" -BUILD_XUL="" -RESTART_ONLY="" -STAFF_CLIENT_ONLY="" -STOP_ONLY="" -START_ONLY="" -ATTACH_ONLY="" -DETACH_ONLY="" -CONFIRM_ATTACH="" -NO_DETACH_SLEEP="" +ACTIONS="" # if the script exits early, SUCCESS will be left as 0, # which is our sign to warn the user. @@ -54,27 +41,36 @@ function usage { Synopsis: - Deploy the Git tag 'kcls-2.4.001', using a staff client build - ID of 'kcls-2.4.001'. - - $0 -t kcls-2.4.001 + Deploy the Git tag 'kcls-2.5.001', using a staff client build + ID of 'kcls-2.5.001' and a series ID of kcls-2.5. - Check out and update the git branch 'dev/berick/abc-123-foobar', - then deploy with a staff client build ID of 'rel_2_4_1' + $0 -t kcls-2.5.001 -i kcls-2.5 -a stop-all,deploy-all - $0 -b dev/berick/abc-123-foobar -s rel_2_4_1 + The same, but instead of a tag, check out and update the git + branch 'dev/berick/abc-123-foobar', then start services. - Pull changes to the currently checked out branch, then - copy only the web files into place. - - $0 -w -p + $0 -b dev/berick/abc-123-foobar -s kcls-2.5.001 -i kcls-2.5 \ + -a stop-all,deploy-all,start-all Options: - -o - Restart Evergreen/Apache services only. No code is - updated or installed. - + -a actions + Comma-separated list of actions to perform. Options: + + detach + stop-apache + stop-eg + update-eg + deploy-eg + update-web + build-eg-staff + start-eg + start-apache + attach + stop-all (detach,stop-apache,stop-eg) + deploy-all (update-eg,deploy-eg,build-eg-staff) + start-all (start-eg,start-apache) + -p 'git pull' the currently checked out branch. @@ -103,24 +99,6 @@ function usage { -r Defaults to "kcls". - -a - Automatically reattach the brick after the update. This is - useful if there is no desire to manually test the brick - after the update. The default is to leave detached. - - -g - Prompt to continue before attaching. This is useful for - testing a server before putting it back into rotation. - - -n - Do not stop/start Apache. This is useful for non-brick - servers, like SIP, etc. servers. - - -w - Update web files only. Instead of running the full make / - install dance, directly copy web files into place. This - is ideal for rapid UI development. - -c Run the full autoreconf, configure, and 'make clean' steps when building Evergreen. These are generally only needed @@ -128,36 +106,13 @@ function usage { (-b) is used, since checking out a branch results in a 'git reset --hard', forcing configure, etc. to run anyway. - -x - Build a XUL client and place it in the published "builds" - directory. This happens alongside a build/install/restart. - See -k for staff client building only. - - -k Build a XUL client without performing any other installation - or restart actions. Flags -p, -t, -b are honored if - specified. - -f Service startup sleep time in seconds. Defaults to $START_SLEEP. Increase this value if autogen regularly fails. - -d No sleep after detach. This is useful for quickly stopping - an entire cluster. - - -u - Detach server (via ping.txt) - - -v - Attach server (via ping.txt) - - -l - Detach, stop services, stop apache - - -m - Start services, start apache, leave detached. Combine - with -a to also attach. - + -d Number of seconds to wait after detach. The default is + $DETACH_SLEEP. USAGE trap - EXIT @@ -194,26 +149,6 @@ function set_builder { function inspect_params { - if [ -n "$NO_DETACH_SLEEP" ]; then - DETACH_SLEEP=0; - fi - - # no need to detach the brick when not restarting services - if [ -n "$STAFF_CLIENT_ONLY" -o -n "$WEB_ONLY" \ - -o -n "$START_ONLY" -o -n "$ATTACH_ONLY" ]; then - DETACH_NEEDED="" - fi - - if [ -n "$ATTACH_ONLY" ]; then - REATTACH="YES" - return - fi - - if [ -n "$RESTART_ONLY" -o -n "$DETACH_ONLY" ]; then - # these trump other variables. - return - fi - if [ -z "$CLIENT_BUILD_ID" -a -n "$GIT_TAG" ]; then # default to using the git tag if no client build ID is provided CLIENT_BUILD_ID="$GIT_TAG"; @@ -233,9 +168,16 @@ function inspect_params { REBUILD="YES"; fi - if [ -n "$STOP_ONLY" -a -n "$START_ONLY" ]; then - announce "Cannot combined -l and -m. Use -o to restart" - exit 1 + if [[ "$ACTIONS" =~ "stop-all" ]]; then + ACTIONS="$ACTIONS,detach,stop-apache,stop-eg"; + fi + + if [[ "$ACTIONS" =~ "deploy-all" ]]; then + ACTIONS="$ACTIONS,update-eg,deploy-eg,build-eg-staff"; + fi + + if [[ "$ACTIONS" =~ "start-all" ]]; then + ACTIONS="$ACTIONS,start-eg,start-apache" fi } @@ -320,7 +262,7 @@ function publish_staff_client_build { # build the staff client first, so we can get a build # directory whose stamp ID matches the series but whose # version matches the build ID. - if [ -n "$BUILD_XUL" ]; then + if [[ "$ACTIONS" =~ "build-staff" ]]; then build_staff_client; fi @@ -539,28 +481,19 @@ function start_services { trap on_exit EXIT; -while getopts "t:b:r:s:i:f:pagnwchxoklmuvd" opt; do +while getopts "a:t:b:r:s:i:f:d:pchl" opt; do case $opt in - a) REATTACH="YES";; + a) ACTIONS="$OPTARG";; b) GIT_BRANCH="$OPTARG";; c) REBUILD="YES";; - d) NO_DETACH_SLEEP="YES";; + d) DETACH_SLEEP="$OPTARG";; f) START_SLEEP="$OPTARG";; - g) CONFIRM_ATTACH="YES";; i) CLIENT_SERIES_ID="$OPTARG";; - k) STAFF_CLIENT_ONLY="YES";; l) STOP_ONLY="YES";; - m) START_ONLY="YES";; - n) SKIP_APACHE="YES";; - o) RESTART_ONLY="YES";; p) GIT_PULL="YES";; r) GIT_REMOTE="$OPTARG";; s) CLIENT_BUILD_ID="$OPTARG";; t) GIT_TAG="$OPTARG";; - u) DETACH_ONLY="YES";; - v) ATTACH_ONLY="YES";; - w) WEB_ONLY="YES";; - x) BUILD_XUL="YES";; h) usage; esac done; @@ -568,98 +501,78 @@ done; set_builder; inspect_params; -if [ -n "$DETACH_NEEDED" ]; then +cd $EVERGREEN_BASE; +if [[ "$ACTIONS" =~ "detach" ]]; then if [ ! -f $PING_FILE ]; then announce "No ping file found." else announce "Detaching brick" $OSRF mv $PING_FILE $PING_FILE- - if [ -z "$DETACH_ONLY" ]; then - # avoid detach sleep when only detaching - announce "Sleeping $DETACH_SLEEP seconds after detach" - sleep $DETACH_SLEEP - fi + announce "Sleeping $DETACH_SLEEP seconds after detach" + sleep $DETACH_SLEEP fi -fi; +fi -cd $EVERGREEN_BASE; +if [[ "$ACTIONS" =~ "stop-apache" ]]; then + set +e # temporarily disable exit-on-error setting + service apache2 status 2>&1 > /dev/null + stat=$? + set -e + if [ $stat -eq 0 ]; then # apache running + announce "Stopping Apache" + sudo service apache2 stop > /dev/null + else + announce "Apache not running" + fi +fi -if [ -n "$WEB_ONLY" ]; then - # web-only updates don't require restarts. - fetch_code # no-op if no code options are specified - deploy_web +if [[ "$ACTIONS" =~ "stop-eg" ]]; then + announce "Stopping services" + $OSRF /openils/bin/osrf_control --localhost \ + --fast-shutdown-all > /dev/null +fi -elif [ -n "$STAFF_CLIENT_ONLY" ]; then - fetch_code # no-op if no code options are specified +if [[ "$ACTIONS" =~ "update-eg" ]]; then + fetch_code build_code - build_staff_client - -elif [ -n "$DETACH_ONLY" ]; then - SUCCESS=1 - exit; - -elif [ -z "$ATTACH_ONLY" ]; then - - if [ -z "$SKIP_APACHE" -a -z "$START_ONLY" ]; then - set +e # temporarily disable exit-on-error setting - service apache2 status 2>&1 > /dev/null - stat=$? - set -e - if [ $stat -eq 0 ]; then # apache running - announce "Stopping Apache" - sudo service apache2 stop > /dev/null - else - announce "Apache not running" - fi - fi +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. - if [ -z "$START_ONLY" ]; then - announce "Stopping services" - $OSRF /openils/bin/osrf_control --localhost \ - --fast-shutdown-all > /dev/null - fi +if [[ "$ACTIONS" =~ "deploy-eg" ]]; then + deploy_code +fi - if [ -n "$RESTART_ONLY" -o -n "$START_ONLY" ]; then - sleep 1; - start_services; +if [[ "$ACTIONS" =~ "update-web" ]]; then + deploy_web +fi - elif [ -z "$STOP_ONLY" ]; then - fetch_code; - build_code; - deploy_code; - start_services; +if [[ "$ACTIONS" =~ "build-staff" ]]; then + build_staff_client +fi - announce "Running autogen" - $OSRF /openils/bin/autogen.sh > /dev/null - fi +if [[ "$ACTIONS" =~ "start-eg" ]]; then + start_services; + announce "Running autogen" + $OSRF /openils/bin/autogen.sh > /dev/null +fi - if [ -z "$SKIP_APACHE" -a -z "$STOP_ONLY" ]; then - announce "Starting Apache" - sudo service apache2 start > /dev/null - fi; +if [[ "$ACTIONS" =~ "start-apache" ]]; then + announce "Starting Apache" + sudo service apache2 start > /dev/null fi -if [ -f $PING_FILE- -a -z "$STOP_ONLY" ]; then # we detached - if [ -n "$REATTACH" -o -n "$CONFIRM_ATTACH" ]; then - if [ -z "$ATTACH_ONLY" ]; then - if [ -n "$CONFIRM_ATTACH" ]; then - announce "Press 'Enter' to attach server. Control-c to exit." - read X - else - announce "Sleeping $START_SLEEP seconds before attach" - sleep $START_SLEEP; - fi +if [[ "$ACTIONS" =~ "attach" ]]; then + if [ -f $PING_FILE- ]; then + if [[ "$ACTIONS" =~ "start-apache" ]]; then + # if we just started apache, give it + # time to fire up before attaching + announce "Sleeping $START_SLEEP seconds before attach" + sleep $START_SLEEP; fi announce "Attaching brick" $OSRF mv $PING_FILE- $PING_FILE - else - announce "Brick is still detached! Use -a to automatically re-attach" - fi + fi; fi; SUCCESS=1 -- 2.11.0