#!/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 " GNS - Globecom Neighborhood Server\n"; print " APP - Application Server\n"; print " WEBGNS - WEB + GNS Server\n"; print " WEBAPP - WEB + APP 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 #################### $ConfPool = '/public/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 "GNS") { &config_serv(); } # Configure a GNS node elsif ($ARGV[0] eq "APP") { &config_serv(); } # Configure Application Server elsif ($ARGV[0] eq "WEBGNS") { &config_serv(); } # Configure combined Server (GNS + WEB) elsif ($ARGV[0] eq "WEBAPP") { &config_serv(); } # Configure combined Server (APP + WEB) 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 " GNS - Globecom Neighborhood Server\n"; print " APP - Application Server\n"; print " WEBGNS - Combined Server (GNS + WEB)\n"; print " WEBAPP - Combined Server (APP + WEB)\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 Log Server's hostname\n"; &GetHostname (); $LogName = $host; print "\nPlease type the SDU Server's hostname\n"; &GetHostname (); $SduName = $host; print "\nPlease type the SNMP Trap Filter's hostname\n"; &GetHostname (); $SnmpName = $host; print "\nIf a Trap Filter runs on this server, type the snmp (NMS) hostname (CR otherwise)\n"; &GetHostname (); $FilterName = $host; print "\nPlease type the Services mode (n - just apache+npdd, a - also sda, u - also sdu, b - all\n"; $answer = ; chop ($answer); if ($answer eq "b") { # Apache, sda, sdu, npdd Services $ServicesMode = $answer; } elsif ($answer eq "u") { # Apache, sdu, npdd Services $ServicesMode = $answer; } elsif ($answer eq "a") { # Apache, sda, npdd Services $ServicesMode = $answer; } elsif ($answer eq "n") { # Apache, npdd Services $ServicesMode = $answer; } 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 = ; 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 = ""; # Check if Web Server (proxy is used) or Application Server (jserv is used) or just GNS if ($ServerType eq "GNS") { # GNS Server $is_jserv='#'; # Commented out $is_proxy='#'; # Commented out } elsif ($ServerType eq "APP" || $ServerType eq "WEBAPP") { # Application Server $is_jserv=' '; $is_proxy='#'; } elsif ($ServerType eq "WEBGNS") { # GNS + WEB Server $is_jserv='#'; $is_proxy=' '; print "\nPlease type the Servlets Server's hostname\n"; &GetHostname (); $ServletSrvr = $host; } ## 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 = ; ## 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 log.conf - insert the log server name into the required places &UpdateConf ("$ConfTmp/log.conf","log-name", $LogName); # 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","snmp-name", $SnmpName); &UpdateConf ("$ConfTmp/trace.conf","nms-srvr", $FilterName); &AddRelatives("$ConfTmp/trace.conf", 'net', 'host',0); # Configure npdd.conf to do not run Rsm ## (No Rsm for now) &UpdateConf ("$ConfTmp/npdd.conf","on-off", "off"); # 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 = "true"; print "Is Weblogic cluster to be configured? (y/n)\n"; print "A CR means yes\n"; $answer = ; 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 = ; 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 = ; 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 = ; 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 Database name\n"; $DBname = ; chop($DBname); &UpdateConf ("$ConfTmp/weblogic.properties","db-name", $DBname); print "\nPlease type the Database account password\n"; $DBpw = ; chop($DBpw); &UpdateConf ("$ConfTmp/weblogic.properties","db-pw", $DBpw); print "\nPlease type the Database Server name\n"; &GetHostname (); $DBServer = $host; &UpdateConf ("$ConfTmp/weblogic.properties","db-srvr", $DBServer); print "\nPlease type the FTP site name\n"; &GetHostname (); $FtpName = $host.".$Domainname"; # 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); # Configure startWebLogic.sh start up script &UpdateConf ("$ConfTmp/startWebLogic.sh","cluster-on", $WLS_Cluster); &UpdateConf ("$ConfTmp/startWebLogic.sh","cluster-name", $WLS_ClusterName); # Configure apache/conf/jserv/zone.properties - set Weblogic and DB Server &UpdateConf ("$ConfTmp/zone.properties","sched-name", $Hostname); &UpdateConf ("$ConfTmp/zone.properties","db-srvr", $DBServer); &UpdateConf ("$ConfTmp/zone.properties","db-name", $DBname); ##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); ##} ## Update rus.conf - according to existing/unexisting of Real server. Yariv 7.8.2001 print "Is Real-Server exist? (yes/no)\n"; $answer = ; chop ($answer); if ($answer =~ /yes/) { &UpdateConf ("$ConfTmp/rus.conf","yes-no", "yes"); } else { &UpdateConf ("$ConfTmp/rus.conf","yes-no", "no"); } # Configure rus.conf and pici.conf - insert the video server name into the required places # and add children print "\nPlease type the Video Server's hostname\n"; &GetHostname (); $VsName = $host; &UpdateConf ("$ConfTmp/rus.conf","vs-name", $VsName); &AddRelatives("$ConfTmp/rus.conf", 'children', 'child',1); &UpdateConf ("$ConfTmp/rus.conf","resource-dir", $ResrcDir); &UpdateConf ("$ConfTmp/pici.conf","resource-dir", $ResrcDir); # Insert pici and rus parents print "\nPlease type the PICI parent server's hostname\n"; &GetHostname (); $PiciName = $host; &UpdateConf ("$ConfTmp/pici.conf","pici-parent", $PiciName); print "\nPlease type the RUS parent server's hostname\n"; &GetHostname (); $RusName = $host; &UpdateConf ("$ConfTmp/rus.conf","rus-parent", $RusName); # Configure sda.conf and zax.conf - insert the correct resources directory # The zax.conf, also, requires the hostname before the tmp directory &UpdateConf ("$ConfTmp/sda.conf","resource-dir", $ResrcDir); &UpdateConf ("$ConfTmp/zax.conf","resource-dir", $ResrcDir); &UpdateConf ("$ConfTmp/sda.conf","gns-name", $Hostname); print "\nPlease type the Domain name for Admin.html (example: gin.gcin.net) \n"; $DMname = ; 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/*.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/startIsAlive.sh /usr/local/gwa/bin") { print "startIsAlive.sh file copied\n";} else { print "Copy of /usr/local/gwa/bin/startIsAlive.sh file FAILED!!!\n";} ## startWeblogic, shutWeblogic, startTarpFilter copy passed from "WEBAPP||APP" if below. Yariv, 3.6.2001. 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";} ## End change 3.6.2001 ## Copy main Html files to /install/weblogic . Yariv. 3.7.2001 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";} ## End change 3.7.2001 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 "WEBAPP" || $ServerType eq "APP") { # Application Server 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/weblogic.properties /install/weblogic/weblogic.properties") { print "/install/weblogic/weblogic.properties files copied\n";} else { print "Copy of /install/weblogic/weblogic.properties files 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 () { 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 () { 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, 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 = ; 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; } } }