adding utility to quickly switch reporter configs
authorChris Sharp <csharp@georgialibraries.org>
Wed, 6 Mar 2013 15:56:39 +0000 (10:56 -0500)
committerChris Sharp <csharp@georgialibraries.org>
Wed, 6 Mar 2013 15:56:39 +0000 (10:56 -0500)
switcheroo.sh [new file with mode: 0755]

diff --git a/switcheroo.sh b/switcheroo.sh
new file mode 100755 (executable)
index 0000000..616f100
--- /dev/null
@@ -0,0 +1,96 @@
+#!/bin/bash
+
+# (c) Copyright 2013 Georgia Public Library Service
+# Chris Sharp <csharp@georgialibraries.org
+#
+# A utility to ease database server administration by reconfiguring
+# which database is used for reports queries.  It assumes that you're
+# running pgpool to balance the load between two servers named db02 and
+# db03, and that you have created the alternate config files inside your
+# OpenSRF configuration directory.
+#
+
+WORKING_DIR="$PWD"
+CONF_DIR="/openils/conf"
+RUNNING_CONFIG="$CONF_DIR/opensrf.xml"
+PGPOOL_CONFIG="$CONF_DIR/opensrf.xml.pgpool"
+DB02_CONFIG="$CONF_DIR/opensrf.xml.db02"
+DB03_CONFIG="$CONF_DIR/opensrf.xml.db03"
+STATE_FILE="$WORKING_DIR/current"
+OPENSRF_RESTART="/etc/init.d/opensrf restart"
+REPORTER_LOCK="/tmp/reporter-LOCK"
+REPORTS_CMD="/openils/bin/clark-kent.pl"
+
+GetState () {
+if [ -e $STATE_FILE ]; then
+       STATE=$(cat $STATE_FILE)
+       echo "The reporter is currently using $STATE configuration."
+else
+       echo "The state file at $STATE_FILE does not exist, skipping..."
+fi
+}
+
+CheckReporter () {
+if [ -e $REPORTER_LOCK ]; then
+       echo "Reporter lock file is in place, which may mean the reporter is running."
+       echo "Please stop the reporter process and ensure no reports are running before"
+       echo "running this script again."
+       exit;
+fi
+}
+
+StartReporter () {
+echo "Attempting to start the reporting process..."
+su - opensrf -c /bin/bash -c "$REPORTS_CMD -d -c $REPORTS_COUNT"
+if [ "$(pidof 'Clark Kent, waiting for trouble')" ]; then
+       echo "Reporting process started successfully."
+else
+       echo "Looks like something went wrong.  Please start the reporter process manually."
+       exit;
+fi
+}
+
+
+CheckReporter
+echo "This utility changes which database servers are used to run reports queries."
+echo
+GetState
+echo
+echo "Configuration Options:"
+echo
+echo -e "\t1) PgPool Configuration (load is balanced between db02 and db03)"
+echo -e "\t2) db02 only"
+echo -e "\t3) db03 only"
+echo
+read -p "Please select the desired configuration: " CHOICE
+
+if [ $CHOICE = "1" ]; then
+       echo "Selecting PgPool configuration..."
+       cp -v $PGPOOL_CONFIG $RUNNING_CONFIG
+       REPORTS_COUNT="12"
+       echo "Restarting services to activate new configuration..."
+       $OPENSRF_RESTART
+       StartReporter
+       echo "pgpool" > $STATE_FILE
+elif [ $CHOICE = "2" ]; then
+       echo "Selecting db02 configuration..."
+        cp -v $DB02_CONFIG $RUNNING_CONFIG
+        REPORTS_COUNT="8"
+        echo "Restarting services to activate new configuration..."
+        $OPENSRF_RESTART
+        StartReporter
+       echo "db02" > $STATE_FILE
+elif [ $CHOICE = "3" ]; then
+               echo "Selecting db03 configuration..."
+        cp -v $DB03_CONFIG $RUNNING_CONFIG
+        REPORTS_COUNT="12"
+        echo "Restarting services to activate new configuration..."
+        $OPENSRF_RESTART
+        StartReporter
+       echo "db03" > $STATE_FILE
+else
+       echo "Invalid response. Aborting."
+       exit;
+fi 
+       
+