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:s:l" 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";;
78 "l") OPT_LOCALHOST="-l";;
79 "s") OPT_SERVICE="$OPTARG";;
84 # -------------------------------------------------------------------
85 # Load the config file
86 # -------------------------------------------------------------------
87 if [ -e "$OPT_CONFIG_FILE" ]; then
90 if [ -e ~/.oils_brick.cfg ]; then
93 echo "Please specify a valid config file or create one at $DEFAULT_CONFIG";
97 [ -n "$OPT_LOCALHOST" ] && PERL_LOCALHOST_FLAG="--localhost";
99 # make sure an action was specified
100 [ -z "$OPT_ACTION" ] && usage;
102 LOCAL_BASE="osrf_ctl.sh $OPT_LOCALHOST -d $OSRF_PID_DIR -c $OSRF_CONFIG";
103 DRONE_BASE=". /etc/profile && osrf_ctl.sh -d $OSRF_PID_DIR -c $OSRF_CONFIG";
104 PERL_CONTROLLER="opensrf-perl.pl --verbose $PERL_LOCALHOST_FLAG --config $OSRF_CONFIG --pid-dir $OSRF_PID_DIR --action $OPT_ACTION --service $OPT_SERVICE";
106 # -------------------------------------------------------------------
107 # Runs DRONE_ACT on the drones, then LOCAL_ACT on the local machine
108 # -------------------------------------------------------------------
109 function drone_first {
112 echo "drone_first(): $LOCAL_ACT";
113 for drone in ${DRONES[@]:0}; do
115 ssh "$drone" "$DRONE_ACT";
120 # -------------------------------------------------------------------
121 # Runs LOCAL_ACT on the local machine then DRONE_ACT on the drones
122 # -------------------------------------------------------------------
123 function local_first {
126 echo "local_first(): $LOCAL_ACT";
128 for drone in ${DRONES[@]:0}; do
130 ssh "$drone" "$DRONE_ACT";
135 DIR="$XUL_BASE/$OPT_XUL_BUILD_DIR";
136 echo "Building XUL and copying to $DIR";
137 cd "$OILS_SRC_DIR/Open-ILS/xul/staff_client"
139 make STAFF_CLIENT_BUILD_ID="$OPT_XUL_BUILD_ID";
143 cp -r "$OILS_SRC_DIR/Open-ILS/xul/staff_client/build/server" "$DIR";
144 echo -e "\nLinking to new build directory: $OPT_XUL_BUILD_ID -> $DIR\n";
145 rm -f "$OPT_XUL_BUILD_ID";
147 ln -s "$OPT_XUL_BUILD_DIR" current;
148 ln -s current "$OPT_XUL_BUILD_ID";
151 function detach_brick {
152 echo -n "Detaching brick...";
154 [ ! -f "$LDIRECTOR_FILE" ] && \
155 echo "ping file already moved, skipping ..." && return 0;
157 mv -f "$LDIRECTOR_FILE" "$LDIRECTOR_FILE-"
162 [ $x == 0 ] && break;
167 function fetch_build {
169 [ -z "$OPT_FETCH_BASE_URL" -o -z "$OPT_FETCH_FILE" ] && \
170 echo "I need a build URL and a bundle file..." && exit;
172 NEW_DIR=${OPT_FETCH_FILE:0:$(expr ${#OPT_FETCH_FILE} - 7)};
174 if [ ! -d "$NEW_DIR" ]; then
176 echo "Fetching archive... $OPT_FETCH_BASE_URL$OPT_FETCH_FILE";
177 wget -q "$OPT_FETCH_BASE_URL$OPT_FETCH_FILE";
179 [ ! -f "$OPT_FETCH_FILE" ] && \
180 echo "Unable to fetch $OPT_FETCH_FILE!" && exit;
182 # unpack the new build
183 echo "Unpacking archive..."
184 tar -zxf $OPT_FETCH_FILE;
185 cp "current/install.conf" "$NEW_DIR/"
190 ln -s $NEW_DIR current;
193 # This is a per-service action. Currently only support in Perl (and Python).
194 # When other active languages are added, this script will need a language param
195 # to determine which controller script to call.
196 if [ -n "$OPT_SERVICE" ]; then
197 local_first "$PERL_CONTROLLER" "$PERL_CONTROLLER";
203 "start_osrf") local_first "$LOCAL_BASE -a start_perl && $LOCAL_BASE -a start_c" \
204 "$DRONE_BASE -a start_perl && $DRONE_BASE -a start_c";;
206 "stop_osrf") drone_first "$LOCAL_BASE -a stop_perl && $LOCAL_BASE -a stop_c" \
207 "$DRONE_BASE -a stop_perl && $DRONE_BASE -a stop_c";;
209 "restart_osrf") local_first "$LOCAL_BASE -a restart_perl && $LOCAL_BASE -a restart_c" \
210 "$DRONE_BASE -a restart_perl && $DRONE_BASE -a restart_c";;
212 "start_perl") local_first "$LOCAL_BASE -a start_perl" "$DRONE_BASE -a start_perl";;
213 "stop_perl") drone_first "$LOCAL_BASE -a stop_perl" "$DRONE_BASE -a stop_perl";;
214 "restart_perl") local_first "$LOCAL_BASE -a restart_perl" "$DRONE_BASE -a restart_perl";;
215 "start_c") local_first "$LOCAL_BASE -a start_c" "$DRONE_BASE -a start_c";;
216 "stop_c") drone_first "$LOCAL_BASE -a stop_c" "$DRONE_BASE -a stop_c";;
217 "restart_c") local_first "$LOCAL_BASE -a restart_c" "$DRONE_BASE -a restart_c";;
219 "start_all") local_first "$LOCAL_BASE -a start_all" \
220 "$DRONE_BASE -a start_perl && $DRONE_BASE -a start_c";;
222 "stop_all") drone_first "$LOCAL_BASE -a stop_all" \
223 "$DRONE_BASE -a stop_perl && $DRONE_BASE -a stop_c";;
225 "restart_all") $0 $OPT_LOCALHOST -a stop_all; $0 $OPT_LOCALHOST -a start_all;;
226 "build") cd ~/ILS/ && make clean default_config all;;
227 "build_xul") make_xul;;
228 "detach_brick") detach_brick;;
229 "attach_brick") mv "$LDIRECTOR_FILE-" "$LDIRECTOR_FILE";;
230 "fetch") fetch_build;;