File: //opt/VRTSpbx/bin/cluster/VxPBXclconf.pl
# $Copyright: Copyright (c) 2023 Veritas Technologies LLC. All rights reserved $
###########################################################################
# Cluster config script
# Usage: perl VxICSclconf.pl
# -v/V<VCS install location>
# -d/D<identification string> Debug only, commands go nowhere
# -c/C<input file>(The default is VxICSClusEnv.txt in the same dir)
# -u/U<resource type> cluster uninstallation
# -i/I local cluster installation
# -h/H/help gives the help
#
# Creation Date: 12/29/2003
###########################################################################
#!/bin/sh
eval 'exec /opt/VRTSvcs/bin/perl5 -x -S $0 ${1+"$@"}' if 0;
#!/opt/VRTSvcs/bin/perl5
# Some assumptions on names
my $log_file = "VxPBXClusterLogfile";
my $ics_cl_env_input = "VxICSClusEnv.txt";
my $ics_cl_env_conf = "VxICSClusEnv.conf";
my $log_to_file = 1;
my $interactive = 0;
my $debug_only = 0;
my $to_be_uninstall = 0;
my $local_install = 0;
my $reuse_config = 0;
my $is_windows = 0;
my $os_type = "None";
my $os_version = "None";
my $comm_separator = "/";
my $host_name = "";
# Global variables
my $vcs_home;
my ($system_list, $cluster_name, $parallel, $group);
my @groups;
my %home_path = ();
my %resource_map = () ;
my @res_command_list = ();
my @res_link_command_list = ();
my @grp_link_command_list = ();
my @cl_inst_command_list = ();
my @cl_uninst_command_list = ();
my @res_type_command_list = ();
my @sysdependarray = ();
my $pack;
my $command;
#Find out the OS
{
my $win = `ver`;
if ($win =~ /Windows/) {
$is_windows = 1;
$comm_separator = "\\";
}
else {
$os_type = `uname -s`;
$os_version = `uname -r`;
}
}
#Set default VCS home path
if ($is_windows) {
$vcs_home = "C:\\Program Files\\VERITAS\\Cluster Server";
}
else {
$vcs_home = "/opt/VRTSvcs";
}
#Host Name
$host_name=`hostname`;
###########################################################################
# Open a config log file. This would have the commands and the output
# TODO take the logfile location and the default logging
###########################################################################
if ($log_to_file == 1) {
&_log_msg("Trying to open Log file $log_file");
my $file_suc = open LOG, ">$log_file";
if ($file_suc) {
#Open failed
select LOG;
$| = 1;
select STDOUT;
&_log_msg("Buffer off for $log_file");
}
else {
#Open failed
&_log_msg("Failed to open $log_file");
$log_to_file = 0;
}
}
###########################################################################
# Subroutines
###########################################################################
# Sleep for a while
sub _vx_sleep {
my $tim = shift(@_);
if (!$debug_only) {
&_log_msg("sleeping for $tim seconds\n");
#print ("sleeping for $tim seconds\n");
sleep($tim);
}
}
#To log to file
sub _log_in_file {
if ($log_to_file == 1) {
printf LOG ("LOG:@_\n");
}
}
sub _log_msg{
if ($log_to_file == 1) {
printf LOG ("LOG:@_\n");
}
if ($interactive == 1) {
print ("LOG:@_\n");
}
}
# Print Usage
sub _print_usage {
print("\n\tperl VxPBXclconf.pl -c/C<input file>");
print("\n\t [-v/V<VCS Home Path>]");
print("\n\t [-d/D<string>]");
print("\n\t [-i/I]");
print("\n\t [-u/U]");
print("\n\t [-h/H]");
print("\n\t ");
print("\n\t[-v/V<path>]:VCS install location");
print("\n\t[-d/D<string>]:Debug mode only, commands go nowhere");
print("\n\t[-u/U]: Cluster unconfiguration");
print("\n\t[-i/I]: Intermediate node cluster configuration");
print("\n\t[-c/C<input file>]:PBX input file");
print("\n\t[-h/H/help]:Usage\n");
exit(0);
}
while (@ARGV)
{
$_ = shift;
if (/^-[cC](.*)/)
{
# Input file.
if ($1)
{
$ics_cl_env_input = $1;
&_log_msg("Input file = $ics_clus_env_input");
}
next;
}
elsif (/^-[vV](.*)/)
{
# Base dir for VCS.
if ($1)
{
$vcs_home = $1;
$vcs_home =~ s/\"//;
&_log_msg("VCS home = $vcs_home");
}
next;
}
#Debug Mode only
elsif (/^-[dD](.*)/)
{
$debug_only = 1;
if ($1)
{
my $trigger = $1;
&_log_msg("Debug mode only: Trigger: $trigger");
}
next;
}
#Cluster Uninstallation
elsif (/^-[uU](.*)/)
{
if ($local_install) {
print("Invalid combination of arguments ! Can't use installation and uninstallation simulataneously. \n");
exit(1);
}
$to_be_uninstall = 1;
if ($1) {
$pack = $1;
}
else {
$pack = "ALL";
}
}
#Local Cluster Installation
elsif (/^-[iI](.*)/)
{
if ($to_be_uninstall) {
print("Invalid combination of arguments ! Can't use installation and uninstallation simulataneously. \n");
exit(1);
}
$local_install = 1;
}
# Reusing existing cluster configurations
elsif (/^-[rR](.*)/)
{
if ($to_be_uninstall) {
print("Invalid combination of arguments ! Can't use installation and uninstallation simulataneously. \n");
exit(1);
}
$reuse_config = 1;
}
elsif (/^-[hH](.*)/ || /^-[hH]/)
{
&_print_usage();
next;
}
else
{
print "Invalid Argument !\n";
&_print_usage();
exit(1);
}
}
#To run an arbitrary command
sub _exec_cmd {
if (!$debug_only)
{
if ($is_windows) {
#system(@_);
if ($to_be_uninstall ==1)
{
`@_`;
}
else
{
`"@_"`;
}
}
else {
`@_`;
}
}
}
sub _exec_vcs_cmd_returnout {
my $vcs_bin = "$vcs_home$comm_separator"."bin" ;
my $int_cmd = "\"$vcs_bin$comm_separator@_";
my $val=`$int_cmd`;
chomp($val);
return $val;
}
sub _exec_vcs_cmd_returncode
{
my $vcs_bin = "$vcs_home$comm_separator"."bin" ;
my $int_cmd = "\"$vcs_bin$comm_separator@_ 2>&1 1> /dev/null";
my $val=system($int_cmd);
return $val;
}
sub _exec_vcs_cmd {
my $vcs_bin = "$vcs_home$comm_separator"."bin" ;
my $int_cmd = "\"$vcs_bin$comm_separator@_";
&_exec_cmd("$int_cmd");
}
sub _exec_cmd_chomp {
my $out = &_exec_cmd(@_);
chomp($out);
$out;
}
sub _exec_vcs_cmd_chomp {
my $out = &_exec_vcs_cmd(@_);
chomp($out);
$out;
}
#To print on stdout and run an arbitrary command
sub _exec_cmd_print {
&_log_msg("Dispatching command: @_");
&_exec_cmd(@_);
}
sub _exec_vcs_cmd_print {
&_log_msg("Dispatching VCS command: @_");
&_exec_vcs_cmd(@_);
}
#To run the commands in a list
sub _exec_cmd_list_print {
foreach my $sub_cmd (@_) {
&_exec_cmd_print($sub_cmd);
}
}
sub _exec_vcs_cmd_list_print {
foreach my $sub1_cmd (@_) {
&_exec_vcs_cmd_print($sub1_cmd);
}
}
#Check whether VCS is installed or not.
sub _die_if_no_vcs {
if (! -d $vcs_home)
{
&_log_msg("VCS is not installed");
if (!$debug_only)
{
die("VCS is not installed");
}
}
}
sub _vx_wait_till_online {
my $wait_time = 1;
# &_log_msg("Bring the resource online ...");
print("Bringing the resource online ...\n");
# print "@_\n";
# Try for vx_max_time_wait seconds
while ($wait_time <= $vx_max_time_wait)
{
$wait_time++;
if ($wait_time == $vx_max_time_wait) {
die "*** Command failed: $?\n" if $?;
}
my $vxresource_state = &_exec_vcs_cmd_chomp(@_);
if ($vxresource_state eq "ONLINE")
{
goto vx_wait_till_online_done;
}
&_vx_sleep(1);
# print("Wait till resource is in ONLINE state $wait_time\n");
}
vx_wait_till_online_done:
# Give some more time so that resource is available
&_vx_sleep(2);
# &_log_msg("Now online ...");
print("Now online ...\n");
# Return success
$? = 0;
}
sub _get_Y_or_N {
my ($input_str) ;
print "Enter y\/n :" ;
$input_str = <STDIN> ;
if ($input_str =~ /^n.*/i) {
return "n" ;
}
return "y" ;
}
# Remove redundant spaces
sub _remove_space {
my $str = "@_";
$str =~ s/^\s+//g;
$str =~ s/\s+$//g;
$str =~ s/\s+/ /g;
return $str;
}
##############################################################################
# Read resource type, its attributes, resource name, its attributes
# and dependency between resources from ICS input file (default
# ICS input file: VxICSClusEnv.txt)
##############################################################################
sub _read_section {
my $file_name;
if ($#_ <= 1) {
($file_name, $pack) = @_;
}
else {
&_log_msg("Invalid input args. Expecting filename");
return -1 ;
}
my ($file_name) = @_ ;
my ($sec_start, $gen_subsec_start, $res_type_subsec_start, $res_subsec_start, $cl_inst_subsec_start) ;
my $resource = 0 ;
my $dep_sec_start = 0;
my @grp_dep_sec_start = 0;
my $vcs_sec_start = 0 ;
my %name_vals = () ;
my @system_list = ();
unless (open(INPUT, $file_name)) {
&_log_msg("Unable to open cluster input file\n");
print "Unable to open cluster input file \n";
exit (1) ;
}
my @lines = <INPUT> ;
close(INPUT) ;
foreach my $line (@lines) {
chomp($line) ;
#
# If this is comment line, go to next line
#
next if (($line =~ /^#.*/) || ($line !~ /\w+/)) ;
#
# VCS, DEPENDENCY and Resource Section starts here
#
if ($line =~ /^Begin/ && $line =~ /$Section/) {
# Yet it is in Section field
if ($line !~ /SubSection/) {
my @first = split(/Begin/, $line);
my @second= split(/Section/, $first[1]) ;
$sec_name = $second[0];
# Only for VCS section, set "vcs_sec_start" variable
if ($sec_name eq "VCS") {
$vcs_sec_start = 1 ;
next;
}
# Only for dependency section, set "dep_sec_start" variable
if ($sec_name eq "DEPENDENCYLIST") {
$dep_sec_start = 1 ;
next;
}
# Only for group dependency section, set "grp_dep_sec_start" variable
if ($sec_name eq "GROUPDEPENDENCYLIST") {
$grp_dep_sec_start = 1 ;
next;
}
$sec_start = 1 ;
}
# Sub Section field starts
else {
if ($line =~ /BeginGenSubSection/) { $gen_subsec_start = 1; }
elsif ($line =~ /BeginResourceTypeSubSection/) { $res_type_subsec_start = 1; }
elsif ($line =~ /BeginResourceSubSection/) { $res_subsec_start = 1 ;}
elsif ($line =~ /BeginClusInstallSubSection/) { $cl_inst_subsec_start = 1; }
#TODO else: print error message
else {;}
}
}
# Don't go forward if you haven't entered any Section
elsif ($sec_start != 1 && $dep_sec_start != 1 && $vcs_sec_start != 1 && $grp_dep_sec_start != 1) {
next ;
}
#
# Section ends here
#
elsif (($line =~ /^End/ && $line =~ /$Section/)) {
my @intcommands;
my @intcommands2;
# At the end of the Section assign VCS and DEPENDENCY valus in variables
if ($line !~ /SubSection/) {
if ($sec_name eq "VCS") {
$system_list = $name_vals{"SystemList"};
$cluster_name = $name_vals{"ClusterName"} ;
$parallel = $name_vals{"Parallel"} ;
@groups = $name_vals{"GroupName"} ;
if ($name_vals{"HomePath"}) {
$vcs_home = $name_vals{"HomePath"} ;
if ( $is_windows ) {
my @temp = split ("\"", $vcs_home);
$vcs_home = $temp[1] ;
}
}
$group = $groups[0];
$vcs_sec_start = 0;
$sec_name = "" ;
$sec_start = 0 ;
@system_list = split (/\W*\s+\W*/, ($system_list));
}
elsif ($sec_name eq "DEPENDENCYLIST") {
&_make_link_res_commands(\%name_vals, \@intcommands) ;
push (@res_link_command_list, @intcommands);
$dep_sec_start = 0 ;
}
elsif ($sec_name eq "GROUPDEPENDENCYLIST") {
&_make_link_grp_commands(\%name_vals, \@intcommands, $group) ;
push (@grp_link_command_list, @intcommands);
$grp_dep_sec_start = 0 ;
}
}
# At the end of Subsection read the attribute values
# and make commands
else {
if ($line =~ /EndGenSubSection/) {
$gen_subsec_start = 0 ;
}
elsif ($line =~ /EndResourceTypeSubSection/) {
&_make_add_modify_restype_commands($sec_name, \%name_vals, \@system_list, \@intcommands);
push (@res_type_command_list, @intcommands);
$res_type_subsec_start = 0;
}
elsif ($line =~ /EndResourceSubSection/) {
if ($resource == 1) {
$resource = 0;
&_make_add_modify_res_commands($sec_name, \%name_vals, $group, \@intcommands) ;
push (@res_command_list, @intcommands);
# Remove the resources
if (($to_be_uninstall == 1) && (($sec_name eq $pack) ||($pack eq "ALL"))) {
my $command = "\"$vcs_home$comm_separator"."bin$comm_separator"."hares\" -delete $resource_map{$sec_name}" ;
push (@cl_uninst_command_list, $command);
}
}
$res_subsec_start = 0;
}
elsif ($line =~ /EndClusInstallSubSection/) {
if ($is_windows) {
&_make_cl_inst_commands_on_windows(\@system_list, $sec_name, \%name_vals, \@intcommands) ;
}
else {
&_make_cl_inst_commands(\@system_list, $sec_name, \%name_vals, \@intcommands) ;
}
push (@cl_inst_command_list, @intcommands);
if (($to_be_uninstall == 1) && (($sec_name eq $pack) ||($pack eq "ALL"))) {
if ($is_windows) {
&_make_cl_uninst_commands_on_windows(\@system_list, $sec_name, \%name_vals, \@intcommands2) ;
}
else {
&_make_cl_uninst_commands(\@system_list, $sec_name, \%name_vals, \@intcommands2) ;
}
push (@cl_uninst_command_list, @intcommands2);
}
$cl_inst_subsec_start = 0;
}
#TODO else: print error message
else {}
}
%name_vals = () ;
}
# Inside VCS section, read name value pair
elsif ($vcs_sec_start == 1) {
my @lhsrhs = split(/=/, $line) ;
$lhsrhs[0] = &_remove_space("$lhsrhs[0]");
$lhsrhs[1] = &_remove_space("$lhsrhs[1]");
$name_vals{"$lhsrhs[0]"} = "$lhsrhs[1]" ;
}
# Inside DEPENDENCY section
elsif ($dep_sec_start == 1) {
my @lhsrhs = split(/DependsOn/, $line) ;
$lhsrhs[0] = &_remove_space("$lhsrhs[0]");
$lhsrhs[1] = &_remove_space("$lhsrhs[1]");
push @{$name_vals{$lhsrhs[0]}},$lhsrhs[1] ;
}
# Inside GROUPDEPENDENCY section
# e.g ics IsChildAs online:local:soft
elsif ($grp_dep_sec_start == 1) {
my @lhsrhs = split(/IsChildAs/, $line) ;
$lhsrhs[0] = &_remove_space("$lhsrhs[0]");
$lhsrhs[1] = &_remove_space("$lhsrhs[1]");
push @{$name_vals{"childgroups"}},$lhsrhs[0] ;
$name_vals{$lhsrhs[0]."_dependencytype"}=$lhsrhs[1] ;
}
# Inside GEN subsection
elsif ($gen_subsec_start == 1) {
my @lhsrhs = split(/=/, $line) ;
$lhsrhs[0] = &_remove_space("$lhsrhs[0]");
$lhsrhs[1] = &_remove_space("$lhsrhs[1]");
if ($lhsrhs[0] =~ /HomePath/i) {
$home_path{"$sec_name"} = $lhsrhs[1] ;
}
#TODO: print error message
else {
}
}
# Inside resource and resource type sub section
elsif ($res_type_subsec_start == 1 || $res_subsec_start == 1) {
my @lhsrhs = split(/=/, $line) ;
$lhsrhs[0] = &_remove_space("$lhsrhs[0]");
$lhsrhs[1] = &_remove_space("$lhsrhs[1]");
if ($lhsrhs[0] =~ /ResourceName/) {
$resource_map{"$sec_name"} = "$lhsrhs[1]" ;
if ($lhsrhs[1] =~ /\w+/) {
$resource = 1 ;
next ;
}
}
else {
$name_vals{"$lhsrhs[0]"} = "$lhsrhs[1]" ;
}
if($lhsrhs[1]=~/<SysDepend>/ && $reuse_config==1)
{
my @lhs1split= split/</,$lhsrhs[1];
push(@sysdependarray,[$resource_map{"$sec_name"},$lhsrhs[0],$lhs1split[0]]);
}
}
# Inside cluster installation subsection
elsif ($cl_inst_subsec_start == 1) {
my ($src, $dest) = split(/CopyTo/, $line) ;
my @file;
my ($sourceF, $destF);
# if source or destination filenames contain HomePath,
# then we need to substitute with correct home path for
# that resource
if ($src =~ /HomePath/i) {
@file = split (/HomePath/i, $src);
$file[0] = &_remove_space("$file[0]");
$file[1] = &_remove_space("$file[1]");
$sourceF = $home_path{"$sec_name"}."$file[1]";
}
else {
$sourceF = $src;
}
if($is_windows) {
$sourceF =~ s/\//\\/g;
$sourceF =~ s/\"//g;
$sourceF = "\"$sourceF\"";
}
if ($dest =~ /HomePath/i) {
@file = split (/HomePath/i, $dest);
$file[0] = &_remove_space("$file[0]");
$file[1] = &_remove_space("$file[1]");
$destF = "$vcs_home$comm_separator"."bin"."$comm_separator$sec_name".$file[1];
}
else {
$destF = $dest;
}
if($is_windows) {
$destF =~ s/\//\\/g;
$destF = "$destF.pl";
$destF = "\"$destF\"";
}
$name_vals{"$sourceF"} = "$destF" ;
}
#TODO: print error message
else {
}
}
foreach my $i (@cl_inst_command_list) {
&_log_msg("$i") ;
}
&_log_msg();
foreach my $i (@cl_uninst_command_list) {
&_log_msg("$i") ;
}
&_log_msg();
foreach my $i (@res_type_command_list) {
&_log_msg("$i") ;
}
&_log_msg();
foreach my $i (@res_command_list) {
&_log_msg("$i") ;
}
&_log_msg();
foreach my $i (@res_link_command_list) {
&_log_msg("$i") ;
}
&_log_msg();
foreach my $i (@grp_link_command_list) {
&_log_msg("$i") ;
}
&_log_msg();
return 0 ;
}
###########################################################################
# Make the cluster install command list
###########################################################################
sub _make_cl_inst_commands {
if ($#_ != 3) {
&_log_msg("Invalid input args. Expecting System List, Section Name, Name Vals Ref, and Command Ref");
return -1 ;
}
my ($system_list_ref, $sec_name, $vals_ref, $commands_ref) = @_ ;
my $dir = "$vcs_home/bin/".$sec_name;
my $agent = "$sec_name"."Agent";
my @system_list = @$system_list_ref;
for my $each_system (@system_list) {
# if it is local install
my $sys = &_remove_space($each_system);
if (($local_install == 1) ||
($host_name =~ /$sys/)) {
push(@$commands_ref, "mkdir -p $dir 2>/dev/null");
push(@$commands_ref, "ln -s $vcs_home/bin/ScriptAgent $dir/$agent 2> /dev/null");
next;
}
else {
push(@$commands_ref, "rsh $each_system -n mkdir -p $dir 2>/dev/null");
push(@$commands_ref, "rsh $each_system -n ln -s $vcs_home/bin/ScriptAgent $dir/$agent 2> /dev/null");
}
}
foreach my $item (keys %$vals_ref) {
if (!($$vals_ref{$item}))
{
&_log_msg("Skipping command for $item");
next;
}
else
{
for my $each_system (@system_list) {
my $sys = &_remove_space($each_system);
if (($local_install == 1) || ($host_name =~ /$sys/)) {
push(@$commands_ref, "cp -r $item $$vals_ref{$item} 2> /dev/null");
next;
}
else {
#push(@$commands_ref, "rsh $each_system -n cp -r $item $$vals_ref{$item} 2> /dev/null");
#incident 420558
push(@$commands_ref, "rcp $item $each_system:$$vals_ref{$item} 2> /dev/null");
}
}
}
}
if($^O !~ /win/i)
{
my $PBX_HOME = "/opt/VRTSpbx";
my $PBX_BINDIR = "$PBX_HOME/bin";
my $UNIX_PBXCFG_WRAPPER = "pbxcfg";
&_exec_cmd("$PBX_BINDIR/$UNIX_PBXCFG_WRAPPER -e -C");
}
return 0 ;
}
###########################################################################
# Make the cluster install command list on Windows
###########################################################################
sub _make_cl_inst_commands_on_windows {
if ($#_ != 3) {
&_log_msg("Invalid input args. Expecting System List, Section Name, Name Vals Ref, and Command Ref");
return -1 ;
}
my ($system_list_ref, $sec_name, $vals_ref, $commands_ref) = @_ ;
my $dir = "$vcs_home$comm_separator"."bin"."$comm_separator$sec_name";
my @system_list = @$system_list_ref;
for my $each_system (@system_list) {
# if it is local install
if ($local_install == 1) {
push(@$commands_ref, "mkdir \"$dir\" ");
$command = "copy \"$vcs_home\\bin\\VCSdefault.dll\" \"$dir\\$sec_name.dll\"";
push(@$commands_ref, $command);
last;
}
# This part we will have to implement for remote cluster configuration
else {
}
}
foreach my $item (keys %$vals_ref) {
if (!($$vals_ref{$item}))
{
&_log_msg("Skipping command for $item");
next;
}
else
{
for my $each_system (@system_list) {
if ($local_install == 1) {
push(@$commands_ref, "copy $item $$vals_ref{$item}");
last;
}
# This part we will have to implement for remote cluster configuration
else {
}
}
}
}
return 0 ;
}
###########################################################################
# Make the cluster uninstall command list
###########################################################################
sub _make_cl_uninst_commands {
if ($#_ != 3) {
&_log_msg("Invalid input args. Expecting Name Vals Ref, and Command Ref");
return -1 ;
}
my ($system_list_ref, $sec_name, $vals_ref, $commands_ref, $res_name) = @_ ;
my @system_list = @$system_list_ref;
my $dir = "$vcs_home/bin/".$sec_name;
my $agent = "$sec_name"."Agent";
# Remove all the files from VCSHome/bin/RESOURCE directory
foreach my $item (keys %$vals_ref) {
if (!($$vals_ref{$item}))
{
&_log_msg("Skipping command for $item");
next;
}
else
{
for my $each_system (@system_list) {
my $sys = &_remove_space($each_system);
if($host_name =~ /$sys/) {
push(@$commands_ref, "rm -rf $$vals_ref{$item} 2> /dev/null");
}
else {
push(@$commands_ref, "rsh $each_system -n rm -rf $$vals_ref{$item} 2> /dev/null");
}
}
}
}
# Remove the RESOURCE directory from VCSHome/bin directory
for my $each_system (@system_list) {
my $sys = &_remove_space($each_system);
if($host_name =~ /$sys/) {
push(@$commands_ref, "rm -rf $dir/$agent 2>/dev/null");
push(@$commands_ref, "rm -rf $dir 2>/dev/null");
}
else {
push(@$commands_ref, "rsh $each_system -n rm -rf $dir/$agent 2>/dev/null");
push(@$commands_ref, "rsh $each_system -n rm -rf $dir 2>/dev/null");
}
}
push(@$commands_ref, "$vcs_home/bin/hatype -delete $sec_name");
if($^O !~ /win/i)
{
my $PBX_HOME = "/opt/VRTSpbx";
my $PBX_BINDIR = "$PBX_HOME/bin";
my $UNIX_PBXCFG_WRAPPER = "pbxcfg";
&_exec_cmd("$PBX_BINDIR/$UNIX_PBXCFG_WRAPPER -d -C");
}
return 0 ;
}
###########################################################################
# Make the cluster uninstall command list on WINDOWS
###########################################################################
sub _make_cl_uninst_commands_on_windows {
if ($#_ != 3) {
&_log_msg("Invalid input args. Expecting Name Vals Ref, and Command Ref");
return -1 ;
}
my ($system_list_ref, $sec_name, $vals_ref, $commands_ref, $res_name) = @_ ;
my @system_list = @$system_list_ref;
my $dir = "$vcs_home$comm_separator"."bin$comm_separator".$sec_name;
my $agent = "$sec_name"."Agent";
# Remove all the files from VCSHome\bin\RESOURCE directory
# foreach my $item (keys %$vals_ref) {
# if (!($$vals_ref{$item}))
# {
# &_log_msg("Skipping command for $item");
# next;
# }
# else
#
# for my $each_system (@system_list) {
# push(@$commands_ref, "rmdir \\S \\Q $$vals_ref{$item}");
# }
# }
# }
# Remove the RESOURCE directory from VCSHome/bin directory
# push(@$commands_ref, "rmdir \\S \\Q \" $dir\\$agent\" ");
push(@$commands_ref, " \"$vcs_home\\bin\\hatype\" -delete $sec_name");
push(@$commands_ref, "perl -e sleep(5);");
push(@$commands_ref, "rmdir /S /Q \"$dir\" ");
return 0 ;
}
###########################################################################
# Make the hares -add -modify command list
###########################################################################
sub _make_add_modify_res_commands {
if ($#_ != 3) {
&_log_msg("Invalid input args. Expecting Sectionname, Name Vals, and group name");
return -1 ;
}
my $dolocal = 1;
my ($sec_name, $vals_ref, $group, $commands_ref) = @_ ;
my $resource = $resource_map{$sec_name};
push(@$commands_ref, "hares\" -add $resource $sec_name $group") ;
foreach my $item (keys %$vals_ref) {
if (($$vals_ref{$item}) != 0 && !($$vals_ref{$item}))
{
&_log_msg("Skipping command for $item");
next;
}
# Set the attribute value for local system
elsif (($item =~ /.*@.*/))
{
my @lhsrhs = split(/@/, $item) ;
if ($dolocal)
{
push (@$commands_ref, "hares\" -local $resource $lhsrhs[0]");
--$dolocal;
}
push(@$commands_ref, "hares\" -modify $resource $lhsrhs[0] $$vals_ref{$item} -sys $lhsrhs[1]");
}
# Set the attribute value for all the system in a cluster
else
{
push(@$commands_ref, "hares\" -modify $resource $item $$vals_ref{$item}");
}
}
return 0 ;
}
###########################################################################
# Make the hares -link command list
###########################################################################
sub _make_link_res_commands {
if ($#_ != 1) {
&_log_msg("Invalid input args. Expecting Parent Resource, Child Resource and Command Reference");
return -1 ;
}
my ($vals_ref, $commands_ref) = @_ ;
foreach my $item (keys %$vals_ref) {
if (!($vals_ref->{$item})==-1) {
&_log_msg("Skipping command for $item");
next;
}
else {
my @childarray=@{$vals_ref->{$item}};
foreach $child (@childarray)
{
push(@$commands_ref, "hares\" -link $item $child");
}
}
}
return 0 ;
}
###########################################################################
# Make the hagrp -link command list
###########################################################################
sub _make_link_grp_commands {
if ($#_ != 2) {
&_log_msg("Invalid input args. Expecting Parent Group, Child Group and Command Reference");
return -1 ;
}
my ($vals_ref, $commands_ref, $group) = @_ ;
my @childarray=@{$vals_ref->{"childgroups"}};
foreach $childgroup (@childarray)
{
my $dependencytypestring=$vals_ref->{$childgroup."_dependencytype"};
my @dependencytypearray=split /:/,$dependencytypestring;
push(@$commands_ref, "hagrp\" -link $group $childgroup $dependencytypearray[0] $dependencytypearray[1] $dependencytypearray[2]");
}
return 0 ;
}
###########################################################################
# Make the haattr -add -modify command list
###########################################################################
sub _make_add_modify_restype_commands {
if ($#_ != 3) {
&_log_msg("Invalid input args. Expecting Sectionname, Name Vals, and group name");
return -1 ;
}
my ($sec_name, $vals_ref, $systemListRef, $commands_ref) = @_ ;
my $args;
# check if PBX is already installed
my $typeexists = &_exec_vcs_cmd_returncode("hatype\" -display $sec_name");
if ($typeexists == 0)
{
return 0;
}
push(@$commands_ref, "hatype\" -add $sec_name") ;
if ($is_windows) {
# push(@$commands_ref, "hatype\" -modify $sec_name SourceFile .\$sec_name.cf") ;
}
else {
push(@$commands_ref, "hatype\" -modify $sec_name SourceFile ./$sec_name.cf") ;
}
# First find out what are the arguments in ArgList
foreach my $item (keys %$vals_ref) {
if ($item =~ /ArgList/) {
$args = $$vals_ref{$item};
push(@$commands_ref, "hatype\" -modify $sec_name $item $$vals_ref{$item}");
}
}
foreach my $item (keys %$vals_ref) {
if (!($$vals_ref{$item}))
{
&_log_msg("Skipping command for $item");
next;
}
# Add the resource attribute value to a resource type
elsif ($args =~ /$item/) {
if ($$vals_ref{$item} =~ /\w+/) {
if ( $item =~ /path/i ) {
my $path = $$vals_ref{$item};
if ( $path =~ /^(.*)\\\"/ ) {
$path=$1."\"";
}
push(@$commands_ref, "haattr\" -add $sec_name $item $path");
}
else {
push(@$commands_ref, "haattr\" -add $sec_name $item $$vals_ref{$item}");
}
}
}
# Modify the resource type attribute value
else
{
if ($item !~ /ArgList/) {
push(@$commands_ref, "hatype\" -modify $sec_name $item $$vals_ref{$item}");
}
}
}
my @system_list = @$systemListRef;
# Start the agents
for ($i=0; $i<= $#system_list; ++$i) {
push(@$commands_ref, "haagent\" -start $sec_name -sys $system_list[$i]");
}
return 0 ;
}
###########################################################################
# No use going forward if VCS is not there, so die.
###########################################################################
&_die_if_no_vcs;
###########################################################################
#Cluster Uninstallation
###########################################################################
if ($to_be_uninstall ==1)
{
if (($to_be_uninstall == 1) && (($sec_name eq $pack) ||($pack eq "ALL"))) {
my $command = "\"$vcs_home$comm_separator"."bin"."$comm_separator"."haconf\" -makerw";
push (@cl_uninst_command_list, $command);
}
&_read_section($ics_cl_env_input, $pack) ;
$command = "\"$vcs_home$comm_separator"."bin"."$comm_separator"."hagrp\" -delete $groups[0]";
push (@cl_uninst_command_list, $command);
&_exec_cmd_list_print(@cl_uninst_command_list);
&_log_msg("Close and dump the configuration");
my $cmd = "haconf\" -dump -makero";
&_exec_vcs_cmd_print($cmd);
&_vx_sleep(2);
exit(0);
}
###########################################################################
# Read VCS, Resource and VCS configuration and make list of commands
###########################################################################
&_read_section($ics_cl_env_input) ;
###########################################################################
#Cluster Installation
###########################################################################
&_exec_cmd_list_print(@cl_inst_command_list);
&_vx_sleep(2);
# if local cluster installation, then after installation don't go forward.
if ($local_install == 1 ) {
exit(0);
}
#if reuse config then just set sysdepend properties and add hostname to grp's list and quit
if ($reuse_config == 1 ) {
my $host=$host_name;
chomp($host);
my $cmd = "hagrp\" -modify $groups[0] SystemList -add $host 1";
&_exec_vcs_cmd_print($cmd);
foreach $trio (@sysdependarray)
{
my $cmd = "hares\" -modify $trio->[0] $trio->[1] $trio->[2] -sys $host";
&_exec_vcs_cmd_print($cmd);
}
exit(0);
}
###########################################################################
# Configure VCS
###########################################################################
# Make the config writable
{
&_log_msg( "Make VCS config writable");
my $cmd = "haconf\" -makerw";
&_exec_vcs_cmd_print($cmd);
}
#Custom Agent Configuration
&_exec_vcs_cmd_list_print(@res_type_command_list);
&_vx_sleep(10);
my @systems_temp = split (/\W*\s+\W*/, $system_list);
my @systems = ();
if (($systems_temp[0]) eq "all")
{
@systems= &_exec_vcs_cmd("hasys\" -list");
}
else
{
@systems = @systems_temp;
}
&_log_msg("Systems in the cluster for the APP:\n @systems");
# Configure the groups on the systems.
&_log_msg("Following Groups would be configured on the systems visible:\n @groups");
foreach $group (@groups)
{
&_log_msg("configuring group $group");
my $cmd = "hagrp\" -add $group";
&_exec_vcs_cmd_print($cmd);
}
# Configure system list for the groups.
&_log_msg("Adding the system list on groups");
foreach my $grp (@groups)
{
my $i = 0;
foreach my $system (@systems)
{
chomp($system);
my $cmd = "hagrp\" -modify $grp SystemList -add $system $i";
&_exec_vcs_cmd_print($cmd);
$i++;
}
}
&_log_msg("Adding the system list on groups autostartlist");
foreach my $grp (@groups)
{
foreach my $system (@systems)
{
chomp($system);
my $cmd = "hagrp\" -modify $grp AutoStartList -add $system";
&_exec_vcs_cmd_print($cmd);
}
}
foreach my $grp (@groups)
{
my $cmd = "hagrp\" -modify $grp Parallel $parallel";
&_exec_vcs_cmd_print($cmd);
}
# Add the resources to the group
&_exec_vcs_cmd_list_print(@res_command_list);
&_vx_sleep(5);
# Link the resources
&_exec_vcs_cmd_list_print(@res_link_command_list);
&_vx_sleep(5);
# Link the groups
&_exec_vcs_cmd_list_print(@grp_link_command_list);
&_vx_sleep(5);
#Start the service group
{
&_log_msg("Start $groups[0]");
my $cmd = "hagrp\" -enableresources $groups[0]";
&_exec_vcs_cmd_print($cmd);
&_vx_sleep(10);
}
foreach my $system (@systems)
{
my $sub3_cmd = "hagrp\" -online $groups[0] -sys $system";
&_exec_vcs_cmd_print($sub3_cmd);
&_vx_sleep(5);
my $sub4_cmd = "hagrp \" -state $groups[0] -sys $system ";
&_vx_wait_till_online($sub4_cmd);
# &_vx_sleep(2);
}
#Close the configuration
{
&_log_msg("Close and dump the configuration");
my $cmd = "haconf\" -dump -makero";
&_exec_vcs_cmd_print($cmd);
}