aboutsummaryrefslogtreecommitdiffstats
path: root/script
diff options
context:
space:
mode:
authorSeb Bacon <seb.bacon@gmail.com>2011-08-11 17:51:04 +0100
committerSeb Bacon <seb.bacon@gmail.com>2011-08-12 16:11:19 +0100
commit9bd22ea1b3ad1b94328d3d32b6a8cfb9d6ee7a09 (patch)
tree865c9fd6840e9b7536e463bad90df8d6c8cf2d77 /script
parent766df1c7de8f820bd6e451526787632a136bc635 (diff)
Improve db compact script: handle spaces in filenames nicely, output errors to STDERR, and don't do anything if there's a half-finished attempt still lying around.
Diffstat (limited to 'script')
-rwxr-xr-xscript/compact-xapian-database29
1 files changed, 19 insertions, 10 deletions
diff --git a/script/compact-xapian-database b/script/compact-xapian-database
index 5c12b5dae..f1a6058b0 100755
--- a/script/compact-xapian-database
+++ b/script/compact-xapian-database
@@ -1,16 +1,25 @@
#!/bin/bash
-RAILS_ENV=$1
+export RAILS_ENV=$1
set -e
+
if [ -x /usr/bin/xapian-compact ]; then
- XAPIAN_DB_DIR="$( cd "$( dirname "$0" )" && pwd )/../vendor/plugins/acts_as_xapian/xapiandbs"
- OWNER=`stat -c %U $XAPIAN_DB_DIR/$RAILS_ENV`
- su -c "xapian-compact $XAPIAN_DB_DIR/$RAILS_ENV $XAPIAN_DB_DIR/$RAILS_ENV.new" $OWNER
- mv $XAPIAN_DB_DIR/$RAILS_ENV $XAPIAN_DB_DIR/$RAILS_ENV.tmp
- mv $XAPIAN_DB_DIR/$RAILS_ENV.new $XAPIAN_DB_DIR/$RAILS_ENV
- rm -rf $XAPIAN_DB_DIR/$RAILS_ENV.tmp
- /etc/init.d/apache2 restart
+ XAPIAN_DB_DIR=$( cd "$( dirname "$0" )" && pwd )/../vendor/plugins/acts_as_xapian/xapiandbs
+ if [ -e "$XAPIAN_DB_DIR/$RAILS_ENV.new" ]; then
+ echo >&2 "Didn't compact Xapian database because there was an existing database at $XAPIAN_DB_DIR/$RAILS_ENV.new"
+ exit 1
+ else
+ OWNER=$(stat -c %U "$XAPIAN_DB_DIR/$RAILS_ENV")
+ export XAPIAN_DB_DIR RAILS_ENV
+ su "$OWNER" <<SU
+ xapian-compact "\$XAPIAN_DB_DIR/\$RAILS_ENV" "\$XAPIAN_DB_DIR/\$RAILS_ENV.new"
+SU
+ mv "$XAPIAN_DB_DIR/$RAILS_ENV" "$XAPIAN_DB_DIR/$RAILS_ENV.tmp"
+ mv "$XAPIAN_DB_DIR/$RAILS_ENV.new" "$XAPIAN_DB_DIR/$RAILS_ENV"
+ rm -rf "$XAPIAN_DB_DIR/$RAILS_ENV.tmp"
+ /etc/init.d/apache2 restart
+ fi
else
- echo "Could not find xapian-compact script; have you installed xapian-tools?"
+ echo >&2 "Could not find xapian-compact script; have you installed xapian-tools?"
exit 1
-fi \ No newline at end of file
+fi