Skip to content

Instantly share code, notes, and snippets.

@jhorsman
Created December 18, 2018 14:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jhorsman/230e874acd57284c895c4a8c0a9b827c to your computer and use it in GitHub Desktop.
Save jhorsman/230e874acd57284c895c4a8c0a9b827c to your computer and use it in GitHub Desktop.
Script to restart SDL Tridion Docs content manager services. This covers the Windows services, component service and IIS application pools. Something similar can be done with the ISHDeploy module from https://github.com/sdl/ISHDeploy.
<#
.SYNOPSIS
Restarts Docs Content Manager services
.EXAMPLE
Restart-Docs
Restart-Docs -WindowsServices
Restart-Docs -ComponentServices
Restart-Docs -ApplicationPools
Restart-Docs -ComponentServices -ApplicationPools
.NOTES
Author: Jan Horsman
#>
#Requires -RunAsAdministrator
[CmdletBinding()]
Param(
[parameter(Mandatory=$false, HelpMessage="Restart Windows services")]
[switch]$WindowsServices,
[parameter(Mandatory=$false, HelpMessage="Restart component services")]
[switch]$ComponentServices,
[parameter(Mandatory=$false, HelpMessage="Restart IIS application pools")]
[switch]$ApplicationPools)
$ErrorActionPreference = "Stop"
if($WindowsServices -ne $true -and $ComponentServices -ne $true -and $ApplicationPools -ne $true)
{
#default to restarting everything
$WindowsServices = $true
$ComponentServices = $true
$ApplicationPools = $true
}
if($WindowsServices)
{
Write-Host "Restarting Trisoft services"
$services = Get-Service | Where { $_.DisplayName.StartsWith("Trisoft") }
if($services -eq $null)
{
Write-Warning "Could not find Trisoft services"
} else
{
foreach ($svc in $services)
{
if($svc.Status -eq "Running")
{
Write-Host (" restarting {0} " -f $svc.DisplayName)
Restart-Service $svc.name -Force
} else {
Write-Host (" ignoring {0}, it is {1}" -f $svc.DisplayName, $svc.Status)
}
}
}
}
if($ComponentServices)
{
Write-Host "Restarting component services"
$comAdmin = New-Object -comobject COMAdmin.COMAdminCatalog
$apps = $comAdmin.GetCollection("Applications")
$apps.Populate();
# restart only Trisoft-InfoShare-Author because the other component services are libraries
$apps = $apps | Where-Object { $_.Name.Equals("Trisoft-InfoShare-Author") }
if($apps -eq $null)
{
Write-Warning "Could not find Trisoft-InfoShare-Author component service"
} else
{
foreach ($app in $apps)
{
$comAdmin.ShutdownApplication($app.Name)
Write-Host " Stoped " $app.Name
$comAdmin.StartApplication($app.Name)
Write-Host " Started" $app.Name
}
}
}
if($ApplicationPools)
{
Write-Host "Restarting application pools"
Import-Module "IISAdministration"
$appPools = Get-IISAppPool | Where-Object { $_.Name.StartsWith("Trisoft") }
if($appPools -eq $null) {
Write-Warning "Could not find Trisoft app pools"
} else
{
foreach ($pool in $appPools)
{
if($pool.State -ne "Started")
{
Write-Host " ignoring "$pool.Name", it is"$pool.Status
} else {
$result = $pool.Recycle()
Restart-WebAppPool $pool.Name
if($result -eq "Started")
{
Write-Host " Recycled " $pool.Name
} else
{
Write-Warning ("Unexpected result while recycling app pool {0}: {1}" -f $pool.Name, $result)
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment