2 # -------------------------------------------------------------------
4 # XXX This probably only works on Linux for now...
6 # This script is used to manage "bricks", which are collections of
7 # servers all serving a single OpenSRF domain. There will be 1
8 # lead machine, which will typcically run this script, and 1 or more
9 # drones, which respond to this script.
11 # XXX The fetching and build commands need to be updated to work
12 # with the now-separated OpenSRF 0.9 and Evergreen 1.2
13 # -------------------------------------------------------------------
14 [ -f /etc/profile ] && . /etc/profile
15 [ -f ~/.bashrc ] && . ~/.bashrc
17 DRONE_COUNT=2; # how many drones are in this brick
18 ETH_DEV="eth0" # ethernet device
19 PREFIX="/openils" # the installed ILS files prefix
21 # this is useful if you are using ldirector. we can
22 # "detach" a brick by removing the ldirector ping file
23 LDIRECTOR_FILE="/$PREFIX/var/web/ldirectorping.txt"
26 SRC_DIR="/home/opensrf/ILS";
28 STAFF_CLIENT_BUILD_ID="sc_v100_rc2";
29 XUL_BASE="/$PREFIX/var/web/xul";
31 IP_PREFIX=$(/sbin/ifconfig | grep -A1 $ETH_DEV | grep inet | cut -d'.' -f1,2,3 | cut -d':' -f2);
32 IP=$(/sbin/ifconfig | grep -A1 $ETH_DEV | grep inet | cut -d'.' -f 4 | cut -d' ' -f1);
33 FIRST=$(expr $IP + 1);
34 LAST=$(expr $IP + $DRONE_COUNT);
37 OSRF_CONFIG="/$PREFIX/conf/opensrf_core.xml";
38 LOCAL_BASE="osrf_ctl.sh -d $OSRF_PID_DIR -c $OSRF_CONFIG";
39 DRONE_BASE=". /etc/profile && osrf_ctl.sh -d $OSRF_PID_DIR -c $OSRF_CONFIG";
42 # -------------------------------------------------------------------
43 # Make sure we're the opensrf user
44 # -------------------------------------------------------------------
45 [ $(whoami) != 'opensrf' ] && echo 'Must run as user "opensrf"' && exit;
49 echo "usage: $0 -a <action>"
50 echo " -u <base_url> : host + path URL where the download file lives";
51 echo " -f <build_file> : the name of the bundle to fetch";
52 echo " -x <xul_dir> : the destination xul directory";
65 echo " restart_perl_c";
75 # -------------------------------------------------------------------
76 # Load the config opts
77 # -------------------------------------------------------------------
78 while getopts "a:x:bf:hu:" flag; do
80 "a") OPT_ACTION="$OPTARG";;
81 "x") OPT_XUL_DIR="$OPTARG";;
82 "u") OPT_FETCH_BASE_URL="$OPTARG";;
83 "f") OPT_FETCH_FILE="$OPTARG";;
90 [ -z "$OPT_ACTION" ] && usage;
93 # -------------------------------------------------------------------
94 # Runs DRONE_ACT on the drones, the LOCAL_ACT on the local machine
95 # -------------------------------------------------------------------
96 function drone_first {
100 echo -e "\ndrone_first() $LOCAL_ACT\n";
101 for(( i = $FIRST; i <= $LAST; i++ )) {
102 echo -e "\n$IP_PREFIX.$i\n"
103 ssh $OPT_SSH_BACKGROUND "$IP_PREFIX.$i" "$DRONE_ACT";
104 [ -n "$SLEEP" -a -n "$OPT_SSH_BACKGROUND" ] && sleep $SLEEP;
109 # -------------------------------------------------------------------
110 # Runs LOCAL_ACT on the local machine and DRONE_ACT on the drones
111 # -------------------------------------------------------------------
112 function local_first {
116 echo -e "\nlocal_first() $LOCAL_ACT\n";
118 for(( i = $FIRST; i <= $LAST; i++ )) {
119 echo -e "\n$IP_PREFIX.$i\n"
120 ssh $OPT_SSH_BACKGROUND "$IP_PREFIX.$i" "$DRONE_ACT";
121 [ -n "$SLEEP" -a -n "$OPT_SSH_BACKGROUND" ] && sleep $SLEEP;
126 [ -z "$OPT_XUL_DIR" ] && echo "Try again with -x to specify xul directory" && exit;
127 DIR="$XUL_BASE/$OPT_XUL_DIR";
128 echo "Building XUL and copying to $DIR";
129 cd "$SRC_DIR/Open-ILS/xul/staff_client"
131 make STAFF_CLIENT_BUILD_ID="$STAFF_CLIENT_BUILD_ID";
132 cd /$PREFIX/var/web/xul/
135 cp -r "$SRC_DIR/Open-ILS/xul/staff_client/build/server" "$DIR";
136 #cp /$PREFIX/var/web/xul/*.jpg "$DIR/server/";
137 #cp /$PREFIX/var/web/xul/index.html "$DIR/server/";
138 #cd /$PREFIX/var/web/xul/;
139 echo -e "\n[pwd=$PWD] Linking to new build directory: $STAFF_CLIENT_BUILD_ID -> $DIR\n";
140 rm "$STAFF_CLIENT_BUILD_ID";
141 ln -s "$OPT_XUL_DIR" "$STAFF_CLIENT_BUILD_ID";
144 function detach_brick {
145 echo -n "Detaching brick...";
147 [ ! -f "$LDIRECTOR_FILE" ] && \
148 echo "ping file already moved, skipping ..." && return 0;
150 mv -f "$LDIRECTOR_FILE" "$LDIRECTOR_FILE.x"
155 [ $x == 0 ] && break;
160 function fetch_build {
162 [ -z "$OPT_FETCH_BASE_URL" -o -z "$OPT_FETCH_FILE" ] && \
163 echo "I need a build URL and a bundle file..." && exit;
165 NEW_DIR=${OPT_FETCH_FILE:0:$(expr ${#OPT_FETCH_FILE} - 7)};
167 if [ ! -d "$NEW_DIR" ]; then
169 echo "Fetching archive... $OPT_FETCH_BASE_URL$OPT_FETCH_FILE";
170 wget -q "$OPT_FETCH_BASE_URL$OPT_FETCH_FILE";
172 [ ! -f "$OPT_FETCH_FILE" ] && \
173 echo "Unable to fetch $OPT_FETCH_FILE!" && exit;
175 # unpack the new build
176 echo "Unpacking archive..."
177 tar -zxf $OPT_FETCH_FILE;
178 cp "ILS/install.conf" "$NEW_DIR/"
188 "start_perl_c") local_first "$LOCAL_BASE -a start_perl && $LOCAL_BASE -a start_c" \
189 "$DRONE_BASE -a start_perl && $DRONE_BASE -a start_c" 4;;
191 "stop_perl_c") drone_first "$LOCAL_BASE -a stop_perl && $LOCAL_BASE -a stop_c" \
192 "$DRONE_BASE -a stop_perl && $DRONE_BASE -a stop_c" 2;;
194 "restart_perl_c") local_first "$LOCAL_BASE -a restart_perl && $LOCAL_BASE -a restart_c" \
195 "$DRONE_BASE -a restart_perl && $DRONE_BASE -a restart_c" 4;;
197 "start_perl") local_first "$LOCAL_BASE -a start_perl" "$DRONE_BASE -a start_perl" 4;;
198 "stop_perl") drone_first "$LOCAL_BASE -a stop_perl" "$DRONE_BASE -a stop_perl" 2;;
199 "restart_perl") local_first "$LOCAL_BASE -a restart_perl" "$DRONE_BASE -a restart_perl" 4;;
200 "start_c") local_first "$LOCAL_BASE -a start_c" "$DRONE_BASE -a start_c" 2;;
201 "stop_c") drone_first "$LOCAL_BASE -a stop_c" "$DRONE_BASE -a stop_c" 2;;
202 "restart_c") local_first "$LOCAL_BASE -a restart_c" "$DRONE_BASE -a restart_c" 2;;
204 "start_all") local_first "$LOCAL_BASE -a start_all" \
205 "$DRONE_BASE -a start_perl && $DRONE_BASE -a start_c" 4;;
207 "stop_all") drone_first "$LOCAL_BASE -a stop_all" \
208 "$DRONE_BASE -a stop_perl && $DRONE_BASE -a stop_c" 2;;
210 "restart_all") $0 -a stop_all; $0 -a start_all;;
211 "build") cd ~/ILS/ && make clean default_config all;;
212 "build_xul") make_xul;;
213 "detach_brick") detach_brick;;
214 "attach_brick") mv "$LDIRECTOR_FILE.x" "$LDIRECTOR_FILE";;
215 "fetch") fetch_build;;