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";
45 echo " -s <service_name> : apply action only to specified service";
62 # -------------------------------------------------------------------
63 # Load the config opts
64 # -------------------------------------------------------------------
65 while getopts "a:x:bf:hu:c:i:s:l" flag; do
67 "a") OPT_ACTION="$OPTARG";;
68 "u") OPT_FETCH_BASE_URL="$OPTARG";;
69 "f") OPT_FETCH_FILE="$OPTARG";;
70 "x") OPT_XUL_BUILD_DIR="$OPTARG";;
71 "i") OPT_XUL_BUILD_ID="$OPTARG";;
72 "c") OPT_CONFIG_FILE="$OPTARG";;
73 "l") OPT_LOCALHOST="-l";;
74 "s") OPT_SERVICE="$OPTARG";;
79 # -------------------------------------------------------------------
80 # Load the config file
81 # -------------------------------------------------------------------
82 if [ -e "$OPT_CONFIG_FILE" ]; then
85 if [ -e ~/.oils_brick.cfg ]; then
88 echo "Please specify a valid config file or create one at $DEFAULT_CONFIG";
92 [ -n "$OPT_LOCALHOST" ] && SERVICE_LOCALHOST_FLAG="--localhost";
94 # make sure an action was specified
95 [ -z "$OPT_ACTION" ] && usage;
97 LOCAL_BASE="osrf_control $OPT_LOCALHOST --pid-dir $OSRF_PID_DIR --config $OSRF_CONFIG";
98 DRONE_BASE=". /etc/profile && osrf_control --pid-dir $OSRF_PID_DIR --config $OSRF_CONFIG";
99 SERVICE_CONTROLLER="osrf_control $SERVICE_LOCALHOST_FLAG --config $OSRF_CONFIG --pid-dir $OSRF_PID_DIR --service $OPT_SERVICE";
101 # -------------------------------------------------------------------
102 # Runs DRONE_ACT on the drones, then LOCAL_ACT on the local machine
103 # -------------------------------------------------------------------
104 function drone_first {
107 echo "drone_first(): $LOCAL_ACT";
108 for drone in ${DRONES[@]:0}; do
110 ssh "$drone" "$DRONE_ACT";
115 # -------------------------------------------------------------------
116 # Runs LOCAL_ACT on the local machine then DRONE_ACT on the drones
117 # -------------------------------------------------------------------
118 function local_first {
121 echo "local_first(): $LOCAL_ACT";
123 for drone in ${DRONES[@]:0}; do
125 ssh "$drone" "$DRONE_ACT";
130 DIR="$XUL_BASE/$OPT_XUL_BUILD_DIR";
131 echo "Building XUL and copying to $DIR";
132 cd "$OILS_SRC_DIR/Open-ILS/xul/staff_client"
134 make STAFF_CLIENT_BUILD_ID="$OPT_XUL_BUILD_ID";
138 cp -r "$OILS_SRC_DIR/Open-ILS/xul/staff_client/build/server" "$DIR";
139 echo -e "\nLinking to new build directory: $OPT_XUL_BUILD_ID -> $DIR\n";
140 rm -f "$OPT_XUL_BUILD_ID";
142 ln -s "$OPT_XUL_BUILD_DIR" current;
143 ln -s current "$OPT_XUL_BUILD_ID";
146 function detach_brick {
147 echo -n "Detaching brick...";
149 [ ! -f "$LDIRECTOR_FILE" ] && \
150 echo "ping file already moved, skipping ..." && return 0;
152 mv -f "$LDIRECTOR_FILE" "$LDIRECTOR_FILE-"
157 [ $x == 0 ] && break;
162 function fetch_build {
164 [ -z "$OPT_FETCH_BASE_URL" -o -z "$OPT_FETCH_FILE" ] && \
165 echo "I need a build URL and a bundle file..." && exit;
167 NEW_DIR=${OPT_FETCH_FILE:0:$(expr ${#OPT_FETCH_FILE} - 7)};
169 if [ ! -d "$NEW_DIR" ]; then
171 echo "Fetching archive... $OPT_FETCH_BASE_URL$OPT_FETCH_FILE";
172 wget -q "$OPT_FETCH_BASE_URL$OPT_FETCH_FILE";
174 [ ! -f "$OPT_FETCH_FILE" ] && \
175 echo "Unable to fetch $OPT_FETCH_FILE!" && exit;
177 # unpack the new build
178 echo "Unpacking archive..."
179 tar -zxf $OPT_FETCH_FILE;
180 cp "current/install.conf" "$NEW_DIR/"
185 ln -s $NEW_DIR current;
188 # This is a per-service action. Currently only support in Perl (and Python).
189 # When other active languages are added, this script will need a language param
190 # to determine which controller script to call.
191 if [ -n "$OPT_SERVICE" ]; then
193 "start_osrf") local_first "$SERVICE_CONTROLLER --start" \
194 "$SERVICE_CONTROLLER --start";;
195 "stop_osrf") local_first "$SERVICE_CONTROLLER --stop" \
196 "$SERVICE_CONTROLLER --stop";;
197 "restart_osrf") local_first "$SERVICE_CONTROLLER --restart" \
198 "$SERVICE_CONTROLLER --restart";;
199 *) echo "Can only do start_osrf, stop_osrf, or restart_osrf for an individual service";;
206 "start_osrf") local_first "$LOCAL_BASE --start-services" \
207 "$DRONE_BASE --start-services";;
209 "stop_osrf") drone_first "$LOCAL_BASE --stop-services" \
210 "$DRONE_BASE --stop-services";;
212 "restart_osrf") local_first "$LOCAL_BASE --restart-services" \
213 "$DRONE_BASE --restart-services";;
215 "start_all") local_first "$LOCAL_BASE --start-all" \
216 "$DRONE_BASE --start-services";;
218 "stop_all") drone_first "$LOCAL_BASE --stop-all" \
219 "$DRONE_BASE --stop-services";;
221 "restart_all") $0 $OPT_LOCALHOST -a stop_all; $0 $OPT_LOCALHOST -a start_all;;
222 "build") cd ~/ILS/ && make clean default_config all;;
223 "build_xul") make_xul;;
224 "detach_brick") detach_brick;;
225 "attach_brick") mv "$LDIRECTOR_FILE-" "$LDIRECTOR_FILE";;
226 "fetch") fetch_build;;