AEM Dispatcher Installation Automation


SYNOPSIS:
Following script will create dispatcher folder and will assign appropriate permissions. Then it will create docroot, logs and scripts folders inside dispatcher folder. Scripts copies the necessary files for dispatcher and also populates the scripts with dynamic variables. Later, checks if required IIS AppPool is present, if not terminates the website creation and the script too. Finally, does the house keeping as well by cleaning up any temporary files created during script execution.
Script is IDEMPOTENT.
ASSUMPTIONS:
- web.config file with necessary modifications is present at BASEPATH
- dispatcher.any file with necessary modifications is present at BASEPATH
- disp_iss.dll file with necessary modifications is present at BASEPATH
- disp_iss.ini file with necessary modifications is present at BASEPATH
[main]
configpath=${DISPSCRIPTS}\dispatcher.any
loglevel=3
servervariables=1
logfile=${DISPLOGS}\dispatcher.%Y-%m-%d-%H_%M_%S.log
rotate=5M

# Variables Declaration
param(
[String][parameter(Mandatory=$False,ValueFromPipeline=$False)]$BASEPATH="C:\Users\SKYDEVOPS\AEM\zinstaller",
[String][parameter(Mandatory=$False,ValueFromPipeline=$False)]$DISPATCHER="C:\dispatcher2",
[String][parameter(Mandatory=$False,ValueFromPipeline=$False)]$DOCROOT="$DISPATCHER" + "\docroot",
[String][parameter(Mandatory=$False,ValueFromPipeline=$False)]$DISPLOGS="$DISPATCHER" + "\logs",
[String][parameter(Mandatory=$False,ValueFromPipeline=$False)]$DISPSCRIPTS="$DISPATCHER" + "\scripts",
[String][parameter(Mandatory=$False,ValueFromPipeline=$False)]$TEMPFILE="$BASEPATH" + "\tempfile",
[String][parameter(Mandatory=$False,ValueFromPipeline=$False)]$DOCROOTMOD=$DOCROOT.replace("\","/"),
[String][parameter(Mandatory=$False,ValueFromPipeline=$False)]$CQ_HOST="127.0.0.1",
[int][parameter(Mandatory=$False,ValueFromPipeline=$False)]$CQ_PORT=4503,
[String][parameter(Mandatory=$False,ValueFromPipeline=$False)]$myWebSiteName="CQ_Dispatcher",
[String][parameter(Mandatory=$False,ValueFromPipeline=$False)]$myWebSitePoolName="DefaultAppPool",
[int][parameter(Mandatory=$False,ValueFromPipeline=$False)]$myWebSitePort=80,
[String][parameter(Mandatory=$False,ValueFromPipeline=$False)]$myWebSiteProtocol="http",
[String][parameter(Mandatory=$False,ValueFromPipeline=$False)]$myWebSiteIP="*",
[String][parameter(Mandatory=$False,ValueFromPipeline=$False)]$myWebSitePath="$DOCROOT"
)
$ErrorActionPreference = 'Stop'
$WarningPreference = 'SilentlyContinue'
# Create Folders if it doesnt Exist
# DISPATCHER Folder
if (!(Test-PATH -Path $DISPATCHER)) {
Write-Host -ForegroundColor Red "`n$DISPATCHER Path Not-Found"
Write-Output "Creating $DISPATCHER"
$null = New-Item -ItemType directory -Path "$DISPATCHER"
$acl = Get-Acl -Path $DISPATCHER
# add a new permission (FullControl, Modify, Read)
$permission = 'IIS AppPool\DefaultAppPool', 'FullControl', 'ContainerInherit, ObjectInherit', 'None', 'Allow'
$rule = New-Object -TypeName System.Security.AccessControl.FileSystemAccessRule -ArgumentList $permission
$acl.SetAccessRule($rule)
$acl | Set-Acl $DISPATCHER
}else {
Write-Host -ForegroundColor Green "`n$DISPATCHER Path Found"
$acl = Get-Acl -Path $DISPATCHER
# add a new permission (FullControl, Modify, Read)
$permission = 'IIS AppPool\DefaultAppPool', 'FullControl', 'ContainerInherit, ObjectInherit', 'None', 'Allow'
$rule = New-Object -TypeName System.Security.AccessControl.FileSystemAccessRule -ArgumentList $permission
$acl.SetAccessRule($rule)
$acl | Set-Acl $DISPATCHER
}
# DISPATCHER DOCROOT Folder
if (!(Test-PATH -Path $DOCROOT)) {
Write-Host -ForegroundColor Red "`n$DOCROOT Path Not-Found"
Write-Output "Creating $DOCROOT"
$null = New-Item -ItemType directory -Path "$DOCROOT"
# Copy WEBCONFIG
Copy-Item -Path $BASEPATH\IIS\web.config -Destination $TEMPFILE
$ImportWCONF = Get-Content $TEMPFILE -Raw
$ExecutionContext.InvokeCommand.ExpandString($ImportWCONF) | Set-Content $TEMPFILE
Copy-Item -Path $TEMPFILE -Destination $DOCROOT\
Rename-Item -Path "$DOCROOT\tempfile" -NewName "$DOCROOT\web.config"
Copy-Item -Path $BASEPATH\IIS\rewritemaps.config -Destination $DOCROOT\
}else {
Write-Host -ForegroundColor Green "`n$DOCROOT Path Found"
if (!(Test-PATH -Path $DISPSCRIPTS\rewritemaps.config)) {
Copy-Item -Path $BASEPATH\IIS\rewritemaps.config -Destination $DOCROOT\
}
if (!(Test-PATH -Path $DISPSCRIPTS\web.config)) {
Copy-Item -Path $BASEPATH\IIS\web.config -Destination $TEMPFILE
$ImportWCONF = Get-Content $TEMPFILE -Raw
$ExecutionContext.InvokeCommand.ExpandString($ImportWCONF) | Set-Content $TEMPFILE
Copy-Item -Path $TEMPFILE -Destination $DOCROOT\
Rename-Item -Path "$DOCROOT\tempfile" -NewName "$DOCROOT\web.config"
}
}
# DISPATCHER Logs Folder
if (!(Test-PATH -Path $DISPLOGS)) {
Write-Host -ForegroundColor Red "`n$DISPLOGS Path Not-Found"
Write-Output "Creating $DISPLOGS"
$null = New-Item -ItemType directory -Path "$DISPLOGS"
}else {
Write-Host -ForegroundColor Green "`n$DISPLOGS Path Found"
}
# DISPATCHER scripts Folder
if (!(Test-PATH -Path $DISPSCRIPTS)) {
Write-Host -ForegroundColor Red "`n$DISPSCRIPTS Path Not-Found"
Write-Output "Creating $DISPSCRIPTS"
$null = New-Item -ItemType directory -Path "$DISPSCRIPTS"
# Copy INI file
Copy-Item -Path $BASEPATH\IIS\disp_iis.ini -Destination $TEMPFILE
$ImportINI = Get-Content $TEMPFILE -Raw
$ExecutionContext.InvokeCommand.ExpandString($ImportINI) | Set-Content $TEMPFILE
Copy-Item -Path $TEMPFILE -Destination $DISPSCRIPTS\
Rename-Item -Path "$DISPSCRIPTS\tempfile" -NewName "$DISPSCRIPTS\disp_iis.ini"
# Copy DLL
Copy-Item -Path $BASEPATH\IIS\disp_iis.dll -Destination $DISPSCRIPTS\
# Copy dispatcher.any
Copy-Item -Path $BASEPATH\IIS\dispatcher.any -Destination $TEMPFILE
$ImportANY = Get-Content $TEMPFILE -Raw
$ExecutionContext.InvokeCommand.ExpandString($ImportANY) | Set-Content $TEMPFILE
Copy-Item -Path $TEMPFILE -Destination $DISPSCRIPTS\
Rename-Item -Path "$DISPSCRIPTS\tempfile" -NewName "$DISPSCRIPTS\dispatcher.any"
# Copy WEBCONFIG
Copy-Item -Path $BASEPATH\IIS\web.config -Destination $DISPSCRIPTS\
}else {
Write-Host -ForegroundColor Green "`n$DISPSCRIPTS Path Found"
if (!(Test-PATH -Path $DISPSCRIPTS\disp_iis.ini)) {
Copy-Item -Path $BASEPATH\IIS\disp_iis.ini -Destination $TEMPFILE
$ImportINI = Get-Content $TEMPFILE -Raw
$ExecutionContext.InvokeCommand.ExpandString($ImportINI) | Set-Content $TEMPFILE
Copy-Item -Path $TEMPFILE -Destination $DISPSCRIPTS\
Rename-Item -Path "$DISPSCRIPTS\tempfile" -NewName "$DISPSCRIPTS\disp_iis.ini"
}
if (!(Test-PATH -Path $DISPSCRIPTS\disp_iis.dll)) {
Copy-Item -Path $BASEPATH\IIS\disp_iis.dll -Destination $DISPSCRIPTS\
}
if (!(Test-PATH -Path $DISPSCRIPTS\dispatcher.any)) {
Copy-Item -Path $BASEPATH\IIS\dispatcher.any -Destination $TEMPFILE
$ImportANY = Get-Content $TEMPFILE -Raw
$ExecutionContext.InvokeCommand.ExpandString($ImportANY) | Set-Content $TEMPFILE
Copy-Item -Path $TEMPFILE -Destination $DISPSCRIPTS\
Rename-Item -Path "$DISPSCRIPTS\tempfile" -NewName "$DISPSCRIPTS\dispatcher.any"
}
if (!(Test-PATH -Path $DISPSCRIPTS\web.config)) {
Copy-Item -Path $BASEPATH\IIS\web.config -Destination $DISPSCRIPTS\
}
}
# IIS DefaultAppPool
Write-Host -ForegroundColor Yellow "`nChecking IIS APP POOLS"
$SKYARRAY = @()
$APPPOOLS = 'DefaultAppPool'
foreach ($APPPOOL in $APPPOOLS) {
$MyPool = (get-IISAppPool) | where-object {$_.Name -eq "$APPPOOL"}
$SKYARRAY += New-Object psobject -Property @{
Name = $APPPOOL
Status = if (!($MyPool.State)) {Write-Output "NA"}else {Write-Output $MyPool.State}
Exist = if (!($MyPool)) {Write-Output "Not-Found"}else {Write-Output "Found"}
}
}
$SKYARRAY | format-table -Property Name, Exist, Status
if ($SKYARRAY[0].Name -eq "$myWebSitePoolName") {
Write-Output "$myWebSitePoolName Found"
# Create Website
Import-Module "WebAdministration"
if ($(Get-Website | Where-Object { $_.Name -eq "$myWebSiteName" }) -eq $null) {
Write-Host "WebSite $myWebSiteName Not-Found"
Write-Host -ForegroundColor Green "Creating WebSite $myWebSiteName"
New-WebSite -Name $myWebSiteName -IPAddress $myWebSiteIP -Port $myWebSitePort -PhysicalPath $myWebSitePath -ApplicationPool $myWebSitePoolName
# Remove temporary files
if (Test-PATH $TEMPFILE) {
Remove-Item -Path $TEMPFILE
}
Write-Host -ForegroundColor Green "Done."
}else {
Write-Host "WebSite $myWebSiteName Found"
$DELCONFIRM = Read-Host "Do you want to Delete and Re-Create WebSite $myWebSiteName [y/n]:"
if ($DELCONFIRM -eq "y" -or $DELCONFIRM -eq "Y" -or $DELCONFIRM -eq "yes") {
Remove-WebSite -Name $myWebSiteName
Write-Host -ForegroundColor Green "Creating Website $myWebSiteName"
New-WebSite -Name $myWebSiteName -IPAddress $myWebSiteIP -Port $myWebSitePort -PhysicalPath $myWebSitePath -ApplicationPool $myWebSitePoolName
}else {
Write-Host -ForegroundColor Red "WebSite $myWebSiteName Not Deleted"
if (Test-PATH $TEMPFILE) {
Remove-Item -Path $TEMPFILE
}
Write-Host -ForegroundColor Green "Script Execution Done."
Exit
}
}
}else {
Write-Host -ForegroundColor Red "$myWebSitePoolName Not-Found, Terminating Website Creation"
Exit
}
To get Help and check the available parameters use the following Command
Get-Help .\aem_iss.ps1 -Full
Following is the output in a Text Format
NAME C:\Users\SKYDEVOPS\Documents\scripts\IIS\aem_iis.ps1 SYNOPSIS This script installs and configures AEM Dispatcher on IIS, using golden config files. SYNTAX C:\Users\SKYDEVOPS\Documents\scripts\IIS\aem_iis.ps1 [[-BASEPATH] ] [[-DISPATCHER] ] [[-DOCROOT] ] [[-DISPLOGS] ] [[-DISPSCRIPTS] ] [[-TEMPFILE] ] [[-DOCROOTMOD] ] [[-CQ_HOST] ] [[-CQ_PORT] ] [[-myWebSiteName] ] [[-myWebSitePoolName] ] [[-myWebSitePort] ] [[-myWebSiteProtocol] ] [[-myWebSiteIP] ] [[-myWebSitePath] ] [] DESCRIPTION Installs AEM Dispatcher on windows Features: 1. Checks for dispatcher folder, if not present it will create dispatcher folder 1.1. Adds DefaultAppPool user 1.2. Adds permissions to dispathcer folder 2. Checks for docroot folder, if not present creates it 2.1. Copies rewritemaps.config file 2.2. Copies and Modifies web.config file and dynamically adds ScriptProcessor PATH 3. Checks if logs folder is present, if not creates 4. Checks for scripts folder, if not present creates it 4.1. Copies DLL file 4.2. Copies disp_iis.ini and dynamically populates configpath, logfile 4.3. Copies dispatcher.any and dynamically populates hostname, port, and docroot 4.4. Copies rewritemaps.config file 4.5. Copies and Modifies web.config file and dynamically adds ScriptProcessor PATH 5. Checks if DefaultAppPool exists 6. Create WebSite PARAMETERS -BASEPATH PATH where all the required files and golden configs are available Required? false Position? 1 Default value C:\Users\SKYDEVOPS\AEM\zinstaller Accept pipeline input? false Accept wildcard characters? false -DISPATCHER PATH where dispatcher will be created Required? false Position? 2 Default value C:\dispatcher2 Accept pipeline input? false Accept wildcard characters? false -DOCROOT PATH for the docroot Required? false Position? 3 Default value "$DISPATCHER" + "\docroot" Accept pipeline input? false Accept wildcard characters? false -DISPLOGS PATH for dispatcher logs Required? false Position? 4 Default value "$DISPATCHER" + "\logs" Accept pipeline input? false Accept wildcard characters? false -DISPSCRIPTS PATH for dispatcher scripts folder Required? false Position? 5 Default value "$DISPATCHER" + "\scripts" Accept pipeline input? false Accept wildcard characters? false -TEMPFILE Temporary file for modifying and populating dynamic variables on the fly Required? false Position? 6 Default value "$BASEPATH" + "\tempfile" Accept pipeline input? false Accept wildcard characters? false -DOCROOTMOD Temporary parameter for modifying the path of docroot Required? false Position? 7 Default value $DOCROOT.replace("\","/") Accept pipeline input? false Accept wildcard characters? false -CQ_HOST Hostname of the AEM Publish instance Required? false Position? 8 Default value 127.0.0.1 Accept pipeline input? false Accept wildcard characters? false -CQ_PORT Port on which AEM publish instance is running Required? false Position? 9 Default value 4503 Accept pipeline input? false Accept wildcard characters? false -myWebSiteName Name of the WebSite on IIS Required? false Position? 10 Default value CQ_Dispatcher Accept pipeline input? false Accept wildcard characters? false -myWebSitePoolName Name of the AppPool under which the website is created Required? false Position? 11 Default value DefaultAppPool Accept pipeline input? false Accept wildcard characters? false -myWebSitePort Port on which the website will be running Required? false Position? 12 Default value 80 Accept pipeline input? false Accept wildcard characters? false -myWebSiteProtocol Protocol on which the website will be running Ex: http,https Required? false Position? 13 Default value http Accept pipeline input? false Accept wildcard characters? false -myWebSiteIP IP address of the website Required? false Position? 14 Default value * Accept pipeline input? false Accept wildcard characters? false -myWebSitePath Physical path of the website files, Here, its Dispatcher Docroot Required? false Position? 15 Default value "$DOCROOT" Accept pipeline input? false Accept wildcard characters? false This cmdlet supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction, WarningVariable, OutBuffer, PipelineVariable, and OutVariable. For more information, see about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216). INPUTS NONE OUTPUTS Only Console Output NOTES Author: Shashi yebbare (syebbare@skydevops.in) Company: Skydevops Pvt. Ltd. (www.skydevops.co.in) Version: 2.0.0 -------------------------- EXAMPLE 1 -------------------------- PS c:\> .\aem_iis.ps1 RELATED LINKS https://docs.microsoft.com/en-us/iis/configuration/system.webServer/handlers/add#005 https://social.technet.microsoft.com/wiki/contents/articles/15994.powershell-advanced-function-parameter-attributes.aspx https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_comment_based_help?view=powershell-6
Categories