#!/usr/local/bin/perl
# /public/scripts/ConfSetupGlb.pl
# A script that installs the relevant configuration files on a globecom server.
#
# The destination server type is required as an argument. The type may be:
# GNS or MSF
# A third option is DEMO, which is a GNS + WebServer
#
use Socket; ## Needed by gethostbyname
if ($#ARGV < 0) {
print "Usage: ConfSetupGlb.sh Type\n";
print " where Type is the server type one of:\n";
print " FES - Globecom Front End Server\n";
print " LCM - Life Cycle Manager Server\n";
exit;
}
# Get this machine's system-name, host-name and domain-name
$Sysname = `uname`;
chop($Sysname);
$Hostname = `hostname`;
chop($Hostname);
if ($Hostname =~ /([^\.]+)\.\S+/) { # extract first part if defined with a domain name
$Hostname = $1;
}
######################### Change at the farm ####################
$Domainname = `domainname`;
chop($Domainname);
$Domainname = $Domainname.'.net';
$WLS_ClusterName = "gccluster";
######################### Change at the farm ####################
# A directory that holds a pool of adjusted config files
print "Please type version name (Example: prd_2.0.1) ?\n";
$answer = <STDIN>;
chop ($answer);
$CnfName = $answer;
$ConfPool = "/public/$CnfName/ins/conf"; # A directory that holds a pool of adjusted config files
# Open a current configuration file where all the settings are collected
$currfile = "$ConfPool/CurrentConfig-$ARGV[0]-$Hostname";
$stat = system("touch $currfile");
$stat = system("chmod 777 $currfile");
open(CURR, ">$currfile") || die "Cannot open $currfile: $!";
# Call the appropriate configurator
$ServerType = $ARGV[0];
if ($ARGV[0] eq "FES") { &config_serv(); } # Configure a FES node
elsif ($ARGV[0] eq "LCM") { &config_serv(); } # Configure LCM Server
else {
# Illegal argument
print "Illegal argument $ARGV[0]\n\n";
print "Usage: ConfSetupGlb.sh Type\n";
print " where Type is the server's type one of:\n";
print " FES - Globecom Front End Server\n";
print " LCM - Life Cycle Manager Server\n";
exit;
}
close(CURR);
print "\n ----- End of $ARGV[0] configuration ----\n";
## A subroutine to configure a Globecom Server ***************************
sub config_serv {
$ConfTmp = '/tmp/gc-conf'; # A temporary directory to prepare the correct config files in
# Create a temporary directory to collected config files to
$sataus = system("rm -rf $ConfTmp");
$status = system("mkdir $ConfTmp");
$status = system("cp $ConfPool/GLB/* $ConfTmp");
# Collect general information
print "\nPlease type the Sdu Server's host FULL name\n";
&GetHostname ();
$SduName = $host;
print "\nPlease type the LCM Server's host FULL name\n";
&GetHostname ();
$LcmName = $host;
if ($ServerType eq "FES") {
print "\nPlease type the FES WEB access name\n";
&GetHostname ();
$FesWebName = $host;
print "\nPlease type the Convertor mode (epop or ncr or internet) \n";
$answer = <STDIN>;
chop ($answer);
if ($answer eq "epop") { # epop mode
$ConvMode = $answer;
}
elsif ($answer eq "ncr") { # ncr mode
$ConvMode = $answer;
}
elsif ($answer eq "internet") { # internet mode
$ConvMode = $answer;
}
else {#
# Illegal mode
print "Illegal mode \n\n";
exit;
}
}
print "\nPlease type the SNMP Trap Filter's FULL host hostname\n";
&GetHostname ();
$SnmpName = $host;
print "\nIf a Trap Filter runs on this server, type the snmp (NMS) FULL hostname (CR otherwise)\n";
&GetHostname ();
$FilterName = $host;
# print "\nPlease type the Services mode (n - none, a - just apache, w - just weblogic, b - apache+weblogic, t - apache+weblogic+TrapsFilter, f - weblogic+TrapsFilter\n";
# $answer = <STDIN>;
# chop ($answer);
# if ($answer eq "b") { # apache, weblogic Services
# $ServicesMode = $answer;
# }
# elsif ($answer eq "n") { # none Services
# $ServicesMode = $answer;
# }
# elsif ($answer eq "a") { # apache Services
# $ServicesMode = $answer;
# }
# elsif ($answer eq "w") { # weblogic Services
# $ServicesMode = $answer;
# }
# elsif ($answer eq "f") { # weblogic, TrapsFilter Services
# $ServicesMode = $answer;
# }
# elsif ($answer eq "t") { # weblogic, Apache, TrapsFilter Services
# $ServicesMode = $answer;
# }
# else {#
# Illegal mode
# print "Illegal mode \n\n";
# exit;
# }
if ($ServerType eq "FES") { # apache, startFES Services
$ServicesMode = "e";
}
elsif ($ServerType eq "LCM") { # weblogic Services
$ServicesMode = "w";
}
else {
# Illegal mode
print "Illegal mode \n\n";
exit;
}
$ResrcDir = "/data/var";
print "Please type resource directory name, if not the default /data/var?\n";
print "Type CR, if /data/var\n";
$answer = <STDIN>;
chop ($answer);
$ResrcDir = $answer if ($answer =~ /\/\w+/); # Set resource dir if contains '/'
# Translate name to IP addr
$addr = gethostbyname ($Hostname);
$HostAddr = inet_ntoa($addr);
$HostAddr =~ /\d+.\d+.\d+.(\d+)/;
$Sched_ID = $1; # Set the scheduler ID as the last octet of the ip address
$WLS_Dir = "server".$Sched_ID; # The name of weblogic cluster dir
#$ServletSrvr = "";
#print "\nPlease type the Servlets Server's FULL host name\n";
#&GetHostname ();
#$ServletSrvr = $host;
# Check if proxy is used or jserv is used (FES)
if ($ServerType eq "LCM") { # GNS Server
$is_jserv=' '; # Commented out
$is_proxy='#'; # Commented out
$sl_app=' ';
}
elsif ($ServerType eq "LCM") { # LCM Server
$is_jserv='#';
$is_proxy='#';
$sl_app='#';
}
## Update httpd.conf according to Apache version - StrongHold or other. Yariv 14.6.2001, Temporary
print "Is Apache Stronghold system? (y/n)\n";
print "A CR means yes\n";
$answer = <STDIN>;
chop ($answer);
if ($answer =~ /n/) {
if (!system "mv $ConfTmp/httpd.conf_no_stronghold $ConfTmp/httpd.conf") { print "httpd.conf NON stronghold set\n";}
else { print "Modify of httpd.conf file FAILED!!!\n";}
}
if ($Sysname eq "Linux") {
if (!system "mv $ConfTmp/httpd.conf_lnx6.0 $ConfTmp/httpd.conf") { print "httpd.conf for Linux set\n";}
else { print "Modify of httpd.conf file for Linux FAILED!!!\n";}
}
# Configure httpd.conf - insert the hostname, domain and res-dir into the required
# places. Also, activate/deactivate proxy and jserv
&UpdateConf ("$ConfTmp/httpd.conf","as-name", $Hostname);
&UpdateConf ("$ConfTmp/httpd.conf","domain-name", $Domainname);
# &UpdateConf ("$ConfTmp/httpd.conf","resource-dir", $ResrcDir);
&UpdateConf ("$ConfTmp/httpd.conf","is-jserv", $is_jserv);
# &UpdateConf ("$ConfTmp/httpd.conf","is-proxy", $is_proxy);
# &UpdateConf ("$ConfTmp/httpd.conf","app-srvr", $ServletSrvr);
# Configure sdu.conf - insert the SDU server name into the required places
# &UpdateConf ("$ConfTmp/sdu.conf","sdu-name", $SduName);
# &UpdateConf ("$ConfTmp/sdu.conf","resource-dir", $ResrcDir);
# Configure trace.conf - insert the snmp server and trap filter names into the required places
&UpdateConf ("$ConfTmp/trace.conf","nms-srvr", $FilterName);
&AddRelatives("$ConfTmp/trace.conf", 'net', 'host',0);
# Configure sduagent.ini
&UpdateConf ("$ConfTmp/sduagent.ini","lcm-srvr", "$LcmName");
&UpdateConf ("$ConfTmp/sduagent.ini","sdu-srvr", "$SduName");
&UpdateConf ("$ConfTmp/sduagent.ini","as-name", "$Hostname");
&UpdateConf ("$ConfTmp/sduagent.ini","snmp-name", $SnmpName);
&UpdateConf ("$ConfTmp/sduagent.ini","fes-webname", $FesWebName);
&UpdateConf ("$ConfTmp/sduagent.ini","conv-mode", $ConvMode);
## Fill content in fesserv.conf and sduagent.ini
if ($ServerType eq "FES") {
&UpdateConf ("$ConfTmp/sduagent.ini","host-name", "$Hostname");
&UpdateConf ("$ConfTmp/fesserv.conf","host-name", "$Hostname");
## $status = system("/public/scripts/Add2FESServ");
}
# Configure glbservices.conf - set the Globecom services mode
&UpdateConf ("$ConfTmp/glbservices.conf","mode-char", $ServicesMode);
# Configure XmlConvertor.conf - set the resource-dir
# &UpdateConf ("$ConfTmp/XmlConvertor.conf","resource-dir", $ResrcDir);
# Configure rmserver.cfg - set the resource-dir
&UpdateConf ("$ConfTmp/rmserver.cfg","resource-dir", $ResrcDir);
# Configure weblogic.properties - set DB name and IP and DB password
# Configure a cluster if working in cluster mode
$WLS_Cluster = "false";
$ClusterIPs = $Hostname;
$WLS_ClusterName = ""; # Set empty cluster name
if ($ServerType eq "LCM") {
$WLS_Cluster = "true";
print "Is Weblogic cluster to be configured? (y/n)\n";
print "A CR means yes\n";
$answer = <STDIN>;
chop ($answer);
if ($answer =~ /n/) {
$WLS_Cluster = "false"; # Set yes or no
$WLS_ClusterName = "" if ($answer =~ /n/); # Set empty cluster name
$ClusterIPs = $Hostname;
}
else {
print "Please type the name of the other application server\n";
$answer = <STDIN>;
chop($answer);
# Translate name to IP addr
$addr = gethostbyname ($answer);
$OtherAddr = inet_ntoa($addr);
$OtherAddr =~ /\d+.\d+.\d+.(\d+)/;
$OtherID = $1; # Set the server ID as the last octet of the ip address
$OtherWLS_Dir = "server".$OtherID; # The name of weblogic other cluster dir
print "Please type the Cluster servers IPs - separated by ~ \n";
$answer = <STDIN>;
chop($answer);
$ClusterIPs = $answer;
# Set load algorithm to round-robin, and modify scheduler settings
&UpdateConf ("$ConfTmp/weblogic.properties","#weblogic.cluster.defaultLoadAlgorithm=round-robin","weblogic.cluster.defaultLoadAlgorithm=round-robin" );
&UpdateConf ("$ConfTmp/weblogic.properties","weblogic.system.startupClass.scheduler=globecom.globalsale.scheduler.schedulerMain","#weblogic.system.startupClass.scheduler=globecom.globalsale.scheduler.schedulerMain" );
&UpdateConf ("$ConfTmp/weblogic.properties","weblogic.system.startupArgs.scheduler=number=3","#weblogic.system.startupArgs.scheduler=number=3" );
&UpdateConf ("$ConfTmp/startWebLogic.sh","cluster.enable=false", "cluster.enable=true");
# Modify Multicast IP address if required
$MulticastIP = "237.0.0.1";
print "Please type Multicast IP Address, ( default is 237.0.0.1 )?\n";
print "Type CR, if 237.0.0.1\n";
$answer = <STDIN>;
chop ($answer);
$MulticastIP = $answer if ($answer =~ /\d+\.\d+/); # Set IP address if contains '.'
&UpdateConf ("$ConfTmp/startWebLogic.sh","237.0.0.1", $MulticastIP);
}
print "\nPlease type the Weblogic port number\n";
$WLport = <STDIN>;
chop($WLport);
&UpdateConf ("$ConfTmp/weblogic.properties","wl-port", $WLport);
&UpdateConf ("$ConfTmp/zone.properties","wl-port", $WLport);
&UpdateConf ("$ConfTmp/EJB_Param.ini","wl-port", $WLport);
&UpdateConf ("$ConfTmp/shutWebLogic.sh","wl-port", $WLport);
print "\nPlease type the FTP user name\n";
$FTPname = <STDIN>;
chop($FTPname);
print "\nPlease type the FTP account password\n";
$FTPpass = <STDIN>;
chop($FTPpass);
print "\nPlease type the Database name\n";
$DBname = <STDIN>;
chop($DBname);
&UpdateConf ("$ConfTmp/weblogic.properties","db-name", $DBname);
print "\nPlease type the Database account password\n";
$DBpw = <STDIN>;
chop($DBpw);
&UpdateConf ("$ConfTmp/weblogic.properties","db-pw", $DBpw);
print "\nPlease type the Database Server FULL host name\n";
&GetHostname ();
$DBServer = $host;
&UpdateConf ("$ConfTmp/weblogic.properties","db-srvr", $DBServer);
print "\nPlease type the Weblogic Server FULL host name\n";
&GetHostname ();
$WLServer = $host;
&UpdateConf ("$ConfTmp/weblogic.properties","wl-srvr", $WLServer);
print "\nPlease type the FTP site name\n";
&GetHostname ();
# $FtpName = $host.".$Domainname";
$FtpName = $host;
$FullHostName = $Hostname.".$Domainname";
&UpdateConf ("$ConfTmp/weblogic.properties","full-host", $FullHostName);
# Configure EJB_Param.ini - set Weblogic Server, FTP Server and SDU server name,
# database specifications and trace server
&UpdateConf ("$ConfTmp/EJB_Param.ini","clip-name", $ClusterIPs);
&UpdateConf ("$ConfTmp/EJB_Param.ini","wl-name", $Hostname);
&UpdateConf ("$ConfTmp/EJB_Param.ini","ftp-name", $FtpName);
&UpdateConf ("$ConfTmp/EJB_Param.ini","sdu-name", $SduName);
&UpdateConf ("$ConfTmp/EJB_Param.ini","sched_id", $Sched_ID);
&UpdateConf ("$ConfTmp/EJB_Param.ini","db-name", $DBname);
&UpdateConf ("$ConfTmp/EJB_Param.ini","db-pw", $DBpw);
&UpdateConf ("$ConfTmp/EJB_Param.ini","db-srvr", $DBServer);
&UpdateConf ("$ConfTmp/EJB_Param.ini","snmp-name", $SnmpName);
&UpdateConf ("$ConfTmp/EJB_Param.ini","os-name", "UNIX");
&UpdateConf ("$ConfTmp/EJB_Param.ini","xmlc-drive", "");
&UpdateConf ("$ConfTmp/EJB_Param.ini","ftp-user", $FTPname);
&UpdateConf ("$ConfTmp/EJB_Param.ini","ftp-pass", $FTPpass);
# Configure startWebLogic.sh start up script
&UpdateConf ("$ConfTmp/startWebLogic.sh","cluster-on", $WLS_Cluster);
&UpdateConf ("$ConfTmp/startWebLogic.sh","cluster-name", $WLS_ClusterName);
} # End of LCM-only procedure
# Configure apache/conf/jserv/zone.properties - set Weblogic and DB Server
&UpdateConf ("$ConfTmp/zone.properties","sched-name", $SduName);
&UpdateConf ("$ConfTmp/zone.properties","db-srvr", $DBServer);
&UpdateConf ("$ConfTmp/zone.properties","db-name", $DBname);
&UpdateConf ("$ConfTmp/zone.properties","sl-app", $sl_app);
&UpdateConf ("$ConfTmp/zone.properties","sl-sdu", $sl_sdu);
##if ($WLS_Cluster eq "true")
##{
## &UpdateConf ("$ConfTmp/zone.properties","wl-name", $WLS_ClusterName);
##} else {
## If cluster then some IPs, else - one IP
&UpdateConf ("$ConfTmp/zone.properties","clip-name", $ClusterIPs);
## &UpdateConf ("$ConfTmp/zone.properties","wl-name", $Hostname);
##}
print "\nPlease type the Domain name for Admin.html (example: gin.gcin.net) \n";
$DMname = <STDIN>;
chop($DMname);
&UpdateConf ("$ConfTmp/Admin.html","dm-name", $DMname);
## Copy original configuration files (without Globecom definitions) to side storage.
$status = system("/public/scripts/CPConfFiles");
## Move each file from /tmp/gc-conf into its place
if (!system "cp -f $ConfTmp/jserv.conf /usr/local/apache/conf/jserv/jserv.conf") { print "/usr/local/apache/conf/jserv/jserv.conf files copied\n";}
else { print "Copy of /usr/local/apache/conf/jserv/jserv.conf file FAILED!!!\n";}
if (!system "cp -f $ConfTmp/zone.properties /usr/local/apache/conf/jserv/zone.properties") { print "/usr/local/apache/conf/jserv/zone.properties files copied\n";}
else { print "Copy of /usr/local/apache/conf/jserv/zone.properties file FAILED!!!\n";}
if (!system "cp -f $ConfTmp/jserv.properties /usr/local/apache/conf/jserv/jserv.properties") { print "/usr/local/apache/conf/jserv/jserv.properties files copied\n";}
else { print "Copy of /usr/local/apache/conf/jserv/jserv.properties file FAILED!!!\n";}
if (!system "cp -f $ConfTmp/*.conf /usr/local/gwa/conf") { print "/usr/local/gwa/conf files copied\n";}
else { print "Copy of /usr/local/gwa/conf file FAILED!!!\n";}
if (!system "cp -f $ConfTmp/*.ini /usr/local/gwa/conf") { print "/usr/local/gwa/conf ini files copied\n";}
else { print "Copy of /usr/local/gwa/conf ini file FAILED!!!\n";}
if (!system "cp -f $ConfTmp/startWebLogic.sh /install/weblogic/startWebLogic.sh") { print "/install/weblogic/startWebLogic.sh files copied\n";}
else { print "Copy of /install/weblogic/startWebLogic.sh file FAILED!!!\n";}
if (!system "cp -f $ConfTmp/shutWebLogic.sh /install/weblogic/shutWebLogic.sh") { print "/install/weblogic/shutWebLogic.sh files copied\n";}
else { print "Copy of /install/weblogic/shutWebLogic.sh file FAILED!!!\n";}
if (!system "cp -f $ConfTmp/startTrapsFilter.sh /usr/local/gwa/bin/startTrapsFilter.sh") { print "startTrapsFilter.sh files copied\n";}
else { print "Copy of startTrapsFilter.sh file FAILED!!!\n";}
if (!system "cp -f $ConfTmp/Admin.html /install/weblogic/Admin.html") { print "Admin.html file copied\n";}
else { print "Copy of Admin.html file FAILED!!!\n";}
if (!system "cp -f $ConfTmp/Cancel.html /install/weblogic/Cancel.html") { print "Cancel.html file copied\n";}
else { print "Copy of Cancel.html file FAILED!!!\n";}
if (!system "cp -f $ConfTmp/httpd.conf /usr/local/apache/conf/httpd.conf") { print "/usr/local/apache/conf/httpd.conf files copied\n";}
else { print "Copy of /usr/local/apache/conf/httpd.conf file FAILED!!!\n";}
if (!system "cp -f $ConfTmp/rmserver.cfg /usr/local/real") { print "/usr/local/real/rmserver.cfg files copied\n";}
else { print "Copy of /usr/local/real/rmserver.cfg FAILED!!!\n";}
if ($ServerType eq "LCM") { # Application Server
if (!system "cp -f $ConfTmp/weblogic.properties /install/weblogic/weblogic.properties") { print "/install/weblogic/weblogic.properties files copied\n";}
else { print "Copy of /install/weblogic/weblogic.properties file FAILED!!!\n";}
}
if (!system "cp -f $ConfTmp/EJB_Param.ini /install/weblogic/EJB_Param.ini") { print "/install/weblogic/EJB_Param.ini files copied\n";}
else { print "Copy of /install/weblogic/EJB_Param.ini files FAILED!!!\n";}
# If Weblogic Cluster
if ($WLS_Cluster eq "true")
{
if (!system "cp -f $ConfTmp/weblogic.properties /install/weblogic/$WLS_ClusterName/weblogic.properties") { print "Copied to /install/weblogic/$WLS_ClusterName/weblogic.properties\n";}
else { print "Copy to /install/weblogic/$WLS_ClusterName/weblogic.properties file FAILED!!!\n";}
if (!system "cp -f $ConfTmp/weblogic.properties /install/weblogic/$WLS_ClusterName/$WLS_Dir/weblogic.properties") { print "Copied to /install/weblogic/$WLS_ClusterName/$WLS_Dir/weblogic.properties\n";}
else { print "Copy to /install/weblogic/$WLS_ClusterName/$WLS_Dir/weblogic.propertie files FAILED!!!\n";}
if (!system "cp -f $ConfTmp/weblogic.properties /install/weblogic/$WLS_ClusterName/$OtherWLS_Dir/weblogic.properties") { print "Copied to /install/weblogic/$WLS_ClusterName/$OtherWLS_Dir/weblogic.properties\n";}
else { print "Copy to /install/weblogic/$WLS_ClusterName/$OtherWLS_Dir/weblogic.properties file FAILED!!!\n";}
}
}
# Support subroutines ***************************************************************
## A subroutine to replace a generic value with the specific one in a given conf file
sub UpdateConf {
local ($filename,$generic,$specific) = @_; # locally name the parameters
print "\nReplacing -$generic- with -$specific- in $filename\n\n";
print CURR "$filename: $generic = $specific\n"; # Update current config file
local $newfile = "$filename-new";
open(CONFILE, $filename) || die "Cannot open $filename";
open(NEW, ">$newfile") || die "Cannot open $newfile";
while (<CONFILE>) {
if (/$generic/) { # If a line with the generic pattern is found
s/$generic/$specific/;
print "Updated line: $_ \n";
}
print NEW $_;
}
close(NEW);
close(CONFILE);
## Overwrite with new file
local $stat;
$stat = `rm -f $filename`;
$stat = `mv -f $newfile $filename`;
}
## A subroutine to add a list of relatives (children or parents) in a given conf file's section
sub AddRelatives {
local ($filename,$section,$prefix,$count) = @_; # locally name the parameters
print "\nAdding relatives to $section section of $filename\n\n";
local $newfile = "$filename-new";
local $relative;
local $i=0;
open(CONFILE, $filename) || die "Cannot open $filename: $!";
open(NEW, ">$newfile") || die "Cannot open $newfile: $!";
while (<CONFILE>) {
print NEW $_;
if (/$section/) { # If section found
next unless (/\[/); # Make sure a section name
# Loop inserting given names
print "Please, type the names of the $section servers FULL names, one per line\n";
print "Terminate the sequence with an empty line\n";
while (true) {
&GetHostname ();
$inp = $host;
last if (!($inp =~ /\w/)); # Exit on empty string
$i = $i + 1;
if ($count == 0) { ## Do not add a counter
print "$prefix"."="."$inp\n";
print NEW "$prefix"."="."$inp\n";
print CURR "$filename: $prefix"."= "."$inp\n"; # Update current config file
}
else { ## Add a counter
print "$prefix".$i." address="."$inp\n";
print NEW "$prefix".$i." address="."$inp\n";
print CURR "$filename: $prefix".$i." ="."$inp\n"; # Update current config file
}
}
}
}
close(NEW);
close(CONFILE);
## Overwrite with new file
local $stat;
$stat = `rm -f $filename`;
$stat = `mv -f $newfile $filename`;
}
sub GetHostname {
# Request a hostname and check that it has an IP address
while (true) { # Loop until a valid name is input
$host = "";
$haddr = "";
$hostn = <STDIN>;
chop($hostn);
last if (!($hostn =~ /\w/)); # If an empty string, exit
$gaddr = gethostbyname ($hostn);
if ($gaddr eq "") {
print "Bad hostname. Please, try again.\n";
}
else {
$ipaddr = inet_ntoa($gaddr);
$host = $hostn;
$haddr = $ipaddr;
last;
}
}
}