created an external brick configuration file
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 28 Jan 2008 23:20:29 +0000 (23:20 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 28 Jan 2008 23:20:29 +0000 (23:20 +0000)
brick_ctl can now take disparate sets of IPs for the master and drones
removed the linux-specific IP grepping in favor of the configured IPs
made xul building more flexible
general cleanup

committing example config file

git-svn-id: svn://svn.open-ils.org/ILS/trunk@8523 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/support-scripts/brick_ctl.sh
Open-ILS/src/support-scripts/oils_brick.cfg.example [new file with mode: 0644]

index e64674b..35e01c0 100755 (executable)
@@ -1,40 +1,32 @@
 #!/bin/bash
-# -------------------------------------------------------------------
-#
-# XXX This probably only works on Linux for now...
+# ---------------------------------------------------------------
+# Copyright (C) 2007-2008  Georgia Public Library Service
 #
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# ---------------------------------------------------------------
+
+# -------------------------------------------------------------------
 # This script is used to manage "bricks", which are collections of
 # servers all serving a single OpenSRF domain.  There will be 1
-# lead machine, which will typcically run this script, and 1 or more
+# master machine, which will typcically run this script, and 1 or more
 # drones, which respond to this script.
-#
-# XXX The fetching and build commands need to be updated to work
-# with the now-separated OpenSRF 0.9 and Evergreen 1.2 
 # -------------------------------------------------------------------
-[ -f /etc/profile ] && . /etc/profile
-[ -f ~/.bashrc ] && . ~/.bashrc
-
-DRONE_COUNT=2; # how many drones are in this brick
-ETH_DEV="eth0" # ethernet device 
-PREFIX="/openils" # the installed ILS files prefix
 
-# this is useful if you are using ldirector.  we can
-# "detach" a brick by removing the ldirector ping file
-LDIRECTOR_FILE="/$PREFIX/var/web/ldirectorping.txt"
+# TODO finish the download and build functionality
 
-# XXX needs work
-SRC_DIR="/home/opensrf/ILS";
 
-STAFF_CLIENT_BUILD_ID="sc_v100_rc2";
-XUL_BASE="/$PREFIX/var/web/xul";
-
-IP_PREFIX=$(/sbin/ifconfig | grep -A1 $ETH_DEV | grep inet | cut -d'.' -f1,2,3 | cut -d':' -f2);
-IP=$(/sbin/ifconfig | grep -A1 $ETH_DEV | grep inet | cut -d'.' -f 4 | cut -d' ' -f1);
-FIRST=$(expr $IP + 1);
-LAST=$(expr $IP + $DRONE_COUNT);
+[ -f /etc/profile ] && . /etc/profile
+[ -f ~/.bashrc ] && . ~/.bashrc
 
-OSRF_PID_DIR="/tmp/";
-OSRF_CONFIG="/$PREFIX/conf/opensrf_core.xml";
+DEFAULT_CONFIG=~/.oils_brick.cfg
 LOCAL_BASE="osrf_ctl.sh -d $OSRF_PID_DIR -c $OSRF_CONFIG";
 DRONE_BASE=". /etc/profile && osrf_ctl.sh -d $OSRF_PID_DIR -c $OSRF_CONFIG";
 
@@ -44,175 +36,186 @@ DRONE_BASE=". /etc/profile && osrf_ctl.sh -d $OSRF_PID_DIR -c $OSRF_CONFIG";
 # -------------------------------------------------------------------
 [ $(whoami) != 'opensrf' ] && echo 'Must run as user "opensrf"' && exit;
 
+
 function usage {
-       echo "";        
-       echo "usage: $0 -a <action>"
-       echo "  -u <base_url> : host + path URL where the download file lives";
-       echo "  -f <build_file> : the name of the bundle to fetch";
-       echo "  -x <xul_dir> : the destination xul directory";
-       echo "Actions:";        
-       echo "  fetch";
-       echo "  start_perl";
-       echo "  start_c";
-       echo "  start_perl_c";
-       echo "  start_all";
-       echo "  stop_perl";
-       echo "  stop_c";
-       echo "  stop_perl_c";
-       echo "  stop_all";
-       echo "  restart_perl";
-       echo "  restart_c";
-       echo "  restart_perl_c";
-       echo "  restart_all";
-       echo "  build";
-       echo "  build_xul";
-       echo "  detach_brick";
-       echo "  attach_brick";
-       exit 0;
+    echo "";    
+    echo "usage: $0 -a <action>"
+    echo "  -u <base_url> : host + path URL where the download file lives";
+    echo "  -f <build_file> : the name of the bundle to fetch";
+    echo "  -x <xul_dir> : staff client build directory";
+    echo "  -i <xul_build_id> : staff client build ID";
+    echo "Actions:";    
+    echo "  fetch";
+    echo "  start_perl";
+    echo "  start_c";
+    echo "  start_osrf";
+    echo "  start_all";
+    echo "  stop_perl";
+    echo "  stop_c";
+    echo "  stop_osrf";
+    echo "  stop_all";
+    echo "  restart_perl";
+    echo "  restart_c";
+    echo "  restart_osrf";
+    echo "  restart_all";
+    echo "  build";
+    echo "  build_xul";
+    echo "  detach_brick";
+    echo "  attach_brick";
+    exit 0;
 }
 
 
 # -------------------------------------------------------------------
 # Load the config opts
 # -------------------------------------------------------------------
-while getopts  "a:x:bf:hu:" flag; do
-       case $flag in   
-               "a") OPT_ACTION="$OPTARG";;
-               "x") OPT_XUL_DIR="$OPTARG";;
-               "u") OPT_FETCH_BASE_URL="$OPTARG";;
-               "f") OPT_FETCH_FILE="$OPTARG";;
-               "h"|*) usage;;
-       esac;
+while getopts  "a:x:bf:hu:c:i:" flag; do
+    case $flag in   
+        "a") OPT_ACTION="$OPTARG";;
+        "u") OPT_FETCH_BASE_URL="$OPTARG";;
+        "f") OPT_FETCH_FILE="$OPTARG";;
+        "x") OPT_XUL_BUILD_DIR="$OPTARG";;
+        "i") OPT_XUL_BUILD_ID="$OPTARG";;
+        "c") OPT_CONFIG_FILE="$OPTARG";;
+        "h"|*) usage;;
+    esac;
 done
 
-
-
+# -------------------------------------------------------------------
+# Load the config file
+# -------------------------------------------------------------------
+if [ -e "$OPT_CONFIG_FILE" ]; then
+    . $OPT_CONFIG_FILE;
+else
+    if [ -e ~/.oils_brick.cfg ]; then
+        . $DEFAULT_CONFIG; 
+    else
+        echo "Please specify a valid config file or create one at $DEFAULT_CONFIG";
+    fi;
+fi;
+
+
+# make sure an action was specified
 [ -z "$OPT_ACTION" ] && usage;
 
 
 # -------------------------------------------------------------------
-# Runs DRONE_ACT on the drones, the LOCAL_ACT on the local machine
+# Runs DRONE_ACT on the drones, then LOCAL_ACT on the local machine
 # -------------------------------------------------------------------
 function drone_first {
-       LOCAL_ACT=$1
-       DRONE_ACT=$2
-       SLEEP=$3;
-       echo -e "\ndrone_first() $LOCAL_ACT\n";
-       for(( i = $FIRST; i <= $LAST; i++ )) {
-               echo -e "\n$IP_PREFIX.$i\n"
-               ssh $OPT_SSH_BACKGROUND "$IP_PREFIX.$i" "$DRONE_ACT";
-               [ -n "$SLEEP" -a -n "$OPT_SSH_BACKGROUND" ] && sleep $SLEEP;
-       }
-       $LOCAL_ACT;
+    LOCAL_ACT=$1
+    DRONE_ACT=$2
+    echo "drone_first(): $LOCAL_ACT";
+    for drone in ${DRONES[@]:0}; do
+        echo "* $drone"
+        ssh "$drone" "$DRONE_ACT";
+    done;   
+    $LOCAL_ACT;
 }
 
 # -------------------------------------------------------------------
-# Runs LOCAL_ACT on the local machine and DRONE_ACT on the drones
+# Runs LOCAL_ACT on the local machine then DRONE_ACT on the drones
 # -------------------------------------------------------------------
 function local_first {
-       LOCAL_ACT=$1
-       DRONE_ACT=$2
-       SLEEP=$3;
-       echo -e "\nlocal_first() $LOCAL_ACT\n";
-       $LOCAL_ACT;
-       for(( i = $FIRST; i <= $LAST; i++ )) {
-               echo -e "\n$IP_PREFIX.$i\n"
-               ssh $OPT_SSH_BACKGROUND "$IP_PREFIX.$i" "$DRONE_ACT";
-               [ -n "$SLEEP" -a -n "$OPT_SSH_BACKGROUND" ] && sleep $SLEEP;
-       }
+    LOCAL_ACT=$1
+    DRONE_ACT=$2
+    echo  "local_first(): $LOCAL_ACT";
+    $LOCAL_ACT;
+    for drone in ${DRONES[@]:0}; do
+        echo "* $drone"
+        ssh "$drone" "$DRONE_ACT";
+    done;   
 }
 
 function make_xul {
-       [ -z "$OPT_XUL_DIR" ] && echo "Try again with -x to specify xul directory" && exit;
-       DIR="$XUL_BASE/$OPT_XUL_DIR";
-       echo "Building XUL and copying to $DIR";
-       cd "$SRC_DIR/Open-ILS/xul/staff_client" 
-       make clean;
-       make STAFF_CLIENT_BUILD_ID="$STAFF_CLIENT_BUILD_ID";
-       cd /$PREFIX/var/web/xul/
-       mkdir -p "$DIR";
-       cd "$DIR";
-       cp -r "$SRC_DIR/Open-ILS/xul/staff_client/build/server" "$DIR";
-       #cp /$PREFIX/var/web/xul/*.jpg "$DIR/server/";
-       #cp /$PREFIX/var/web/xul/index.html "$DIR/server/";
-       #cd /$PREFIX/var/web/xul/;
-       echo -e "\n[pwd=$PWD] Linking to new build directory: $STAFF_CLIENT_BUILD_ID -> $DIR\n";
-       rm "$STAFF_CLIENT_BUILD_ID";
-       ln -s "$OPT_XUL_DIR" "$STAFF_CLIENT_BUILD_ID";
+    DIR="$XUL_BASE/$OPT_XUL_BUILD_DIR";
+    echo "Building XUL and copying to $DIR";
+    cd "$OILS_SRC_DIR/Open-ILS/xul/staff_client" 
+    make clean;
+    make STAFF_CLIENT_BUILD_ID="$OPT_XUL_BUILD_ID";
+    cd "$XUL_BASE";
+    mkdir -p "$DIR";
+    cd "$DIR/..";
+    cp -r "$OILS_SRC_DIR/Open-ILS/xul/staff_client/build/server" "$DIR";
+    echo -e "\nLinking to new build directory: $OPT_XUL_BUILD_ID -> $DIR\n";
+    rm -f "$OPT_XUL_BUILD_ID";
+    rm -f current;
+    ln -s "$OPT_XUL_BUILD_DIR" current;
+    ln -s current "$OPT_XUL_BUILD_ID";
 }
 
 function detach_brick {
-       echo -n "Detaching brick...";
-
-       [ ! -f "$LDIRECTOR_FILE" ] && \
-               echo "ping file already moved, skipping ..." && return 0;
-
-       mv -f "$LDIRECTOR_FILE" "$LDIRECTOR_FILE.x"
-       x=10;
-       while(sleep 1); do
-               x=$(expr $x - 1);
-               echo -n " $x ";
-               [ $x == 0 ] && break;
-       done;
-       echo "";
+    echo -n "Detaching brick...";
+
+    [ ! -f "$LDIRECTOR_FILE" ] && \
+        echo "ping file already moved, skipping ..." && return 0;
+
+    mv -f "$LDIRECTOR_FILE" "$LDIRECTOR_FILE-"
+    x=10;
+    while(sleep 1); do
+        x=$(expr $x - 1);
+        echo -n " $x ";
+        [ $x == 0 ] && break;
+    done;
+    echo "";
 }
 
 function fetch_build {
 
-       [ -z "$OPT_FETCH_BASE_URL" -o -z "$OPT_FETCH_FILE" ] && \
-               echo "I need a build URL and a bundle file..." && exit;
-       
-       NEW_DIR=${OPT_FETCH_FILE:0:$(expr ${#OPT_FETCH_FILE} - 7)};
-
-       if [ ! -d "$NEW_DIR" ]; then
-       
-               echo "Fetching archive...  $OPT_FETCH_BASE_URL$OPT_FETCH_FILE";
-               wget -q "$OPT_FETCH_BASE_URL$OPT_FETCH_FILE";
-       
-               [ ! -f "$OPT_FETCH_FILE" ] && \
-                       echo "Unable to fetch $OPT_FETCH_FILE!" && exit;
-               
-               # unpack the new build
-               echo "Unpacking archive..."
-               tar -zxf $OPT_FETCH_FILE;
-               cp "ILS/install.conf" "$NEW_DIR/"
-               rm $OPT_FETCH_FILE;
-       fi;
-
-       rm ILS;
-       ln -s $NEW_DIR ILS
+    [ -z "$OPT_FETCH_BASE_URL" -o -z "$OPT_FETCH_FILE" ] && \
+        echo "I need a build URL and a bundle file..." && exit;
+    
+    NEW_DIR=${OPT_FETCH_FILE:0:$(expr ${#OPT_FETCH_FILE} - 7)};
+
+    if [ ! -d "$NEW_DIR" ]; then
+    
+        echo "Fetching archive...  $OPT_FETCH_BASE_URL$OPT_FETCH_FILE";
+        wget -q "$OPT_FETCH_BASE_URL$OPT_FETCH_FILE";
+    
+        [ ! -f "$OPT_FETCH_FILE" ] && \
+            echo "Unable to fetch $OPT_FETCH_FILE!" && exit;
+        
+        # unpack the new build
+        echo "Unpacking archive..."
+        tar -zxf $OPT_FETCH_FILE;
+        cp "current/install.conf" "$NEW_DIR/"
+        rm $OPT_FETCH_FILE;
+    fi;
+
+    rm current;
+    ln -s $NEW_DIR current;
 }
 
 case $OPT_ACTION in
 
-       "start_perl_c") local_first "$LOCAL_BASE -a start_perl && $LOCAL_BASE -a start_c" \
-               "$DRONE_BASE -a start_perl && $DRONE_BASE -a start_c" 4;;
+    "start_osrf") local_first "$LOCAL_BASE -a start_perl && $LOCAL_BASE -a start_c" \
+        "$DRONE_BASE -a start_perl && $DRONE_BASE -a start_c";;
 
-       "stop_perl_c") drone_first "$LOCAL_BASE -a stop_perl && $LOCAL_BASE -a stop_c" \
-               "$DRONE_BASE -a stop_perl && $DRONE_BASE -a stop_c" 2;;
+    "stop_osrf") drone_first "$LOCAL_BASE -a stop_perl && $LOCAL_BASE -a stop_c" \
+        "$DRONE_BASE -a stop_perl && $DRONE_BASE -a stop_c";;
 
-       "restart_perl_c") local_first "$LOCAL_BASE -a restart_perl && $LOCAL_BASE -a restart_c" \
-               "$DRONE_BASE -a restart_perl && $DRONE_BASE -a restart_c" 4;;
+    "restart_osrf") local_first "$LOCAL_BASE -a restart_perl && $LOCAL_BASE -a restart_c" \
+        "$DRONE_BASE -a restart_perl && $DRONE_BASE -a restart_c";;
 
-       "start_perl") local_first "$LOCAL_BASE -a start_perl" "$DRONE_BASE -a start_perl" 4;;
-       "stop_perl") drone_first "$LOCAL_BASE -a stop_perl" "$DRONE_BASE -a stop_perl" 2;;
-       "restart_perl") local_first "$LOCAL_BASE -a restart_perl" "$DRONE_BASE -a restart_perl" 4;;
-       "start_c") local_first "$LOCAL_BASE -a start_c" "$DRONE_BASE -a start_c" 2;;
-       "stop_c") drone_first "$LOCAL_BASE -a stop_c" "$DRONE_BASE -a stop_c" 2;;
-       "restart_c") local_first "$LOCAL_BASE -a restart_c" "$DRONE_BASE -a restart_c" 2;;
+    "start_perl") local_first "$LOCAL_BASE -a start_perl" "$DRONE_BASE -a start_perl";;
+    "stop_perl") drone_first "$LOCAL_BASE -a stop_perl" "$DRONE_BASE -a stop_perl";;
+    "restart_perl") local_first "$LOCAL_BASE -a restart_perl" "$DRONE_BASE -a restart_perl";;
+    "start_c") local_first "$LOCAL_BASE -a start_c" "$DRONE_BASE -a start_c";;
+    "stop_c") drone_first "$LOCAL_BASE -a stop_c" "$DRONE_BASE -a stop_c";;
+    "restart_c") local_first "$LOCAL_BASE -a restart_c" "$DRONE_BASE -a restart_c";;
 
-       "start_all") local_first "$LOCAL_BASE -a start_all" \
-               "$DRONE_BASE -a start_perl && $DRONE_BASE -a start_c" 4;;
+    "start_all") local_first "$LOCAL_BASE -a start_all" \
+        "$DRONE_BASE -a start_perl && $DRONE_BASE -a start_c";;
 
-       "stop_all") drone_first "$LOCAL_BASE -a stop_all" \
-               "$DRONE_BASE -a stop_perl && $DRONE_BASE -a stop_c" 2;;
+    "stop_all") drone_first "$LOCAL_BASE -a stop_all" \
+        "$DRONE_BASE -a stop_perl && $DRONE_BASE -a stop_c";;
 
-       "restart_all") $0 -a stop_all; $0 -a start_all;;
-       "build") cd ~/ILS/ && make clean default_config all;;
-       "build_xul") make_xul;;
-       "detach_brick") detach_brick;;
-       "attach_brick") mv "$LDIRECTOR_FILE.x" "$LDIRECTOR_FILE";;
-       "fetch") fetch_build;;
+    "restart_all") $0 -a stop_all; $0 -a start_all;;
+    "build") cd ~/ILS/ && make clean default_config all;;
+    "build_xul") make_xul;;
+    "detach_brick") detach_brick;;
+    "attach_brick") mv "$LDIRECTOR_FILE-" "$LDIRECTOR_FILE";;
+    "fetch") fetch_build;;
 esac;
 
 
diff --git a/Open-ILS/src/support-scripts/oils_brick.cfg.example b/Open-ILS/src/support-scripts/oils_brick.cfg.example
new file mode 100644 (file)
index 0000000..3346d1c
--- /dev/null
@@ -0,0 +1,18 @@
+# this is the lead machine
+export MASTER="10.1.0.10"
+# array of drone machines
+export DRONES=("10.1.0.11" "10.1.0.12" "10.1.0.13" "10.1.0.14")
+# if you use ldirector (or similar), this is the ping file
+export LDIRECTOR_FILE="/$PREFIX/var/web/ldirectorping.txt"
+# ILS sources directory
+export OILS_SRC_DIR=/home/opensrf/current
+# OpenSRF sources directory
+export OSRF_SRC_DIR=/home/opensrf/OpenSRF-0.9
+# install prefix
+export PREFIX=/openils
+# XUL install prefix
+export XUL_BASE="/$PREFIX/var/web/xul"
+# OpenSRF bootstrap config
+export OSRF_CONFIG="/$PREFIX/conf/opensrf_core.xml"
+# ILS PID directory
+export OSRF_PID_DIR=/var/run/evergreen