Browse Source

added Monitor_http.ps1

Tobias Simetsreiter 4 năm trước cách đây
mục cha
commit
aee284b9b9
1 tập tin đã thay đổi với 39 bổ sung0 xóa
  1. 39 0
      Monitor_http.ps1

+ 39 - 0
Monitor_http.ps1

@@ -0,0 +1,39 @@
+param(
+    $Uri = "http://localhost:8080",
+    $ServiceName = "tomcat8"
+)
+
+$Date = Get-Date
+
+$logfile = ".\logs\Monitor_http_{0}-{1}-{2}.log" -f ($Date.Year,$Date.Month,$Date.Day)
+
+Function main(){
+
+$Date.ToString()
+
+try {
+    $Response = Invoke-WebRequest -UseBasicParsing -URI $Uri
+    $success = $true
+} catch {
+    $_.exception
+    $success = $false
+}
+
+if ($success -and $Response.StatusCode -ne 200){
+    "Stopping Service ${ServiceName}"
+    net stop  $ServiceName
+    "Stopped Service ${ServiceName}"
+    sleep 20 | Out-Null
+    "Starting Service ${ServiceName}"
+    net start $ServiceName
+    "Started Service ${ServiceName}"
+} else {
+    "Service ${ServiceName} is up and running..."
+}
+}
+
+try {
+    main >> $logfile
+} catch {
+    $_.exception >> $logfile
+}