#!/bin/bash -p

# $Id: runagent.bash,v 1.3 2007/07/22 21:19:06 blaine Exp $

# JMX Accelerated Howto and its sample code are copyrighted with the
# BSD license available in the Howto document.
# Copyright (c) 2004-2007, Axis Data Management Corp

# This is a UNIX script for starting up a secured RMI Jmx ConnectorServer.

# Update the SECURITY SETTINGS and CLASSPATH.
# The CLASSPATH must include the jars that you want to manage.
# Generally, the manager/client doesn't need access to the .class files,
# but my Jmx*Adaptor classes do, since I want to display bean details which
# are only possible to display if intimate details of the class definition
# are known.
# Invoke like "nohup ./run.bash"

export SECURITY_SETTINGS=
#SECURITY_SETTINGS='-Djava.security.manager -Djava.security.policy==secure.policy'
#SECURITY_SETTINGS="$SECURITY_SETTINGS -Djava.security.debug=access.failure"

[ -e rmiregistry.pid ] && kill -INT $(<rmiregistry.pid) 2>&-
[ -e connsvr.pid ] && kill -INT $(<connsvr.pid) 2>&-
rm -f rmiregistry.pid connsvr.pid
sleep 1

export CLASSPATH=.:tst.jar:offlimits:admcjmx-adaptors.jar

bash -c 'echo $$ > rmiregistry.pid; exec rmiregistry 2003'&
bash -c 'echo $$ > connsvr.pid;
java $SECURITY_SETTINGS ConnectorServerAgent service:jmx:rmi:///jndi/rmi://localhost:2003/jmxdemo'> stdout.txt 2> stderr.txt &

echo -en 'Please stand by for 5 seconds to verify that server started ok...  '
sleep 5
kill -0 $(<connsvr.pid) || {
    echo '
Failed to start server.
See the files "stdout.txt" and "stderr.txt" for program output.' 1>&2
    exit 1
}

echo 'Looks OK!
???
???
???
???
