#!/bin/sh

###############################################################################
#
#   Copyright (c) 2006 Zenoss, Inc. all rights reserved.
#
#   This library is free software; you can redistribute it and/or
#   modify it under the terms of the GNU General Public
#   License as published by the Free Software Foundation; either
#   version 2.1 of the License.
#
###############################################################################

#
# This script runs weekly and is reponsible for packing the Zeo
# database.  As objects are deleted their space is never reclaimed
# from the Zeo database until it is packed.  This script executes the
# Zenoss command to pack the database.
#

# location of the shell script that initializes the zenoss environment
ZENOSS_ENV=~zenoss/.bashrc

# print the error message passed and exit with a return code of 1 (error)
fail() {
    echo $*
    exit 1
}


#
# main script starts here
#

# set up the environment
test -f ${ZENOSS_ENV} || fail "Source environment not found"
. ${ZENOSS_ENV}

PORT=`grep address ${ZENHOME}/etc/zeo.conf | head -n 1 | awk '{ print $2 }'`
if [ -z "$ZOPEHOME" ] ; then
   ZOPEHOME="$ZENHOME"
fi
$ZOPEHOME/bin/zeopack.py -p ${PORT}
