#!/usr/bin/env bash
#
# Copyright (C) 2003 VA Linux Systems Japan, K.K.
#
# LICENSE NOTICE
#
#  This program 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 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#

# $Id: ultrapossum-test,v 1.5 2004/10/12 06:52:07 taru Exp $

: <<-POD

=head1 NAME

ultrapossum-test - Testing Framework of UltraPossum Installation Status

=head1 SYNOPSIS

B<ultrapossum-test> [<test scripts>...]

=head1 DESCRIPTION

B<ultrapossum-test> provides the testing framework of UltraPossum
installation. It is mainly used for system administrators to check
whether its installation is completed.

=head1 AUTHOR

Masato Taruishi <taru@valinux.co.jp>

=cut

POD

set -e

eval `ultrapossum-config init`
trap "eval `ultrapossum-config term`" 0

if test "x$HOST" != "x$MASTER"; then
  echo "Must be run on master: $MASTER" 1>&2
  exit 1
fi

if test "x$ULTRAPOSSUM_MODULE_SERVER" != "xinstalled"; then
  echo "UltraPossum Server not installed" 1>&2
  exit 1
fi

ERRORFILE=$LOGDIR/ultrapossum-test-error

install -d  $LOGDIR
if test -x "/usr/bin/savelog"; then
  if test -f $ERRORFILE; then
    savelog $ERRORFILE > /dev/null 2> /dev/null
  fi
  cp /dev/null $ERRORFILE
fi

if test "x`$MODULEDIR/server/startup master_status`" = "xstopped"; then
  if test -x "/etc/init.d/ultrapossum-server"; then
    /etc/init.d/ultrapossum-server restart
  else
    echo -n "Restarting UltraPossum server... "
    $MODULEDIR/server/startup stop || true
    $MODULEDIR/server/startup start
    echo "done"
  fi
fi
$MODULEDIR/test/runtest "$@" 2>> $ERRORFILE

