function Get-URL([string] $url){
(New-Object net.webclient).DownloadString($url)
}
$g_backendUrl = "http://localhost:56783/"
function Test-KilnVersion(){
try {
$resp = Get-Url(($g_backendUrl + "version"))
return ($resp.length -gt 0)
}
catch {
return $False
}
}
function Test-KilnDiff([string] $sRepoGUID, [string] $sChangeset1, [string] $sChangeset2){
try {
$url =$g_backendUrl + "repo/" + $sRepoGUID + "/diff/" + $sChangeset1 + ":" + $sChangeset2 + "?format=json&ignorews=True&maxsize=100000&timeout=10"
$resp = Get-Url($url)
return ($resp.length -gt 0)
}
catch {
return $False
}
}
function Log-ServiceStats([string] $service, [string] $logFile){
try {
$measure = get-process $service -ErrorAction Stop | Measure-Object WorkingSet -sum
write "$(Get-Date -format o) The service $service has $($measure.Count) instances with a total WorkingSet of: $($measure.Sum)" | out-file -append $logFile
}
catch {
write "$(Get-Date -format o) The service $service is not currently running." | out-file -append $logFile
}
}
function Check-KilnBackend([string] $sRepoGUID, [string] $sChangeset1, [string] $sChangeset2, [string] $logFile = ""){
if (-Not ((Test-KilnVersion) -and (Test-KilnDiff $sRepoGUID $sChangeset1 $sChangeset2))){
#Restart the Kiln storage Service because something bad happened
write "$(Get-Date -format o) Something is wrong. Restarting Kiln Storage Service" | foreach{if ($logFile -ne "") {out-file -append $logFile} else {out-default}}
Restart-Service "KilnStorageService"
return $False
}
else {
write "$(Get-Date -format o) Kiln backend is OK" | foreach{if ($logFile -ne "") {$_ | out-file -append $logFile} else {$_ | out-default}}
return $True
}
}
|
Loading...