Repository: archiva
Updated Branches:
  refs/heads/master e37ed6209 -> de5a585c9


Adding powershell script for proc cleanup on CI server

This script is used by the jenkins builds to cleanup hanging processes
after abort.


Project: http://git-wip-us.apache.org/repos/asf/archiva/repo
Commit: http://git-wip-us.apache.org/repos/asf/archiva/commit/3bb2fad4
Tree: http://git-wip-us.apache.org/repos/asf/archiva/tree/3bb2fad4
Diff: http://git-wip-us.apache.org/repos/asf/archiva/diff/3bb2fad4

Branch: refs/heads/master
Commit: 3bb2fad4dcc10543320030d01d5b209f8e64de87
Parents: e37ed62
Author: Martin Stockhammer <[email protected]>
Authored: Sun Apr 30 21:45:14 2017 +0200
Committer: Martin Stockhammer <[email protected]>
Committed: Sun Apr 30 21:45:14 2017 +0200

----------------------------------------------------------------------
 src/ci/scripts/cleanup.bat |  4 ++
 src/ci/scripts/cleanup.ps1 | 96 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 100 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/archiva/blob/3bb2fad4/src/ci/scripts/cleanup.bat
----------------------------------------------------------------------
diff --git a/src/ci/scripts/cleanup.bat b/src/ci/scripts/cleanup.bat
new file mode 100644
index 0000000..fdb09df
--- /dev/null
+++ b/src/ci/scripts/cleanup.bat
@@ -0,0 +1,4 @@
+@echo off
+SET runpath=%~dp0
+
+PowerShell.exe -NonInteractive -ExecutionPolicy bypass -File 
%runpath%cleanup.ps1 %*

http://git-wip-us.apache.org/repos/asf/archiva/blob/3bb2fad4/src/ci/scripts/cleanup.ps1
----------------------------------------------------------------------
diff --git a/src/ci/scripts/cleanup.ps1 b/src/ci/scripts/cleanup.ps1
new file mode 100644
index 0000000..fd709ed
--- /dev/null
+++ b/src/ci/scripts/cleanup.ps1
@@ -0,0 +1,96 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+#
+# Powershell script for cleaning up remaining browser and selenium server 
processes on the CI servers
+#
+# Author: Martin Stockhammer <[email protected]>  
+# Date  : 2017-04-30
+#
+# Descriptions:
+#  Stopps processes related to the selenium checks, if they were not stopped 
by the selenium server, because
+#  the job was aborted.
+#  The script cannot determine, which of the processes are started by the 
current job, so if there are
+#  parallel jobs running on this server that start processes with the same 
name and user, these
+#  will be stopped too.
+#
+#  Per default the script will stop "firefox.exe","iexplore.exe","chrome.exe"
+#  and the processes "java.exe","mshta.exe" if their commandline arguments 
contain "selenium-server"
+# 
+# Parameters:
+#  -Verbose              : If set, more output will be printed
+#  -Browsers proc1,proc2 : The list of executables that define the browser 
processes, that are started by selenium
+#  -SeleniumProcesses    : The list of processes with the string 
"selenium-server" in the commandline arguments
+
+param (
+    [switch]$Verbose = $False,
+    [String[]]$Browsers = @("firefox.exe","iexplore.exe","chrome.exe"),
+    [String[]]$SeleniumProcesses = @("mshta.exe","java.exe")
+)
+
+# $currentUser = [System.Security.Principal.WindowsIdentity]::GetCurrent().Name
+$currentUser = $env:UserName
+Write-Output "User: $currentUser"
+
+if ($Verbose) 
+{
+  Get-Process | Get-Member
+  
+  $View = @(
+   @{l='Handles';e={$_.HandleCount}},
+   @{l='NPM(K)';e={ (Get-Process -Id 
$_.ProcessId).NonpagedSystemMemorySize/1KB -as [int]}},
+   @{l='PM(K)';e={ $_.PrivatePageCount/1KB -as [int]}},
+   @{l='WS(K)';e={ $_.WorkingSetSize/1KB -as [int]}},
+   @{l='VM(M)';e={ $_.VirtualSize/1mB -as [int]}},
+   @{l='CPU(s)';e={ (Get-Process -Id $_.ProcessId).CPU -as [int]}},
+   @{l='Id';e={ $_.ProcessId}},
+   'UserName'
+   @{l='ProcessName';e={ $_.ProcessName}}
+  )
+  Get-WmiObject Win32_Process | % { $_ | 
+      Add-Member -MemberType ScriptProperty -Name UserName -Value {
+          '{0}\{1}' -f $this.GetOwner().Domain,$this.GetOwner().User
+      } -Force -PassThru
+  }  
+}
+
+foreach ($procName in $SeleniumProcesses) 
+{
+  $processes = Get-WmiObject Win32_Process -Filter "name = '$procName'" | 
Where-Object {$_.GetOwner().User -eq $currentUser }  | Where-Object 
{$_.CommandLine -match "selenium-server"}
+  if ($Verbose) {
+    Write-Output "Filter: name = '$procName'"
+  }
+  foreach($proc in $processes)
+  {
+    Write-Output "stopping proccess $($proc.ProcessId) with 
$($proc.ThreadCount) threads; $($proc.CommandLine.Substring(0, 50))..."
+    Stop-Process -F $proc.ProcessId
+  }
+}
+
+foreach ($procName in $Browsers) 
+{
+  $processes = Get-WmiObject Win32_Process -Filter "name = '$procName'" | 
Where-Object {$_.GetOwner().User -eq $currentUser } 
+  if ($Verbose) {
+    Write-Output "Filter: name = '$procName'"
+  }
+  foreach($proc in $processes)
+  {
+     Write-Output "stopping proccess $($proc.ProcessId) with 
$($proc.ThreadCount) threads; $($proc.CommandLine.Substring(0, 50))..."
+     Stop-Process -F $proc.ProcessId
+  }
+}

Reply via email to