2 # ---------------------------------------------------------------
3 # Copyright (C) 2007-2008 Georgia Public Library Service
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 # ---------------------------------------------------------------
16 # -------------------------------------------------------------------
17 # This script is used to manage "bricks", which are collections of
18 # servers all serving a single OpenSRF domain. There will be 1
19 # master machine, which will typcically run this script, and 1 or more
20 # drones, which respond to this script.
21 # -------------------------------------------------------------------
23 # TODO finish the download and build functionality
26 [ -f /etc/profile ] && . /etc/profile
27 [ -f ~/.bashrc ] && . ~/.bashrc
29 DEFAULT_CONFIG=~/.oils_brick.cfg
32 # -------------------------------------------------------------------
33 # Make sure we're the opensrf user
34 # -------------------------------------------------------------------
35 [ $(whoami) != 'opensrf' ] && echo 'Must run as user "opensrf"' && exit;
40 echo "usage: $0 -a <action>"
41 echo " -u <base_url> : host + path URL where the download file lives";
42 echo " -f <build_file> : the name of the bundle to fetch";
43 echo " -x <xul_dir> : staff client build directory";
44 echo " -i <xul_build_id> : staff client build ID";
67 # -------------------------------------------------------------------
68 # Load the config opts
69 # -------------------------------------------------------------------
70 while getopts "a:x:bf:hu:c:i:" flag; do
72 "a") OPT_ACTION="$OPTARG";;
73 "u") OPT_FETCH_BASE_URL="$OPTARG";;
74 "f") OPT_FETCH_FILE="$OPTARG";;
75 "x") OPT_XUL_BUILD_DIR="$OPTARG";;
76 "i") OPT_XUL_BUILD_ID="$OPTARG";;
77 "c") OPT_CONFIG_FILE="$OPTARG";;
82 # -------------------------------------------------------------------
83 # Load the config file
84 # -------------------------------------------------------------------
85 if [ -e "$OPT_CONFIG_FILE" ]; then
88 if [ -e ~/.oils_brick.cfg ]; then
91 echo "Please specify a valid config file or create one at $DEFAULT_CONFIG";
96 # make sure an action was specified
97 [ -z "$OPT_ACTION" ] && usage;
99 LOCAL_BASE="osrf_ctl.sh -d $OSRF_PID_DIR -c $OSRF_CONFIG";
100 DRONE_BASE=". /etc/profile && osrf_ctl.sh -d $OSRF_PID_DIR -c $OSRF_CONFIG";
102 # -------------------------------------------------------------------
103 # Runs DRONE_ACT on the drones, then LOCAL_ACT on the local machine
104 # -------------------------------------------------------------------
105 function drone_first {
108 echo "drone_first(): $LOCAL_ACT";
109 for drone in ${DRONES[@]:0}; do
111 ssh "$drone" "$DRONE_ACT";
116 # -------------------------------------------------------------------
117 # Runs LOCAL_ACT on the local machine then DRONE_ACT on the drones
118 # -------------------------------------------------------------------
119 function local_first {
122 echo "local_first(): $LOCAL_ACT";
124 for drone in ${DRONES[@]:0}; do
126 ssh "$drone" "$DRONE_ACT";
131 DIR="$XUL_BASE/$OPT_XUL_BUILD_DIR";
132 echo "Building XUL and copying to $DIR";
133 cd "$OILS_SRC_DIR/Open-ILS/xul/staff_client"
135 make STAFF_CLIENT_BUILD_ID="$OPT_XUL_BUILD_ID";
139 cp -r "$OILS_SRC_DIR/Open-ILS/xul/staff_client/build/server" "$DIR";
140 echo -e "\nLinking to new build directory: $OPT_XUL_BUILD_ID -> $DIR\n";
141 rm -f "$OPT_XUL_BUILD_ID";
143 ln -s "$OPT_XUL_BUILD_DIR" current;
144 ln -s current "$OPT_XUL_BUILD_ID";
147 function detach_brick {
148 echo -n "Detaching brick...";
150 [ ! -f "$LDIRECTOR_FILE" ] && \
151 echo "ping file already moved, skipping ..." && return 0;
153 mv -f "$LDIRECTOR_FILE" "$LDIRECTOR_FILE-"
158 [ $x == 0 ] && break;
163 function fetch_build {
165 [ -z "$OPT_FETCH_BASE_URL" -o -z "$OPT_FETCH_FILE" ] && \
166 echo "I need a build URL and a bundle file..." && exit;
168 NEW_DIR=${OPT_FETCH_FILE:0:$(expr ${#OPT_FETCH_FILE} - 7)};
170 if [ ! -d "$NEW_DIR" ]; then
172 echo "Fetching archive... $OPT_FETCH_BASE_URL$OPT_FETCH_FILE";
173 wget -q "$OPT_FETCH_BASE_URL$OPT_FETCH_FILE";
175 [ ! -f "$OPT_FETCH_FILE" ] && \
176 echo "Unable to fetch $OPT_FETCH_FILE!" && exit;
178 # unpack the new build
179 echo "Unpacking archive..."
180 tar -zxf $OPT_FETCH_FILE;
181 cp "current/install.conf" "$NEW_DIR/"
186 ln -s $NEW_DIR current;
191 "start_osrf") local_first "$LOCAL_BASE -a start_perl && $LOCAL_BASE -a start_c" \
192 "$DRONE_BASE -a start_perl && $DRONE_BASE -a start_c";;
194 "stop_osrf") drone_first "$LOCAL_BASE -a stop_perl && $LOCAL_BASE -a stop_c" \
195 "$DRONE_BASE -a stop_perl && $DRONE_BASE -a stop_c";;
197 "restart_osrf") local_first "$LOCAL_BASE -a restart_perl && $LOCAL_BASE -a restart_c" \
198 "$DRONE_BASE -a restart_perl && $DRONE_BASE -a restart_c";;
200 "start_perl") local_first "$LOCAL_BASE -a start_perl" "$DRONE_BASE -a start_perl";;
201 "stop_perl") drone_first "$LOCAL_BASE -a stop_perl" "$DRONE_BASE -a stop_perl";;
202 "restart_perl") local_first "$LOCAL_BASE -a restart_perl" "$DRONE_BASE -a restart_perl";;
203 "start_c") local_first "$LOCAL_BASE -a start_c" "$DRONE_BASE -a start_c";;
204 "stop_c") drone_first "$LOCAL_BASE -a stop_c" "$DRONE_BASE -a stop_c";;
205 "restart_c") local_first "$LOCAL_BASE -a restart_c" "$DRONE_BASE -a restart_c";;
207 "start_all") local_first "$LOCAL_BASE -a start_all" \
208 "$DRONE_BASE -a start_perl && $DRONE_BASE -a start_c";;
210 "stop_all") drone_first "$LOCAL_BASE -a stop_all" \
211 "$DRONE_BASE -a stop_perl && $DRONE_BASE -a stop_c";;
213 "restart_all") $0 -a stop_all; $0 -a start_all;;
214 "build") cd ~/ILS/ && make clean default_config all;;
215 "build_xul") make_xul;;
216 "detach_brick") detach_brick;;
217 "attach_brick") mv "$LDIRECTOR_FILE-" "$LDIRECTOR_FILE";;
218 "fetch") fetch_build;;