-
Notifications
You must be signed in to change notification settings - Fork 1
/
InstallPublishingService.ps1
187 lines (152 loc) · 7.02 KB
/
InstallPublishingService.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
param(
[switch] $UpdateSchemasOnly,
[switch] $Uninstall,
[string] $Prefix = "sc10",
[string] $Version = "10.4.0"
)
. $PSScriptRoot\parameters.ps1
$ErrorActionPreference = 'Stop'
$ConnectionStringTemplate = "user id=$($SqlServer.SqlAdminUser);password=$($SqlServer.SqlAdminPassword);data source=$($SqlServer.Address);database={0};MultipleActiveResultSets=True;"
Function Copy-PublishingServiceContent {
Write-Host "Start Extracting Publishing Service Package....." -ForegroundColor Green
If (!(Test-Path -Path $PublishingServiceConfig.PackagePath )) {
throw "Make sure the Publishing Service package exist at $($PublishingServiceConfig.PackagePath)"
}
If (!(Test-Path -Path $PublishingServiceConfig.ContentPath)) {
New-Item -Path $PublishingServiceConfig.ContentPath -ItemType Directory -Force
}
Expand-Archive -Path $PublishingServiceConfig.PackagePath -DestinationPath $PublishingServiceConfig.ContentPath
Write-Host "Extracted Publishing Service Package content to $($PublishingServiceConfig.ContentPath)....." -ForegroundColor Green
}
Function Copy-SitecoreLicense {
Write-Host "Copying Sitecore License....." -ForegroundColor Green
If (!(Test-Path -Path $PublishingServiceConfig.SitecoreLicensePath )) {
throw "Please copy a valid Sitecore license to the SitecorePackages folder"
}
$SitecoreRuntimePath = Join-Path -Path $PublishingServiceConfig.ContentPath -ChildPath "sitecoreruntime"
If (!(Test-Path -Path $SitecoreRuntimePath)) {
New-Item -Path $SitecoreRuntimePath -ItemType Directory -Force
Write-Host "Created sitecoreruntime folder at $($SitecoreRuntimePath)....." -ForegroundColor Green
}
Copy-Item -Path $PublishingServiceConfig.SitecoreLicensePath -Destination $SitecoreRuntimePath
Write-Host "Copied Sitecore license file to $($SitecoreRuntimePath)....." -ForegroundColor Green
}
Function Get-PublishingHostTool {
If (!(Test-Path($PublishingServiceConfig.ContentPath))) {
throw "Could not find the instance of Publishing Service"
}
Set-Location -Path $PublishingServiceConfig.ContentPath
return (Get-Command ".\Sitecore.Framework.Publishing.Host.exe")
}
Function Update-ConnectionString ([string] $DatabaseName) {
Write-Host "Updating connectionstring for $($DatabaseName)" -ForegroundColor Green
$ActualDatabaseName = "$($Prefix)_$($DatabaseName)"
$ConnectionStringForDatabase = ($ConnectionStringTemplate -f $ActualDatabaseName)
& $ExeFile configuration setconnectionstring "$($DatabaseName)" "$($ConnectionStringForDatabase)"
}
Function Update-InstanceName {
& $ExeFile configuration set Sitecore:Publishing:InstanceName -v $SitecoreContentManagementSitename
}
Function Update-Schemas {
& $ExeFile schema upgrade --force
}
Function New-PublishingServiceSite {
& $ExeFile iis install -s "$($PublishingServiceInstance)" -a "$($PublishingServiceInstance)" -p $PublishingServicePort --force
}
Function Update-HostsFile {
$HostsFile = "$($env:windir)\system32\Drivers\etc\hosts"
$Content = Get-Content -Path $HostsFile
$HostsFileRecord = "127.0.0.1 $($PublishingServiceInstance)"
If (-not ($Content -contains "$HostsFileRecord")) {
$HostsFileRecord | Add-Content -PassThru $HostsFile
}
}
Function Invoke-CheckPublishingService {
$PublishingServiceStatusRequest = [System.Net.WebRequest]::Create($PublishingServiceConfig.CheckStatusUrl)
$PublishingServiceStatusResponse = $PublishingServiceStatusRequest.GetResponse();
try {
if ($PublishingServiceStatusResponse.StatusCode -ne 200) {
Write-Host "Could not contact Publishing Service on '$($PublishingServiceConfig.CheckStatusUrl)'. Response status was '$PublishingServiceStatusResponse.StatusCode'" -ForegroundColor Red
}
else {
$reqstream = $PublishingServiceStatusResponse.GetResponseStream()
$sr = new-object System.IO.StreamReader $reqstream
$result = $sr.ReadToEnd()
If ($result -eq '{"status":0}') {
Write-Host "Install $($PublishingServiceInstance) successfully" -ForegroundColor Green
Write-Host "Go to $($PublishingServiceConfig.CheckStatusUrl) to check the status, {'status':0} means the install was successful" -ForegroundColor Green
}
}
}
finally {
$PublishingServiceStatusResponse.Close()
}
}
function Remove-IISSite($name) {
# Delete site
if (Get-Website $name) {
Remove-Website $name
Write-Host "IIS site $name is uninstalled" -ForegroundColor Green
}
else {
Write-Host "Could not find IIS site $name" -ForegroundColor Yellow
}
# Delete app pool
if (Get-IISAppPool $name) {
Remove-WebAppPool $name
Write-Host "IIS App Pool $name is uninstalled" -ForegroundColor Green
}
else {
Write-Host "Could not find IIS App Pool $name" -ForegroundColor Yellow
}
}
function Remove-IISFiles($path) {
# Delete site
if (Test-Path($path)) {
Remove-Item $path -Recurse -Force
Write-Host "Removing files $path" -ForegroundColor Green
}
else {
Write-Host "Could not find files $path" -ForegroundColor Yellow
}
}
################################### EXECUTION ###############################################################
Push-Location $PSScriptRoot
If (-Not $Uninstall) {
If ($UpdateSchemasOnly) {
$ExeFile = Get-PublishingHostTool
Update-Schemas
}
Else {
Write-Host "*******************************************************" -ForegroundColor Yellow
Write-Host " Installing Publishing Service for: $($SitecoreContentManagementSitename)" -ForegroundColor Green
Write-Host " Instance: $($PublishingServiceInstance):$($PublishingServicePort)" -ForegroundColor Green
Write-Host "*******************************************************" -ForegroundColor Yellow
Copy-PublishingServiceContent
if ($Version -eq "10.2.0" -or $Version -eq "10.3.0" -or $Version -eq "10.4.0") {
# The publishing service now uses a license file with the start of 10.2
Copy-SitecoreLicense
}
$ExeFile = Get-PublishingHostTool
Update-ConnectionString -DatabaseName "core"
Update-ConnectionString -DatabaseName "master"
Update-ConnectionString -DatabaseName "web"
Update-InstanceName
Update-Schemas
New-PublishingServiceSite
Update-HostsFile
Invoke-CheckPublishingService
}
}
Else {
Write-Host "*******************************************************" -ForegroundColor Yellow
Write-Host " Uninstalling Publishing Service: $($PublishingServiceInstance):$($PublishingServicePort)" -ForegroundColor Green
Write-Host "*******************************************************" -ForegroundColor Yellow
Import-Module WebAdministration
IISRESET /STOP
Remove-IISSite $PublishingServiceInstance
Remove-IISFiles $PublishingServiceConfig.ContentPath
IISRESET /START
Start-Sleep 10
}
Pop-Location