commit 587e11a6e8630a89683655c84bffa353746a7932 Author: Joe Date: Fri Jan 4 20:11:55 2019 -0600 Initial diff --git a/AppPoolRecycler.docx b/AppPoolRecycler.docx new file mode 100644 index 0000000..b5f5eff Binary files /dev/null and b/AppPoolRecycler.docx differ diff --git a/AppPoolRecycler.sln b/AppPoolRecycler.sln new file mode 100644 index 0000000..32541d7 --- /dev/null +++ b/AppPoolRecycler.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2013 +VisualStudioVersion = 12.0.31101.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "AppPoolRecycler", "AppPoolRecycler\AppPoolRecycler.vbproj", "{2F8ADCFA-52FD-4BAA-B551-0EC614B7DEB2}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {2F8ADCFA-52FD-4BAA-B551-0EC614B7DEB2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2F8ADCFA-52FD-4BAA-B551-0EC614B7DEB2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2F8ADCFA-52FD-4BAA-B551-0EC614B7DEB2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2F8ADCFA-52FD-4BAA-B551-0EC614B7DEB2}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/AppPoolRecycler.v12.suo b/AppPoolRecycler.v12.suo new file mode 100644 index 0000000..8cdc020 Binary files /dev/null and b/AppPoolRecycler.v12.suo differ diff --git a/AppPoolRecycler/App.config b/AppPoolRecycler/App.config new file mode 100644 index 0000000..7e5c86d --- /dev/null +++ b/AppPoolRecycler/App.config @@ -0,0 +1,24 @@ + + + + +
+ + + + + + + + + 300 + + + CasAppPool,CasReportWSPool + + + 60 + + + + \ No newline at end of file diff --git a/AppPoolRecycler/AppPoolRecycler.Designer.vb b/AppPoolRecycler/AppPoolRecycler.Designer.vb new file mode 100644 index 0000000..8a5e875 --- /dev/null +++ b/AppPoolRecycler/AppPoolRecycler.Designer.vb @@ -0,0 +1,48 @@ +Imports System.ServiceProcess + + _ +Partial Class AppPoolRecycler + Inherits System.ServiceProcess.ServiceBase + + 'UserService overrides dispose to clean up the component list. + _ + Protected Overrides Sub Dispose(ByVal disposing As Boolean) + Try + If disposing AndAlso components IsNot Nothing Then + components.Dispose() + End If + Finally + MyBase.Dispose(disposing) + End Try + End Sub + + ' The main entry point for the process + _ + _ + Shared Sub Main() + Dim ServicesToRun() As System.ServiceProcess.ServiceBase + + ' More than one NT Service may run within the same process. To add + ' another service to this process, change the following line to + ' create a second service object. For example, + ' + ' ServicesToRun = New System.ServiceProcess.ServiceBase () {New Service1, New MySecondUserService} + ' + ServicesToRun = New System.ServiceProcess.ServiceBase() {New AppPoolRecycler} + + System.ServiceProcess.ServiceBase.Run(ServicesToRun) + End Sub + + 'Required by the Component Designer + Private components As System.ComponentModel.IContainer + + ' NOTE: The following procedure is required by the Component Designer + ' It can be modified using the Component Designer. + ' Do not modify it using the code editor. + _ + Private Sub InitializeComponent() + components = New System.ComponentModel.Container() + Me.ServiceName = "AppPoolRecycler" + End Sub + +End Class diff --git a/AppPoolRecycler/AppPoolRecycler.vb b/AppPoolRecycler/AppPoolRecycler.vb new file mode 100644 index 0000000..35b593a --- /dev/null +++ b/AppPoolRecycler/AppPoolRecycler.vb @@ -0,0 +1,58 @@ +Imports Microsoft.Web.Administration +Public Class AppPoolRecycler + Private m_EventLog As System.Diagnostics.EventLog + + Protected Overrides Sub OnStart(ByVal args() As String) + ' Add code here to start your service. This method should set things + ' in motion so your service can do its work. + Dim timer As System.Timers.Timer = New System.Timers.Timer() + timer.Interval = My.Settings.CheckSeconds * 1000 ' Milliseconds... + AddHandler timer.Elapsed, AddressOf Me.OnTimer + timer.Start() + + Dim allPools As String = "" + For Each thePool As String In My.Settings.AppPools.Split(",") + allPools += "[" + thePool + "] " + Next + m_EventLog.WriteEntry("CASAppCool Recycle Service has Started. - the pools " + allPools + " will be checked every " & My.Settings.CheckSeconds & " Seconds and requests wich run more than " & My.Settings.MaxReqSeconds & " will be recycled.") + End Sub + + Private Sub OnTimer(sender As Object, e As Timers.ElapsedEventArgs) + For Each theAppPool As String In My.Settings.AppPools.Split(",") + RecycleAppPool(theAppPool) + Next + + End Sub + + Public Sub New() + MyBase.New() + InitializeComponent() + m_EventLog = New System.Diagnostics.EventLog + If Not System.Diagnostics.EventLog.SourceExists("AppPoolRecycler") Then + System.Diagnostics.EventLog.CreateEventSource("AppPoolRecycler", + "Application") + End If + m_EventLog.Source = "AppPoolRecycler" + m_EventLog.Log = "Application" + End Sub + + Public Sub RecycleAppPool(appPoolName As String) + Dim ServerManager As New ServerManager() + Dim CasAppPool As ApplicationPool = ServerManager.ApplicationPools.Item(appPoolName) + For Each wp As WorkerProcess In CasAppPool.WorkerProcesses + For Each req As Request In wp.GetRequests(My.Settings.MaxReqSeconds * 1000) + If CasAppPool.State = ObjectState.Started Then + CasAppPool.Recycle() + m_EventLog.WriteEntry(appPoolName & " has been recycled!! ") + End If + Next + Next + + End Sub + + Protected Overrides Sub OnStop() + ' Add code here to perform any tear-down necessary to stop your service. + m_EventLog.WriteEntry("CASAppPool Recycle Service has Stopped.") + End Sub + +End Class diff --git a/AppPoolRecycler/AppPoolRecycler.vbproj b/AppPoolRecycler/AppPoolRecycler.vbproj new file mode 100644 index 0000000..e1d7918 --- /dev/null +++ b/AppPoolRecycler/AppPoolRecycler.vbproj @@ -0,0 +1,144 @@ + + + + + Debug + AnyCPU + {2F8ADCFA-52FD-4BAA-B551-0EC614B7DEB2} + WinExe + AppPoolRecycler.AppPoolRecycler + AppPoolRecycler + AppPoolRecycler + 512 + Console + v4.5 + + + AnyCPU + true + full + true + true + bin\Debug\ + AppPoolRecycler.xml + 42016,41999,42017,42018,42019,42032,42036,42020,42021,42022 + + + AnyCPU + pdbonly + false + true + true + bin\Release\ + AppPoolRecycler.xml + 42016,41999,42017,42018,42019,42032,42036,42020,42021,42022 + + + On + + + Binary + + + Off + + + On + + + + False + ..\..\..\..\..\..\..\Windows\System32\inetsrv\Microsoft.Web.Administration.dll + + + + + + + + + + + + + + + + + + + + + + + + + + True + Application.myapp + + + Component + + + AppPoolRecycler.vb + + + + True + True + Resources.resx + + + True + Settings.settings + True + + + ProjectInstaller.vb + + + Component + + + + + VbMyResourcesResXFileCodeGenerator + Resources.Designer.vb + My.Resources + Designer + + + ProjectInstaller.vb + + + + + Always + + + MyApplicationCodeGenerator + Application.Designer.vb + + + SettingsSingleFileGenerator + My + Settings.Designer.vb + + + + Always + + + + + + + + \ No newline at end of file diff --git a/AppPoolRecycler/My Project/Application.Designer.vb b/AppPoolRecycler/My Project/Application.Designer.vb new file mode 100644 index 0000000..db8b8b3 --- /dev/null +++ b/AppPoolRecycler/My Project/Application.Designer.vb @@ -0,0 +1,13 @@ +'------------------------------------------------------------------------------ +' +' This code was generated by a tool. +' Runtime Version:4.0.30319.42000 +' +' Changes to this file may cause incorrect behavior and will be lost if +' the code is regenerated. +' +'------------------------------------------------------------------------------ + +Option Strict On +Option Explicit On + diff --git a/AppPoolRecycler/My Project/Application.myapp b/AppPoolRecycler/My Project/Application.myapp new file mode 100644 index 0000000..59bc36e --- /dev/null +++ b/AppPoolRecycler/My Project/Application.myapp @@ -0,0 +1,10 @@ + + + false + false + 0 + true + 0 + 3 + true + diff --git a/AppPoolRecycler/My Project/AssemblyInfo.vb b/AppPoolRecycler/My Project/AssemblyInfo.vb new file mode 100644 index 0000000..051cca1 --- /dev/null +++ b/AppPoolRecycler/My Project/AssemblyInfo.vb @@ -0,0 +1,35 @@ +Imports System +Imports System.Reflection +Imports System.Runtime.InteropServices + +' General Information about an assembly is controlled through the following +' set of attributes. Change these attribute values to modify the information +' associated with an assembly. + +' Review the values of the assembly attributes + + + + + + + + + + +'The following GUID is for the ID of the typelib if this project is exposed to COM + + +' Version information for an assembly consists of the following four values: +' +' Major Version +' Minor Version +' Build Number +' Revision +' +' You can specify all the values or you can default the Build and Revision Numbers +' by using the '*' as shown below: +' + + + diff --git a/AppPoolRecycler/My Project/Resources.Designer.vb b/AppPoolRecycler/My Project/Resources.Designer.vb new file mode 100644 index 0000000..565c00c --- /dev/null +++ b/AppPoolRecycler/My Project/Resources.Designer.vb @@ -0,0 +1,63 @@ +'------------------------------------------------------------------------------ +' +' This code was generated by a tool. +' Runtime Version:4.0.30319.42000 +' +' Changes to this file may cause incorrect behavior and will be lost if +' the code is regenerated. +' +'------------------------------------------------------------------------------ + +Option Strict On +Option Explicit On + +Imports System + +Namespace My.Resources + + 'This class was auto-generated by the StronglyTypedResourceBuilder + 'class via a tool like ResGen or Visual Studio. + 'To add or remove a member, edit your .ResX file then rerun ResGen + 'with the /str option, or rebuild your VS project. + ''' + ''' A strongly-typed resource class, for looking up localized strings, etc. + ''' + _ + Friend Module Resources + + Private resourceMan As Global.System.Resources.ResourceManager + + Private resourceCulture As Global.System.Globalization.CultureInfo + + ''' + ''' Returns the cached ResourceManager instance used by this class. + ''' + _ + Friend ReadOnly Property ResourceManager() As Global.System.Resources.ResourceManager + Get + If Object.ReferenceEquals(resourceMan, Nothing) Then + Dim temp As Global.System.Resources.ResourceManager = New Global.System.Resources.ResourceManager("AppPoolRecycler.Resources", GetType(Resources).Assembly) + resourceMan = temp + End If + Return resourceMan + End Get + End Property + + ''' + ''' Overrides the current thread's CurrentUICulture property for all + ''' resource lookups using this strongly typed resource class. + ''' + _ + Friend Property Culture() As Global.System.Globalization.CultureInfo + Get + Return resourceCulture + End Get + Set + resourceCulture = value + End Set + End Property + End Module +End Namespace diff --git a/AppPoolRecycler/My Project/Resources.resx b/AppPoolRecycler/My Project/Resources.resx new file mode 100644 index 0000000..ffecec8 --- /dev/null +++ b/AppPoolRecycler/My Project/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/AppPoolRecycler/My Project/Settings.Designer.vb b/AppPoolRecycler/My Project/Settings.Designer.vb new file mode 100644 index 0000000..45addb0 --- /dev/null +++ b/AppPoolRecycler/My Project/Settings.Designer.vb @@ -0,0 +1,109 @@ +'------------------------------------------------------------------------------ +' +' This code was generated by a tool. +' Runtime Version:4.0.30319.42000 +' +' Changes to this file may cause incorrect behavior and will be lost if +' the code is regenerated. +' +'------------------------------------------------------------------------------ + +Option Strict On +Option Explicit On + + +Namespace My + + _ + Partial Friend NotInheritable Class MySettings + Inherits Global.System.Configuration.ApplicationSettingsBase + + Private Shared defaultInstance As MySettings = CType(Global.System.Configuration.ApplicationSettingsBase.Synchronized(New MySettings()),MySettings) + +#Region "My.Settings Auto-Save Functionality" +#If _MyType = "WindowsForms" Then + Private Shared addedHandler As Boolean + + Private Shared addedHandlerLockObject As New Object + + _ + Private Shared Sub AutoSaveSettings(ByVal sender As Global.System.Object, ByVal e As Global.System.EventArgs) + If My.Application.SaveMySettingsOnExit Then + My.Settings.Save() + End If + End Sub +#End If +#End Region + + Public Shared ReadOnly Property [Default]() As MySettings + Get + +#If _MyType = "WindowsForms" Then + If Not addedHandler Then + SyncLock addedHandlerLockObject + If Not addedHandler Then + AddHandler My.Application.Shutdown, AddressOf AutoSaveSettings + addedHandler = True + End If + End SyncLock + End If +#End If + Return defaultInstance + End Get + End Property + + _ + Public Property MaxReqSeconds() As String + Get + Return CType(Me("MaxReqSeconds"),String) + End Get + Set + Me("MaxReqSeconds") = value + End Set + End Property + + _ + Public Property AppPools() As String + Get + Return CType(Me("AppPools"),String) + End Get + Set + Me("AppPools") = value + End Set + End Property + + _ + Public Property CheckSeconds() As String + Get + Return CType(Me("CheckSeconds"),String) + End Get + Set + Me("CheckSeconds") = value + End Set + End Property + End Class +End Namespace + +Namespace My + + _ + Friend Module MySettingsProperty + + _ + Friend ReadOnly Property Settings() As Global.AppPoolRecycler.My.MySettings + Get + Return Global.AppPoolRecycler.My.MySettings.Default + End Get + End Property + End Module +End Namespace diff --git a/AppPoolRecycler/My Project/Settings.settings b/AppPoolRecycler/My Project/Settings.settings new file mode 100644 index 0000000..356ed5c --- /dev/null +++ b/AppPoolRecycler/My Project/Settings.settings @@ -0,0 +1,15 @@ + + + + + + 300 + + + CasAppPool,CasReportWSPool + + + 60 + + + \ No newline at end of file diff --git a/AppPoolRecycler/ProjectInstaller.Designer.vb b/AppPoolRecycler/ProjectInstaller.Designer.vb new file mode 100644 index 0000000..308b2f4 --- /dev/null +++ b/AppPoolRecycler/ProjectInstaller.Designer.vb @@ -0,0 +1,48 @@ + Partial Class ProjectInstaller + Inherits System.Configuration.Install.Installer + + 'Installer overrides dispose to clean up the component list. + _ + Protected Overrides Sub Dispose(ByVal disposing As Boolean) + Try + If disposing AndAlso components IsNot Nothing Then + components.Dispose() + End If + Finally + MyBase.Dispose(disposing) + End Try + End Sub + + 'Required by the Component Designer + Private components As System.ComponentModel.IContainer + + 'NOTE: The following procedure is required by the Component Designer + 'It can be modified using the Component Designer. + 'Do not modify it using the code editor. + _ + Private Sub InitializeComponent() + Me.ServiceProcessInstaller1 = New System.ServiceProcess.ServiceProcessInstaller() + Me.ServiceInstaller1 = New System.ServiceProcess.ServiceInstaller() + ' + 'ServiceProcessInstaller1 + ' + Me.ServiceProcessInstaller1.Account = ServiceProcess.ServiceAccount.LocalSystem + Me.ServiceProcessInstaller1.Password = Nothing + Me.ServiceProcessInstaller1.Username = Nothing + ' + 'ServiceInstaller1 + ' + Me.ServiceInstaller1.Description = "Recycling of Application Pools in IIS" + Me.ServiceInstaller1.DisplayName = "AppPoolRecycler" + Me.ServiceInstaller1.ServiceName = "AppPoolRecycler" + Me.ServiceInstaller1.StartType = ServiceProcess.ServiceStartMode.Automatic + ' + 'ProjectInstaller + ' + Me.Installers.AddRange(New System.Configuration.Install.Installer() {Me.ServiceProcessInstaller1, Me.ServiceInstaller1}) + + End Sub + Friend WithEvents ServiceProcessInstaller1 As System.ServiceProcess.ServiceProcessInstaller + Friend WithEvents ServiceInstaller1 As System.ServiceProcess.ServiceInstaller + +End Class diff --git a/AppPoolRecycler/ProjectInstaller.resx b/AppPoolRecycler/ProjectInstaller.resx new file mode 100644 index 0000000..f8a01d0 --- /dev/null +++ b/AppPoolRecycler/ProjectInstaller.resx @@ -0,0 +1,129 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + + 188, 17 + + + False + + \ No newline at end of file diff --git a/AppPoolRecycler/ProjectInstaller.vb b/AppPoolRecycler/ProjectInstaller.vb new file mode 100644 index 0000000..f06aca7 --- /dev/null +++ b/AppPoolRecycler/ProjectInstaller.vb @@ -0,0 +1,16 @@ +Imports System.ComponentModel +Imports System.Configuration.Install + +Public Class ProjectInstaller + + Public Sub New() + MyBase.New() + + 'This call is required by the Component Designer. + InitializeComponent() + + 'Add initialization code after the call to InitializeComponent + + End Sub + +End Class diff --git a/AppPoolRecycler/Readme.txt b/AppPoolRecycler/Readme.txt new file mode 100644 index 0000000..ec56fb8 --- /dev/null +++ b/AppPoolRecycler/Readme.txt @@ -0,0 +1,5 @@ +Install: +C:\Windows\Microsoft.NET\Framework64\v4.0.30319>InstallUtil.exe "C:\Users\u15020\Documents\Visual Studio 2013\Projects\AppPoolRecycler\AppPoolRecycler\bin\Release\AppPoolRecycler.exe" + +Uninstall +C:\Windows\Microsoft.NET\Framework64\v4.0.30319>InstallUtil.exe -u "C:\Users\u15020\Documents\Visual Studio 2013\Projects\AppPoolRecycler\AppPoolRecycler\bin\Release\AppPoolRecycler.exe" \ No newline at end of file diff --git a/AppPoolRecycler/install.cmd b/AppPoolRecycler/install.cmd new file mode 100644 index 0000000..9ae59ea --- /dev/null +++ b/AppPoolRecycler/install.cmd @@ -0,0 +1,18 @@ + +@echo off +cls +whoami /groups | findstr /b BUILTIN\Administrators | findstr /c:"Enabled group" +IF %ERRORLEVEL% EQU 0 ( + ECHO you are Administrator +) ELSE ( + ECHO you are NOT Administrator. Exiting... + + pause + EXIT /B 1 +) + + +for /f "tokens=*" %%f in ('dir /s/b/on %windir%\Microsoft.net\Framework64\installutil.exe') do set lastLine=%%f +%lastLine% AppPoolRecycler.exe + +pause \ No newline at end of file diff --git a/AppPoolRecycler/uninistall.cmd b/AppPoolRecycler/uninistall.cmd new file mode 100644 index 0000000..6527b48 --- /dev/null +++ b/AppPoolRecycler/uninistall.cmd @@ -0,0 +1,17 @@ + +@echo off +cls +whoami /groups | findstr /b BUILTIN\Administrators | findstr /c:"Enabled group" +IF %ERRORLEVEL% EQU 0 ( + ECHO you are Administrator +) ELSE ( + ECHO you are NOT Administrator. Exiting... + + pause + EXIT /B 1 +) + +for /f "tokens=*" %%f in ('dir /s/b/on %windir%\Microsoft.net\Framework64\installutil.exe') do set lastLine=%%f +%lastLine% -u AppPoolRecycler.exe + +pause \ No newline at end of file diff --git a/CasAppPoolRecycleService.suo b/CasAppPoolRecycleService.suo new file mode 100644 index 0000000..bfa059c Binary files /dev/null and b/CasAppPoolRecycleService.suo differ diff --git a/CasAppPoolRecycleService.v12.suo b/CasAppPoolRecycleService.v12.suo new file mode 100644 index 0000000..598701d Binary files /dev/null and b/CasAppPoolRecycleService.v12.suo differ diff --git a/MyAppPoolRecycleService.v12.suo b/MyAppPoolRecycleService.v12.suo new file mode 100644 index 0000000..d2c2fca Binary files /dev/null and b/MyAppPoolRecycleService.v12.suo differ