|
|
@@ -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
|
|
|
+}
|