#!/bin/bash
# This file is part of Karabo.
#
# http://www.karabo.eu
#
# Copyright (C) European XFEL GmbH Schenefeld. All rights reserved.
#
# Karabo is free software: you can redistribute it and/or modify it under
# the terms of the MPL-2 Mozilla Public License.
#
# You should have received a copy of the MPL-2 Public License along with
# Karabo. If not, see <https://www.mozilla.org/en-US/MPL/2.0/>.
#
# Karabo 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.

cd $(dirname $0)
if [ -z $KARABO ]; then
    echo "\$KARABO is not defined. Make sure you have sourced the activate script for the Karabo Framework which you would like to use."
    exit 1
fi

echo "Starting broker ..."
$KARABO/extern/bin/imq start $@
sleep 1

brokerLogFile=$KARABO/var/mq/instances/imqbroker/log/log.txt
brokerConfFile=$KARABO/extern/MessageQueue/etc/mq/imqbrokerd.conf
echo "Info: "
echo "    broker log file $brokerLogFile"
tmp=$(grep 'Java Heap Size' $brokerLogFile)
tmp2=${tmp##*] }
echo "    $tmp2"
echo "    If you want to change available JVM memory size, stop the broker,"
echo "    edit broker config file:"
echo "       $brokerConfFile"
echo "    and start the broker again"
