use threads; use strict; use Config; use Win32::Process::Info; use Win32::Registry; use Sys::Info::OS; use IO::Null; use IPC::System::Simple qw(capture capturex system systemx run runx $EXITVAL EXIT_ANY); use File::Copy; use Win32::Service; use Win32::Process; $| = 1; eval { UnInstallLUAWrapper(); }; if($@){ print "LUA uninstallation was not succeeded\n"; } else{ print "LUA uninstalled successfully\n"; } eval{ InstallLUA(); }; if($@){ print "LUA installation was not succeeded\nTrying one more time..\t\t"; InstallLUA(); } else{ print "LUA installed successfully\n"; } sub UnInstallLUAWrapper { killProcesses("isbew"); killProcesses("msiexec"); my $thr = threads->create( { 'context' => 'scalar', 'exit' => 'thread_only' }, \&UnInstallLUA ); die "thread is not initiated\n" unless ( $thr->is_running() ); my $childthreadId = $thr->tid(); sleep(180); # my $status = $thr->join(); # print "Child thread returned with satus: [$status]\n"; eval { print "Killing child thread id: $childthreadId\t\t"; $thr->kill('KILL')->detach() if ($thr->is_running()); }; if($@){ print "failed\n\n"; } else{ print "done\n\n"; #killProcesses("postgres"); } } sub InstallLUA { my $counter; print "\nInstalling LUA..\n"; eval { killProcesses("isbew"); killProcesses ("msiexec"); }; systemx qw(msiexec /qn /i "LUA.msi" /norestart /l*v LUAInstallationLogs.txt); if ($EXITVAL == 0){ print "done\n"; return 1; } else{ print "failed\n"; return 0; } } sub UnInstallLUA { $SIG{'KILL'} = sub { threads->exit(); }; my $counter; print "\nUninstalling LUA..\t\t"; eval { systemx qw(msiexec /qn /x "LUA.msi" /l*v LUAUninstallationLogs.txt UILevel="2" CLIENTUILEVEL="2" ); }; sleep(2); until ($@ || $counter > 120) { print " ."; sleep(1); $counter++; } if ($@){ print " failed\nLUA could not be uninstalled successfully\n\n"; } else{ print " done\nLUA uninstalled successfully\n\n"; } } sub getProcessIds { my $procName = shift; my $pi = Win32::Process::Info->new(); my @listPids; for($pi->ListPids){ my ($info) = $pi->GetProcInfo($_); push (@listPids, $_) if ($info->{CommandLine} =~ m/$procName/i); } return @listPids; } sub killProcesses { my $processName = shift; print "Killing running $processName processes if any..\n"; my @processPids = getProcessIds("$processName"); for my $pid (@processPids){ #my $isKilled = kill -9, $pid; $^E = 0; Win32::Process::KillProcess($pid, 1); sleep(1); my $err= $^E; unless ($err){ print "Killed pid: $pid\n"; } else{ print "Failed to kill pid: $pid\n"; print "Trying to kill pid $pid one more time using taskkill..\t\t"; eval {system qq(Taskkill /PID $pid /F > NUL 2>&1);}; sleep(1); # until ($@ || my $counter > 2) { # sleep(1); $counter++; # } unless ($@){ print "done\n\n"; } else { die "failed\n\n"; } } } 1; } #### C:\Jenkins Workspace\LUAESD\Setup>msiexec /qn /i "LUA.msi" /norestart /l*v LUAInstal lationLogs.txt C:\Jenkins Workspace\LUAESD\Setup> C:\Jenkins Workspace\LUAESD\Setup> C:\Jenkins Workspace\LUAESD\Setup>perl temp.pl Killing running isbew processes if any.. Killing running msiexec processes if any.. Failed to kill pid: 4100 Trying to kill pid 4100 one more time using taskkill.. done Uninstalling LUA.. Killing child thread id: 1 done LUA uninstalled successfully Installing LUA.. Killing running isbew processes if any.. Killed pid: 4332 Killing running msiexec processes if any.. Free to wrong pool 26540e0 not 2c39b8 during global destruction. Killed pid: 1712 <<<<<<< here, Perl.exe gets crashed