amsfo.pl revision 0a99555401a033704f1f171baab6db11fb5528f2
# Copyright � 2006 Sun Microsystems, Inc. All rights reserved.
#
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
#
# Copyright (c) 2006 Sun Microsystems Inc. All Rights Reserved
#
# The contents of this file are subject to the terms
# of the Common Development and Distribution License
# (the License). You may not use this file except in
# compliance with the License.
#
# You can obtain a copy of the License at
# See the License for the specific language governing
# permission and limitations under the License.
#
# When distributing Covered Code, include this CDDL
# Header Notice in each file and include the License file
# at opensso/legal/CDDLv1.0.txt.
# If applicable, add the following below the CDDL Header,
# with the fields enclosed by brackets [] replaced by
# your own identifying information:
# "Portions Copyrighted [year] [name of copyright owner]"
#
# $Id: amsfo.pl,v 1.7 2009/05/07 06:58:43 kanduls Exp $
#
### To Debug this script set AMDEBUG to true ####
use Win32;
############ Initialize configuration properties############
{
print "Usage: amsfo.pl <configuration file name> start|stop";
print "\n";
print "\n";
print "Example Usage: amsfo.pl c:/sun/AccessManager/lib/amsfo.conf start";
print "\n";
exit 1;
}
my $debug = "true";
my %prop = ();
my @infile = <CONFIGFILE>;
chomp (@infile);
my $line;
my $key;
my $value;
{
if ($line !~ /^#/)
{
}
}
my $am_bin_dir = "$prop{'AM_HOME_DIR'}/bin";
my $jmq_bin_dir = "$prop{'JMQ_INSTALL_DIR'}/bin";
my $jmq_shutdown_exe = "$jmq_bin_dir/imqcmd.exe";
my $jmq_pid_file = "$prop{'LOG_DIR'}/jmq.pid";
my $am_pid_file = "$prop{'LOG_DIR'}/amdb.pid";
my $jmqExecutable = "$jmq_bin_dir/imqbrokerd.exe";
my $broker_options = "-silent";
sub get_pid {
my $pid_file = $_[0];
# Open the pid file and read the pid
print("the pid file is: $pid_file \n");
open(PID_FILE, "< $pid_file");
chomp($pid);
close(PID_FILE);
return $pid;
}
sub stop_jmq() {
if ( $debug eq "true" )
{
print("stopping JMQ Broker..", "\n");
}
if (-f $jmq_pid_file) {
print("Shutting the pid: $jmq_pid", "\n");
if ($ret ne 0) {
print("JMQ Broker is shutdown ", "\n");
unlink($jmq_pid_file);
} else {
print("Error stopping JMQ broker ", "\n");
}
#$ENV{IMQ_JAVAHOME} = $prop{'JAVA_HOME'};
#my @shutdownCmd = ("$jmq_shutdown_exe", "shutdown", "bkr", "-f", "-b", "localhost:$broker_port", "-u", "admin", "-p", "$jmq_password");
#exec(@shutdownCmd) or print STDERR "couldn't exec shutdown command: $!";
}else {
if ($debug eq "true") {
print("JMQ Broker not running", "\n");
}
exit(1);
}
}
sub start_jmq {
if ($debug eq "true")
{
print("starting JMQ Broker", "\n");
}
if ($am_sfo_restart eq "true")
{
$broker_options="$broker_options";
}
$_jmqpid="";
if (-f $jmq_pid_file)
{
}
else {
$brok_status="";
}
if ($brok_status ne "")
{
if ($debug eq "true")
{
print("JMQ Broker is already running.", "\n");
}
}
else {
if ($debug eq "true")
{
print(" $jmqExecutable -bgnd $broker_options -vmargs $broker_vm_args -name $broker_instance_name -port $broker_port -cluster $cluster_list", "\n");
}
$jmq_args = "-bgnd $broker_options -vmargs $broker_vm_args -name $broker_instance_name -port $broker_port -cluster $cluster_list";
# Open the pid file for writing
open(PID_FILE, "> $jmq_pid_file");
close(PID_FILE);
}
}
sub start_am {
if ($debug eq "true" )
{
print("starting amsessiondb client", "\n");
}
# Check if the server is already running.
$_amqpid="";
$amdb_status="";
if (-f $am_pid_file) {
}
else {
$amdb_status="";
}
if ($amdb_status ne "") {
if ($debug eq "true") {
print("AM Session DB client is already running.", "\n");
}
}
else {
if ($delete_database_dir eq "true") {
}
my $imq_jar_path="$prop{'JMQ_INSTALL_DIR'}/lib";
my $jms_jar_path="$prop{'JMQ_INSTALL_DIR'}/lib";
my $bdb_jar_path="$prop{'AM_HOME_DIR'}/../share/lib";
my $classpath="$imq_jar_path/imq.jar;$jms_jar_path/jms.jar;$prop{'AM_HOME_DIR'}/ext/je.jar;$prop{'AM_HOME_DIR'}/locale;$prop{'AM_HOME_DIR'}/lib/am_sessiondb.jar;.";
my $java_opts="";
my $amExecutable = "$java_home/bin/java.exe";
my $cmd_args = " -classpath \"$classpath\" com.sun.identity.ha.jmqdb.client.FAMHaDB -a $cluster_list -u $user_name -f $passwordfile -b $database_dir $amsessiondb_args -m $configFile";
if ($debug eq "true") {
print("$amExecutable $cmd_args\n");
}
# creates dir by creating all the non-existing parent directories first.
# Open the pid file for writing
open(pid_file, "> $am_pid_file");
close(pid_file);
}
}
sub stop_am() {
if ($debug eq "true") {
print("stopping amsessiondb client.\n");
}
if (-f $am_pid_file) {
print("Shutting the pid: $am_pid", "\n");
$? = kill(9, $am_pid);
print("amsessiondb is shutdown", "\n");
unlink($am_pid_file);
}
else {
if ($debug eq "true") {
print("amsessiondb not running", "\n");
}
}
}
############ Start of main ############
start_jmq();
## Wait for 5 sec for the broker to start ##
sleep(10);
}
start_am();
sleep(10);
stop_am();
## Wait untill the AMDB shuts down properly ##
sleep(10);
stop_jmq();
}
start_jmq();
sleep(10);
stop_jmq();
sleep(10);
start_am();
sleep(10);
stop_am();
sleep(10);
}else {
print "Usage: amsfo.pl <configuration file name> start|stop|start-jmq|stop-jmq|start-amsdb|stop-amsdb";
print "\n";
print "\n";
print "Example Usage: amsfo.pl c:/sun/AccessManager/lib/amsfo.conf start";
print "\n";
exit 1;
}