scheme3 & scheme5
Change-Id: I6a0e35de84d7d4af234761330af21b573bb24e43
This commit is contained in:
11
data3/demo_init.sh
Normal file
11
data3/demo_init.sh
Normal file
@@ -0,0 +1,11 @@
|
||||
#!/bin/sh
|
||||
|
||||
AgentConfigBase64='%AGENT_CONFIG_BASE64%'
|
||||
|
||||
mkdir /etc/murano
|
||||
|
||||
echo $AgentConfigBase64 | base64 -d > /etc/murano/agent.config
|
||||
|
||||
chmod 664 /etc/murano/agent.config
|
||||
sleep 10
|
||||
reboot
|
||||
68
data3/init.ps1
Normal file
68
data3/init.ps1
Normal file
@@ -0,0 +1,68 @@
|
||||
#ps1
|
||||
|
||||
$WindowsAgentConfigBase64 = '%AGENT_CONFIG_BASE64%'
|
||||
$WindowsAgentConfigFile = "C:\Murano\Agent\WindowsAgent.exe.config"
|
||||
$WindowsAgentLogFile = "C:\Murano\Agent\log.txt"
|
||||
|
||||
$NewComputerName = '%INTERNAL_HOSTNAME%'
|
||||
$MuranoFileShare = '\\%MURANO_SERVER_ADDRESS%\share'
|
||||
|
||||
$CaRootCertBase64 = "%CA_ROOT_CERT_BASE64%"
|
||||
$CaRootCertFile = "C:\Murano\ca.cert"
|
||||
|
||||
$RestartRequired = $false
|
||||
|
||||
Import-Module CoreFunctions
|
||||
Initialize-Logger 'CloudBase-Init' 'C:\Murano\PowerShell.log'
|
||||
|
||||
$ErrorActionPreference = 'Stop'
|
||||
|
||||
trap {
|
||||
Write-LogError '<exception>'
|
||||
Write-LogError $_ -EntireObject
|
||||
Write-LogError '</exception>'
|
||||
exit 1
|
||||
}
|
||||
|
||||
Write-Log "Importing CA certificate ..."
|
||||
if ($CaRootCertBase64 -eq '') {
|
||||
Write-Log "Importing CA certificate ... skipped"
|
||||
}
|
||||
else {
|
||||
ConvertFrom-Base64String -Base64String $CaRootCertBase64 -Path $CaRootCertFile
|
||||
$cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2 $CaRootCertFile
|
||||
$store = New-Object System.Security.Cryptography.X509Certificates.X509Store("AuthRoot","LocalMachine")
|
||||
$store.Open("MaxAllowed")
|
||||
$store.Add($cert)
|
||||
$store.Close()
|
||||
Write-Log "Importing CA certificate ... done"
|
||||
}
|
||||
|
||||
Write-Log "Updating Murano Windows Agent."
|
||||
Stop-Service "Murano Agent"
|
||||
Backup-File $WindowsAgentConfigFile
|
||||
Remove-Item $WindowsAgentConfigFile -Force
|
||||
Remove-Item $WindowsAgentLogFile -Force
|
||||
ConvertFrom-Base64String -Base64String $WindowsAgentConfigBase64 -Path $WindowsAgentConfigFile
|
||||
Exec sc.exe 'config','"Murano Agent"','start=','delayed-auto'
|
||||
Write-Log "Service has been updated."
|
||||
|
||||
Write-Log "Adding environment variable 'MuranoFileShare' = '$MuranoFileShare' ..."
|
||||
[Environment]::SetEnvironmentVariable('MuranoFileShare', $MuranoFileShare, [EnvironmentVariableTarget]::Machine)
|
||||
Write-Log "Environment variable added."
|
||||
|
||||
Write-Log "Renaming computer to '$NewComputerName' ..."
|
||||
$null = Rename-Computer -NewName $NewComputerName -Force
|
||||
|
||||
Write-Log "New name assigned, restart required."
|
||||
$RestartRequired = $true
|
||||
|
||||
|
||||
Write-Log 'All done!'
|
||||
if ( $RestartRequired ) {
|
||||
Write-Log "Restarting computer ..."
|
||||
Restart-Computer -Force
|
||||
}
|
||||
else {
|
||||
Start-Service 'Murano Agent'
|
||||
}
|
||||
6
data3/linux_init.sh
Normal file
6
data3/linux_init.sh
Normal file
@@ -0,0 +1,6 @@
|
||||
#!/bin/sh
|
||||
|
||||
AgentConfigBase64='%AGENT_CONFIG_BASE64%'
|
||||
service murano-agent stop
|
||||
echo $AgentConfigBase64 | base64 -d > /etc/murano-agent.conf
|
||||
service murano-agent start
|
||||
36
data3/templates/agent-config/Default.template
Normal file
36
data3/templates/agent-config/Default.template
Normal file
@@ -0,0 +1,36 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<configuration>
|
||||
<configSections>
|
||||
<section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog"/>
|
||||
</configSections>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
|
||||
</startup>
|
||||
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<targets>
|
||||
<target name="file" xsi:type="File" fileName="${basedir}/log.txt"
|
||||
layout="${date} ${level}: <${logger:shortName=true}> ${message} ${exception:format=tostring}"/>
|
||||
</targets>
|
||||
|
||||
<rules>
|
||||
<logger name="*" minlevel="Debug" writeTo="file" />
|
||||
</rules>
|
||||
</nlog>
|
||||
<appSettings>
|
||||
<add key="rabbitmq.host" value="%RABBITMQ_HOST%"/>
|
||||
<add key="rabbitmq.port" value="%RABBITMQ_PORT%"/>
|
||||
<add key="rabbitmq.user" value="%RABBITMQ_USER%"/>
|
||||
<add key="rabbitmq.password" value="%RABBITMQ_PASSWORD%"/>
|
||||
<add key="rabbitmq.vhost" value="%RABBITMQ_VHOST%"/>
|
||||
<add key="rabbitmq.inputQueue" value="%RABBITMQ_INPUT_QUEUE%"/>
|
||||
<add key="rabbitmq.resultExchange" value=""/>
|
||||
<add key="rabbitmq.resultRoutingKey" value="%RESULT_QUEUE%"/>
|
||||
<add key="rabbitmq.durableMessages" value="true"/>
|
||||
|
||||
<add key="rabbitmq.ssl" value="%RABBITMQ_SSL%"/>
|
||||
<add key="rabbitmq.allowInvalidCA" value="true"/>
|
||||
<add key="rabbitmq.sslServerName" value=""/>
|
||||
|
||||
</appSettings>
|
||||
</configuration>
|
||||
8
data3/templates/agent-config/Demo.template
Normal file
8
data3/templates/agent-config/Demo.template
Normal file
@@ -0,0 +1,8 @@
|
||||
RABBITMQ_HOST = "%RABBITMQ_HOST%"
|
||||
RABBITMQ_PORT = "%RABBITMQ_PORT%"
|
||||
RABBITMQ_USERNAME = "%RABBITMQ_USER%"
|
||||
RABBITMQ_PASSWORD = "%RABBITMQ_PASSWORD%"
|
||||
RABBITMQ_VHOST = "%RABBITMQ_VHOST%"
|
||||
RABBITMQ_INPUT_QUEUE = "%RABBITMQ_INPUT_QUEUE%"
|
||||
RESULT_QUEUE = "%RESULT_QUEUE%"
|
||||
RABBITMQ_RESULT_ROUTING_KEY = "%RESULT_QUEUE%"
|
||||
35
data3/templates/agent-config/Linux.template
Normal file
35
data3/templates/agent-config/Linux.template
Normal file
@@ -0,0 +1,35 @@
|
||||
[DEFAULT]
|
||||
debug=True
|
||||
verbose=True
|
||||
log_file = /var/log/murano-agnet.log
|
||||
|
||||
storage=/var/murano/plans
|
||||
|
||||
[rabbitmq]
|
||||
|
||||
# Input queue name
|
||||
input_queue = %RABBITMQ_INPUT_QUEUE%
|
||||
|
||||
# Output routing key (usually queue name)
|
||||
result_routing_key = %RESULT_QUEUE%
|
||||
|
||||
# Connection parameters to RabbitMQ service
|
||||
|
||||
# Hostname or IP address where RabbitMQ is located.
|
||||
host = %RABBITMQ_HOST%
|
||||
|
||||
# RabbitMQ port (5672 is a default)
|
||||
port = %RABBITMQ_PORT%
|
||||
|
||||
# Use SSL for RabbitMQ connections (True or False)
|
||||
ssl = %RABBITMQ_SSL%
|
||||
|
||||
# Path to SSL CA certificate or empty to allow self signed server certificate
|
||||
ca_certs =
|
||||
|
||||
# RabbitMQ credentials. Fresh RabbitMQ installation has "guest" account with "guest" password.
|
||||
login = %RABBITMQ_USER%
|
||||
password = %RABBITMQ_PASSWORD%
|
||||
|
||||
# RabbitMQ virtual host (vhost). Fresh RabbitMQ installation has "/" vhost preconfigured.
|
||||
virtual_host = %RABBITMQ_VHOST%
|
||||
12
data3/templates/agent/AskDnsIp.template
Normal file
12
data3/templates/agent/AskDnsIp.template
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"Scripts": [
|
||||
"Get-DnsListeningIpAddress.ps1"
|
||||
],
|
||||
"Commands": [
|
||||
{
|
||||
"Name": "Get-DnsListeningIpAddress",
|
||||
"Arguments": {}
|
||||
}
|
||||
],
|
||||
"RebootOnCompletion": 0
|
||||
}
|
||||
16
data3/templates/agent/CreatePrimaryDC.template
Normal file
16
data3/templates/agent/CreatePrimaryDC.template
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"Scripts": [
|
||||
"ImportCoreFunctions.ps1",
|
||||
"Install-RolePrimaryDomainController.ps1"
|
||||
],
|
||||
"Commands": [
|
||||
{
|
||||
"Name": "Install-RolePrimaryDomainController",
|
||||
"Arguments": {
|
||||
"DomainName": "$domain",
|
||||
"SafeModePassword": "$recoveryPassword"
|
||||
}
|
||||
}
|
||||
],
|
||||
"RebootOnCompletion": 1
|
||||
}
|
||||
18
data3/templates/agent/CreateSecondaryDC.template
Normal file
18
data3/templates/agent/CreateSecondaryDC.template
Normal file
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"Scripts": [
|
||||
"ImportCoreFunctions.ps1",
|
||||
"Install-RoleSecondaryDomainController.ps1"
|
||||
],
|
||||
"Commands": [
|
||||
{
|
||||
"Name": "Install-RoleSecondaryDomainController",
|
||||
"Arguments": {
|
||||
"DomainName": "$domain",
|
||||
"UserName": "Administrator",
|
||||
"Password": "$domainPassword",
|
||||
"SafeModePassword": "$recoveryPassword"
|
||||
}
|
||||
}
|
||||
],
|
||||
"RebootOnCompletion": 1
|
||||
}
|
||||
7
data3/templates/agent/Demo.template
Normal file
7
data3/templates/agent/Demo.template
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"Scripts": [
|
||||
],
|
||||
"Commands": [
|
||||
],
|
||||
"RebootOnCompletion": 0
|
||||
}
|
||||
21
data3/templates/agent/DeployApache.template
Normal file
21
data3/templates/agent/DeployApache.template
Normal file
@@ -0,0 +1,21 @@
|
||||
FormatVersion: 2.0.0
|
||||
Version: 1.0.0
|
||||
Name: Deploy Apache
|
||||
|
||||
Parameters:
|
||||
enablePHP: $enablePHP
|
||||
|
||||
Body: |
|
||||
return apacheDeploy('{0}'.format(args.enablePHP)).stdout
|
||||
|
||||
Scripts:
|
||||
apacheDeploy:
|
||||
Type: Application
|
||||
Version: 1.0.0
|
||||
EntryPoint: Linux/runApacheDeploy.sh
|
||||
Files:
|
||||
- <Linux/installer.sh>
|
||||
- <Linux/common.sh>
|
||||
Options:
|
||||
captureStdout: true
|
||||
captureStderr: true
|
||||
23
data3/templates/agent/DeployTelnet.template
Normal file
23
data3/templates/agent/DeployTelnet.template
Normal file
@@ -0,0 +1,23 @@
|
||||
FormatVersion: 2.0.0
|
||||
Version: 1.0.0
|
||||
Name: Deploy Telnet
|
||||
|
||||
Parameters:
|
||||
appName: $appName
|
||||
|
||||
|
||||
Body: |
|
||||
return telnetDeploy(args.appName).stdout
|
||||
|
||||
Scripts:
|
||||
telnetDeploy:
|
||||
Type: Application
|
||||
Version: 1.0.0
|
||||
EntryPoint: Linux/runTelnetDeploy.sh
|
||||
Files:
|
||||
- <Linux/installer.sh>
|
||||
- <Linux/common.sh>
|
||||
Options:
|
||||
captureStdout: true
|
||||
captureStderr: false
|
||||
|
||||
15
data3/templates/agent/DeployWebApp.template
Normal file
15
data3/templates/agent/DeployWebApp.template
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"Scripts": [
|
||||
"ImportCoreFunctions.ps1",
|
||||
"DeployWebApp.ps1"
|
||||
],
|
||||
"Commands": [
|
||||
{
|
||||
"Name": "Deploy-WebAppFromGit",
|
||||
"Arguments": {
|
||||
"URL": "$repository"
|
||||
}
|
||||
}
|
||||
],
|
||||
"RebootOnCompletion": 0
|
||||
}
|
||||
22
data3/templates/agent/InstallIIS.template
Normal file
22
data3/templates/agent/InstallIIS.template
Normal file
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"Scripts": [
|
||||
"ImportCoreFunctions.ps1",
|
||||
"CopyPrerequisites.ps1",
|
||||
"InstallIIS.ps1"
|
||||
],
|
||||
"Commands": [
|
||||
{
|
||||
"Name": "Copy-Prerequisites",
|
||||
"Arguments": {
|
||||
"Destination": "C:\\Prerequisites"
|
||||
}
|
||||
},
|
||||
{
|
||||
"Name": "Install-WebServer",
|
||||
"Arguments": {
|
||||
"PrerequisitesPath": "C:\\Prerequisites"
|
||||
}
|
||||
}
|
||||
],
|
||||
"RebootOnCompletion": 0
|
||||
}
|
||||
24
data3/templates/agent/InstallMsSqlServer.template
Normal file
24
data3/templates/agent/InstallMsSqlServer.template
Normal file
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"Scripts": [
|
||||
"/ImportCoreFunctions.ps1",
|
||||
"/OptionParser.ps1",
|
||||
"SQLServer/SQLServerOptionParsers.ps1",
|
||||
"SQLServer/SQLServerInstaller.ps1",
|
||||
"SQLServer/Install-SQLServer.ps1",
|
||||
"/Alter-FirewallRulesForSQL.ps1"
|
||||
],
|
||||
"Commands": [
|
||||
{
|
||||
"Name": "Install-SQLServer",
|
||||
"Arguments": {
|
||||
"SAPassword": "$saPassword",
|
||||
"MixedModeAuth": "$mixedModeAuth"
|
||||
}
|
||||
},
|
||||
{
|
||||
"Name": "Enable-SQLExternalAccess",
|
||||
"Arguments": {}
|
||||
}
|
||||
],
|
||||
"RebootOnCompletion": 0
|
||||
}
|
||||
25
data3/templates/agent/JoinDomain.template
Normal file
25
data3/templates/agent/JoinDomain.template
Normal file
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"Scripts": [
|
||||
"ImportCoreFunctions.ps1",
|
||||
"Join-Domain.ps1"
|
||||
],
|
||||
"Commands": [
|
||||
{
|
||||
"Name": "Set-NetworkAdapterConfiguration",
|
||||
"Arguments": {
|
||||
"FirstAvailable": true,
|
||||
"DNSServer": "$dnsIp"
|
||||
}
|
||||
},
|
||||
{
|
||||
"Name": "Join-Domain",
|
||||
"Arguments": {
|
||||
"Username": "$domainUser",
|
||||
"Password": "$domainPassword",
|
||||
"DomainName": "$domain",
|
||||
"OUPath": "$ouPath"
|
||||
}
|
||||
}
|
||||
],
|
||||
"RebootOnCompletion": 1
|
||||
}
|
||||
5
data3/templates/agent/LeaveDomain.template
Normal file
5
data3/templates/agent/LeaveDomain.template
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"Scripts": [],
|
||||
"Commands": [],
|
||||
"RebootOnCompletion": 0,
|
||||
}
|
||||
17
data3/templates/agent/SetPassword.template
Normal file
17
data3/templates/agent/SetPassword.template
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"Scripts": [
|
||||
"ImportCoreFunctions.ps1",
|
||||
"Set-LocalUserPassword.ps1"
|
||||
],
|
||||
"Commands": [
|
||||
{
|
||||
"Name": "Set-LocalUserPassword",
|
||||
"Arguments": {
|
||||
"UserName": "Administrator",
|
||||
"Password": "$adminPassword",
|
||||
"Force": true
|
||||
}
|
||||
}
|
||||
],
|
||||
"RebootOnCompletion": 0
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"Scripts": [
|
||||
"/ImportCoreFunctions.ps1",
|
||||
"SQLServerForAOAG.ps1"
|
||||
],
|
||||
"Commands": [
|
||||
{
|
||||
"Name": "Enable-TrustedHosts",
|
||||
"Arguments": {}
|
||||
},
|
||||
{
|
||||
"Name": "New-SharedFolderForAOAG",
|
||||
"Arguments": {
|
||||
"PrimaryNode": "$primaryNode"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"Scripts": [
|
||||
"/ImportCoreFunctions.ps1",
|
||||
"/Start-PowerShellProcess.ps1",
|
||||
"/Failover-Cluster.ps1"
|
||||
],
|
||||
"Commands": [
|
||||
{
|
||||
"Name": "New-FailoverCluster",
|
||||
"Arguments": {
|
||||
"UserName": "$domainAdminAccountName",
|
||||
"ClusterNodes": "$clusterNodes",
|
||||
"DomainName": "$domainName",
|
||||
"ClusterName": "$clusterName",
|
||||
"UserPassword": "$domainAdminAccountPassword",
|
||||
"StaticAddress": "$clusterIp"
|
||||
}
|
||||
}
|
||||
],
|
||||
"RebootOnCompletion": 0
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"Scripts": [
|
||||
"/ImportCoreFunctions.ps1",
|
||||
"/Update-ServiceConfig.ps1",
|
||||
"SQLServerForAOAG.ps1",
|
||||
"/Failover-Cluster.ps1"
|
||||
],
|
||||
"Commands": [
|
||||
{
|
||||
"Name": "Install-FailoverClusterPrerequisites",
|
||||
"Arguments": {}
|
||||
},
|
||||
{
|
||||
"Name": "Enable-TrustedHosts",
|
||||
"Arguments": {}
|
||||
},
|
||||
{
|
||||
"Name": "Update-ServiceConfig",
|
||||
"Arguments": {
|
||||
"Password": "$domainAdminAccountPassword",
|
||||
"Name": "Murano Agent",
|
||||
"RunAsUser": "$domainAdminAccountName",
|
||||
"DomainName": "$domainName"
|
||||
}
|
||||
}
|
||||
],
|
||||
"RebootOnCompletion": 1
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"Scripts": [
|
||||
"/ImportCoreFunctions.ps1",
|
||||
"/OptionParser.ps1",
|
||||
"/SQLServer/SQLServerOptionParsers.ps1",
|
||||
"/SQLServer/SQLServerInstaller.ps1",
|
||||
"/Export-Function.ps1",
|
||||
"/Start-PowerShellProcess.ps1",
|
||||
"SQLServerForAOAG.ps1"
|
||||
],
|
||||
"Commands": [
|
||||
{
|
||||
"Name": "Initialize-AOAGPrimaryReplica",
|
||||
"Arguments": {
|
||||
"UserName": "$domainAdminAccountName",
|
||||
"NodeList": "$nodeList",
|
||||
"PrimaryNode": "$primaryNode",
|
||||
"DomainName": "$domainName",
|
||||
"UserPassword": "$domainAdminAccountPassword",
|
||||
"GroupName": "$groupName",
|
||||
"ListenerName": "$listenerName",
|
||||
"SyncModeNodeList": "$syncModeNodeList",
|
||||
"ListenerIP": "$listenerIP",
|
||||
"DatabaseList": "$databaseList"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"Scripts": [
|
||||
"/ImportCoreFunctions.ps1",
|
||||
"/OptionParser.ps1",
|
||||
"/SQLServer/SQLServerOptionParsers.ps1",
|
||||
"/SQLServer/SQLServerInstaller.ps1",
|
||||
"/Export-Function.ps1",
|
||||
"/Start-PowerShellProcess.ps1",
|
||||
"SQLServerForAOAG.ps1"
|
||||
],
|
||||
"Commands": [
|
||||
{
|
||||
"Name": "Initialize-AOAGSecondaryReplica",
|
||||
"Arguments": {
|
||||
"UserName": "$domainAdminAccountName",
|
||||
"UserPassword": "$domainAdminAccountPassword",
|
||||
"NodeList": "$nodeList",
|
||||
"PrimaryNode": "$primaryNode",
|
||||
"DomainName": "$domainName"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"Scripts": [
|
||||
"/ImportCoreFunctions.ps1",
|
||||
"/OptionParser.ps1",
|
||||
"/SQLServer/SQLServerOptionParsers.ps1",
|
||||
"/SQLServer/SQLServerInstaller.ps1",
|
||||
"/Export-Function.ps1",
|
||||
"/Start-PowerShellProcess.ps1",
|
||||
"SQLServerForAOAG.ps1"
|
||||
],
|
||||
"Commands": [
|
||||
{
|
||||
"Name": "Initialize-AlwaysOnAvailabilityGroup",
|
||||
"Arguments": {
|
||||
"DomainAdminAccountName": "$domainAdminAccountName",
|
||||
"DomainAdminAccountPassword": "$domainAdminAccountPassword",
|
||||
"NodeList": "$nodeList",
|
||||
"PrimaryNode": "$primaryNode",
|
||||
"DomainName": "$domainName"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
{
|
||||
"Scripts": [
|
||||
"/ImportCoreFunctions.ps1",
|
||||
"/OptionParser.ps1",
|
||||
"/SQLServer/SQLServerOptionParsers.ps1",
|
||||
"/SQLServer/SQLServerInstaller.ps1",
|
||||
"SQLServerForAOAG.ps1"
|
||||
],
|
||||
"Commands": [
|
||||
{
|
||||
"Name": "Disable-Firewall",
|
||||
"Arguments": {}
|
||||
},
|
||||
{
|
||||
"Name": "Install-SQLServerForAOAG",
|
||||
"Arguments": {
|
||||
"SQLServiceUserPassword": "$domainAdminAccountPassword",
|
||||
"SQLServiceUserDomain": "$domainName",
|
||||
"SQLServiceUserName": "$domainAdminAccountName"
|
||||
}
|
||||
},
|
||||
{
|
||||
"Name": "Install-SqlServerPowerShellModule",
|
||||
"Arguments": {}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,538 @@
|
||||
|
||||
trap {
|
||||
&$TrapHandler
|
||||
}
|
||||
|
||||
function Install-SqlServerPowerShellModule {
|
||||
param (
|
||||
[String] $SetupRoot = ''
|
||||
)
|
||||
begin {
|
||||
Show-InvocationInfo $MyInvocation
|
||||
}
|
||||
end {
|
||||
Show-InvocationInfo $MyInvocation -End
|
||||
}
|
||||
process {
|
||||
trap {
|
||||
&$TrapHandler
|
||||
}
|
||||
|
||||
if ((Get-Module SQLPS -ListAvailable) -ne $null) {
|
||||
Write-Log "Module SQLSP already installed."
|
||||
return
|
||||
}
|
||||
|
||||
if ($MuranoFileShare -eq '') {
|
||||
$MuranoFileShare = [String]([Environment]::GetEnvironmentVariable('MuranoFileShare'))
|
||||
if ($MuranoFileShare -eq '') {
|
||||
throw "Unable to find MuranoFileShare path."
|
||||
}
|
||||
}
|
||||
Write-LogDebug "MuranoFileShare = '$MuranoFileShare'"
|
||||
|
||||
if ($SetupRoot -eq '') {
|
||||
$SetupRoot = [IO.Path]::Combine("$MuranoFileShare", 'Prerequisites\SQL Server\Tools')
|
||||
}
|
||||
Write-LogDebug "SetupRoot = '$SetupRoot'"
|
||||
|
||||
$FileList = @(
|
||||
'SQLSysClrTypes.msi',
|
||||
'SharedManagementObjects.msi',
|
||||
'PowerShellTools.msi'
|
||||
)
|
||||
|
||||
foreach ($MsiFile in $FileList) {
|
||||
Write-Log "Trying to install '$MsiFile' ..."
|
||||
$MsiPath = Join-Path $SetupRoot $MsiFile
|
||||
if ([IO.File]::Exists($MsiPath)) {
|
||||
Write-Log "Starting msiexe ..."
|
||||
$Result = Exec -FilePath "msiexec.exe" -ArgumentList @('/i', "`"$MsiPath`"", '/quiet') -PassThru
|
||||
if ($Result.ExitCode -ne 0) {
|
||||
throw "Installation of MSI package '$MsiPath' failed with error code '$($Result.ExitCode)'"
|
||||
}
|
||||
}
|
||||
else {
|
||||
Write-Log "File '$MsiPath' not found."
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
function Install-SqlServerForAOAG {
|
||||
param (
|
||||
# Path to folder where msi files for additional SQL features are located
|
||||
[String] $SetupRoot = '',
|
||||
|
||||
# Path to folder where msi files for additional SQLPS module are located
|
||||
[String] $SqlpsSetupRoot = '',
|
||||
|
||||
[String] $MuranoFileShare = '',
|
||||
|
||||
# (REQUIRED) Domain name
|
||||
[String] $SQLServiceUserDomain = 'fc-acme.local',
|
||||
|
||||
# (REQUIRED) User name for the account which will be used by SQL service
|
||||
[String] $SQLServiceUserName = 'Administrator',
|
||||
|
||||
# (REQUIRED) Password for that user
|
||||
[String] $SQLServiceUserPassword = 'P@ssw0rd',
|
||||
|
||||
[Switch] $UpdateEnabled
|
||||
)
|
||||
begin {
|
||||
Show-InvocationInfo $MyInvocation
|
||||
}
|
||||
end {
|
||||
Show-InvocationInfo $MyInvocation -End
|
||||
}
|
||||
process {
|
||||
trap {
|
||||
&$TrapHandler
|
||||
}
|
||||
|
||||
if ($MuranoFileShare -eq '') {
|
||||
$MuranoFileShare = [String]([Environment]::GetEnvironmentVariable('MuranoFileShare'))
|
||||
if ($MuranoFileShare -eq '') {
|
||||
throw "Unable to find MuranoFileShare path."
|
||||
}
|
||||
}
|
||||
Write-LogDebug "MuranoFileShare = '$MuranoFileShare'"
|
||||
|
||||
if ($SetupRoot -eq '') {
|
||||
$SetupRoot = [IO.Path]::Combine("$MuranoFileShare", 'Prerequisites\SQL Server\2012')
|
||||
}
|
||||
Write-LogDebug "SetupRoot = '$SetupRoot'"
|
||||
|
||||
$ExtraOptions = @{}
|
||||
|
||||
if ($UpdateEnabled) {
|
||||
$ExtraOptions += @{'UpdateEnabled' = $true}
|
||||
}
|
||||
else {
|
||||
$ExtraOptions += @{'UpdateEnabled' = $false}
|
||||
}
|
||||
|
||||
$null = New-SQLServerForAOAG `
|
||||
-SetupRoot $SetupRoot `
|
||||
-SQLSvcUsrDomain $SQLServiceUserDomain `
|
||||
-SQLSvcUsrName $SQLServiceUserName `
|
||||
-SQLSvcUsrPassword $SQLServiceUserPassword `
|
||||
-ExtraOptions $ExtraOptions
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
function Initialize-AlwaysOnAvailabilityGroup {
|
||||
param (
|
||||
[String] $DomainName,
|
||||
[String] $DomainAdminAccountName,
|
||||
[String] $DomainAdminAccountPassword,
|
||||
[String] $SqlServiceAccountName,
|
||||
[String] $PrimaryNode,
|
||||
[String] $ShareName = 'SharedWorkDir'
|
||||
)
|
||||
begin {
|
||||
Show-InvocationInfo $MyInvocation
|
||||
}
|
||||
end {
|
||||
Show-InvocationInfo $MyInvocation -End
|
||||
}
|
||||
process {
|
||||
trap {
|
||||
&$TrapHandler
|
||||
}
|
||||
|
||||
$ShareNetworkPath = '\\' + $PrimaryNode + '\' + $ShareName
|
||||
|
||||
$DomainAdminAccountCreds = New-Credential `
|
||||
-UserName "$DomainName\$DomainAdminAccountName" `
|
||||
-Password "$DomainAdminAccountPassword"
|
||||
|
||||
$FunctionsFile = Export-Function 'Get-NextFreePort', 'Initialize-AlwaysOn'
|
||||
|
||||
$null = Start-PowerShellProcess @"
|
||||
trap {
|
||||
`$_
|
||||
exit 1
|
||||
}
|
||||
|
||||
Import-Module CoreFunctions
|
||||
|
||||
Write-Log "Importing functions file '$FunctionsFile' ..."
|
||||
. "$FunctionsFile"
|
||||
|
||||
Write-Log "Starting 'Initialize-AlwaysOn' ..."
|
||||
`$XmlFile = [IO.Path]::Combine("$ShareNetworkPath", "`$(`$Env:ComputerName).xml")
|
||||
Write-Log "Output XML file is '`$XmlFile'"
|
||||
Initialize-AlwaysOn | Export-CliXml -Path `$XmlFile
|
||||
"@ -Credential $DomainAdminAccountCreds -NoBase64
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function New-SharedFolderForAOAG {
|
||||
param (
|
||||
# (OPTIONAL)
|
||||
[String] $SharePath = [IO.Path]::Combine($Env:SystemDrive + '\', 'SharedWorkDir'),
|
||||
|
||||
# (OPTIONAL)
|
||||
[String] $ShareName = 'SharedWorkDir',
|
||||
|
||||
[String] $PrimaryNode = ' '
|
||||
)
|
||||
begin {
|
||||
Show-InvocationInfo $MyInvocation
|
||||
}
|
||||
end {
|
||||
Show-InvocationInfo $MyInvocation -End
|
||||
}
|
||||
process {
|
||||
trap {
|
||||
&$TrapHandler
|
||||
}
|
||||
|
||||
if ($PrimaryNode.ToLower() -ne ($Env:ComputerName).ToLower()) {
|
||||
Write-Log "This script runs on primary node only."
|
||||
Write-Log "Exiting script."
|
||||
return
|
||||
}
|
||||
|
||||
if ($ShareName -eq '') {
|
||||
$ShareName = [IO.Path]::GetFileNameWithoutExtension($SharePath)
|
||||
}
|
||||
|
||||
Write-LogDebug "SharePath = '$SharePath'"
|
||||
Write-LogDebug "ShareName = '$ShareName'"
|
||||
|
||||
try {
|
||||
Write-LogDebug "Trying to remove share '$ShareName'"
|
||||
$null = Get-SmbShare -Name $ShareName -ErrorAction 'Stop'
|
||||
$null = Remove-SmbShare -Name $ShareName -Force
|
||||
write-Log "Share '$ShareName' removed."
|
||||
}
|
||||
catch {
|
||||
Write-LogWarning "Share '$ShareName' not exists or cannot be deleted."
|
||||
}
|
||||
|
||||
try {
|
||||
Write-LogDebug "Trying to remove folder '$SharePath"
|
||||
$null = Get-Item -Path $SharePath -ErrorAction 'Stop'
|
||||
$null = Remove-Item -Path $SharePath -Recurse -Force
|
||||
Write-Log "Folder '$SharePath' removed."
|
||||
}
|
||||
catch {
|
||||
Write-LogWarning "Folder '$SharePath' not exists or cannot be deleted."
|
||||
}
|
||||
|
||||
$null = New-Item -Path $SharePath -ItemType Container -Force
|
||||
|
||||
$null = New-SmbShare -Path $SharePath `
|
||||
-Name $ShareName `
|
||||
-FullAccess "Everyone" `
|
||||
-Description "Shared folder for AlwaysOn Availability Group setup."
|
||||
|
||||
return '\\' + $Env:ComputerName + '\' + $ShareName
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
function New-DatabaseForAOAG {
|
||||
param (
|
||||
[String] $DatabaseName,
|
||||
[String] $DomainName,
|
||||
[String] $UserName,
|
||||
[String] $UserPassword
|
||||
)
|
||||
|
||||
$Creds = New-Credential -UserName "$DomainName\$UserName" -Password "$UserPassword"
|
||||
|
||||
$FunctionsFile = Export-Function 'Invoke-SQLText', 'ConvertTo-SQLName', 'ConvertTo-SQLString', 'New-SQLDatabase'
|
||||
|
||||
Start-PowerShellProcess @"
|
||||
trap {
|
||||
`$_
|
||||
exit 1
|
||||
}
|
||||
|
||||
Import-Module CoreFunctions
|
||||
|
||||
Write-Log "Importing functions from file '$FunctionsFile' ..."
|
||||
. "$FunctionsFile"
|
||||
|
||||
Write-Log "Starting 'New-SQLDatabase' ..."
|
||||
New-SQLDatabase $DatabaseName
|
||||
"@ -Credential $Creds -NoBase64
|
||||
}
|
||||
|
||||
|
||||
|
||||
function Initialize-AOAGPrimaryReplica {
|
||||
param (
|
||||
# (OPTIONAL) Name of the new Availability Group. If not specified then default name will be used.
|
||||
[String] $GroupName = 'MuranoAG',
|
||||
|
||||
# (REQUIRED) Nodes that will be configured as replica partners.
|
||||
#[Parameter(Mandatory=$true)]
|
||||
[String[]] $NodeList,
|
||||
|
||||
# (REQUIRED) Node name that will be primary for selected Availability Group
|
||||
#[Parameter(Mandatory=$true)]
|
||||
[String] $PrimaryNode,
|
||||
|
||||
# (REQUIRED) Database list that will be added to the Availability Group
|
||||
#[Parameter(Mandatory=$true)]
|
||||
[String[]] $DatabaseList,
|
||||
|
||||
# (REQUIRED) Listener name that will be used by clients to connect to databases in that AG
|
||||
#[Parameter(Mandatory=$true)]
|
||||
[String] $ListenerName = 'MuranoAG_Listener',
|
||||
|
||||
# (REQUIRED) IP address of the listener
|
||||
#[Parameter(Mandatory=$true)]
|
||||
[String] $ListenerIP,
|
||||
|
||||
[String] $ListenerIPMask = '255.255.255.0',
|
||||
|
||||
[String] $ListenerPort = '5023',
|
||||
|
||||
# Sync Mode Node List
|
||||
[String[]] $SyncModeNodeList,
|
||||
|
||||
[String] $SharedWorkDir = 'SharedWorkDir',
|
||||
|
||||
[String] $CliXmlFile = '',
|
||||
|
||||
[String] $DomainName,
|
||||
[String] $UserName,
|
||||
[String] $UserPassword
|
||||
)
|
||||
begin {
|
||||
Show-InvocationInfo $MyInvocation
|
||||
}
|
||||
end {
|
||||
Show-InvocationInfo $MyInvocation -End
|
||||
}
|
||||
process {
|
||||
trap {
|
||||
&$TrapHandler
|
||||
}
|
||||
|
||||
Write-Log "Primary node: '$($PrimaryNode.ToLower())'"
|
||||
Write-Log "Current node: '$(($Env:ComputerName).ToLower())'"
|
||||
|
||||
if ($PrimaryNode.ToLower() -ne $($Env:ComputerName).ToLower()) {
|
||||
Write-Log "This function works on PrimaryNode only."
|
||||
Write-Log "Exiting."
|
||||
return
|
||||
}
|
||||
|
||||
if ($CliXmlFile -eq '') {
|
||||
$ReplicaDefinitionList = @()
|
||||
foreach ($Node in $NodeList) {
|
||||
try {
|
||||
$NodeEndpointPort = Import-CliXml -Path "\\$PrimaryNode\SharedWorkDir\$Node.xml"
|
||||
}
|
||||
catch {
|
||||
Write-Log "Using default endpoint port 5022"
|
||||
$NodeEndpointPort = 5022
|
||||
}
|
||||
|
||||
$ReplicaDefinition = @{
|
||||
"SERVER_INSTANCE" = "$Node";
|
||||
"ENDPOINT_URL" = "TCP://${Node}:${NodeEndpointPort}";
|
||||
"AVAILABILITY_MODE" = "ASYNCHRONOUS_COMMIT";
|
||||
"FAILOVER_MODE"="MANUAL";
|
||||
}
|
||||
|
||||
if ($SyncModeNodeList -contains $Node) {
|
||||
Write-Log "$Node is in SyncModeNodeList"
|
||||
$ReplicaDefinition['AVAILABILITY_MODE'] = "SYNCHRONOUS_COMMIT"
|
||||
$ReplicaDefinition['FAILOVER_MODE'] = "AUTOMATIC"
|
||||
}
|
||||
else {
|
||||
Write-Log "$Node is NOT in SyncModeNodeList"
|
||||
}
|
||||
|
||||
$ReplicaDefinitionList += @($ReplicaDefinition)
|
||||
}
|
||||
|
||||
$Preferences = @{}
|
||||
|
||||
$ListenerDefinition = @{
|
||||
"NAME"=$ListenerName;
|
||||
"PORT" = "$ListenerPort";
|
||||
"STATIC" = "$ListenerIP/$ListenerIPMask"
|
||||
}
|
||||
|
||||
$Parameters = @{
|
||||
'WorkDir' = "\\$PrimaryNode\$SharedWorkDir";
|
||||
'Name' = $GroupName;
|
||||
'DatabaseNames' = $DatabaseList;
|
||||
'ReplicaDefs' = $ReplicaDefinitionList;
|
||||
'Preferences' = $Preferences;
|
||||
'ListenerDef' = $ListenerDefinition;
|
||||
}
|
||||
|
||||
$null = Remove-Item -Path "\\$PrimaryNode\SharedWorkDir\*" -Force
|
||||
|
||||
$CliXmlFile = [IO.Path]::GetTempFileName()
|
||||
|
||||
Write-LogDebug "CliXml file: '$CliXmlFile'"
|
||||
|
||||
$null = Export-CliXml -Path $CliXmlFile -InputObject $Parameters -Depth 10
|
||||
|
||||
$null = Initialize-AOAGPrimaryReplica `
|
||||
-CliXmlFile $CliXmlFile `
|
||||
-DomainName $DomainName `
|
||||
-UserName $UserName `
|
||||
-UserPassword $UserPassword `
|
||||
-PrimaryNode $PrimaryNode
|
||||
|
||||
Write-LogDebug "Inner 'Initialize-AOAGPrimaryReplica' call completed."
|
||||
}
|
||||
else {
|
||||
$Creds = New-Credential -UserName "$DomainName\$UserName" -Password "$UserPassword"
|
||||
|
||||
$FunctionsFile = Export-Function -All
|
||||
|
||||
$null = Start-PowerShellProcess @"
|
||||
trap {
|
||||
`$_
|
||||
exit 1
|
||||
}
|
||||
|
||||
Import-Module CoreFunctions
|
||||
|
||||
Write-Log "Importing functions from '$FunctionsFile' ..."
|
||||
. "$FunctionsFile"
|
||||
|
||||
Write-Log "Importing CliXml parameters file ..."
|
||||
`$Parameters = Import-CliXml -Path $CliXmlFile
|
||||
|
||||
Write-Log "Starting 'New-AlwaysOnAvailabilityGroup' ..."
|
||||
New-AlwaysOnAvailabilityGroup ``
|
||||
-WorkDir `$Parameters['WorkDir'] ``
|
||||
-Name `$Parameters['Name'] ``
|
||||
-DatabaseNames `$Parameters['DatabaseNames'] ``
|
||||
-ReplicaDefs `$Parameters['ReplicaDefs'] ``
|
||||
-Preferences `$Parameters['Preferences'] ``
|
||||
-ListenerDef `$Parameters['ListenerDef']
|
||||
"@ -Credential $Creds -NoBase64
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
function Initialize-AOAGSecondaryReplica {
|
||||
param (
|
||||
# (REQUIRED) Nodes that will be configured as replica partners.
|
||||
[Parameter(Mandatory=$true)]
|
||||
[String[]] $NodeList,
|
||||
|
||||
# (REQUIRED) Node name that will be primary for selected Availability Group
|
||||
[Parameter(Mandatory=$true)]
|
||||
[String] $PrimaryNode,
|
||||
|
||||
[String] $SharedWorkDir = 'SharedWorkDir',
|
||||
|
||||
[String] $DomainName,
|
||||
[String] $UserName,
|
||||
[String] $UserPassword
|
||||
)
|
||||
begin {
|
||||
Show-InvocationInfo $MyInvocation
|
||||
}
|
||||
end {
|
||||
Show-InvocationInfo $MyInvocation -End
|
||||
}
|
||||
process {
|
||||
trap {
|
||||
&$TrapHandler
|
||||
}
|
||||
|
||||
if ($PrimaryNode.ToLower() -eq ($Env:ComputerName).ToLower()) {
|
||||
Write-Log "This function works on any SecondaryNode only."
|
||||
Write-Log "Exiting."
|
||||
return
|
||||
}
|
||||
|
||||
$Creds = New-Credential -UserName "$DomainName\$UserName" -Password "$UserPassword"
|
||||
|
||||
$FunctionsFile = Export-Function -All
|
||||
|
||||
$null = Start-PowerShellProcess @"
|
||||
trap {
|
||||
$_
|
||||
exit 1
|
||||
}
|
||||
|
||||
Import-Module CoreFunctions
|
||||
|
||||
Write-Log "Importing functions from '$FunctionsFile' ..."
|
||||
. "$FunctionsFile"
|
||||
|
||||
Write-Log "Starting 'New-AlwaysOnAvailabilityGroupReplica' ..."
|
||||
New-AlwaysOnAvailabilityGroupReplica -WorkDir "\\$PrimaryNode\$SharedWorkDir"
|
||||
"@ -Credential $Creds -NoBase64
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
function Disable-Firewall {
|
||||
begin {
|
||||
Show-InvocationInfo $MyInvocation
|
||||
}
|
||||
end {
|
||||
Show-InvocationInfo $MyInvocation -End
|
||||
}
|
||||
process {
|
||||
trap {
|
||||
&$TrapHandler
|
||||
}
|
||||
|
||||
netsh advfirewall set allprofiles state off
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
function Enable-Firewall {
|
||||
begin {
|
||||
Show-InvocationInfo $MyInvocation
|
||||
}
|
||||
end {
|
||||
Show-InvocationInfo $MyInvocation -End
|
||||
}
|
||||
process {
|
||||
trap {
|
||||
&$TrapHandler
|
||||
}
|
||||
|
||||
netsh advfirewall set allprofiles state on
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
function Enable-TrustedHosts {
|
||||
begin {
|
||||
Show-InvocationInfo $MyInvocation
|
||||
}
|
||||
end {
|
||||
Show-InvocationInfo $MyInvocation -End
|
||||
}
|
||||
process {
|
||||
trap {
|
||||
&$TrapHandler
|
||||
}
|
||||
|
||||
Set-Item WSMan:\localhost\Client\TrustedHosts -Value '*' -Force
|
||||
}
|
||||
}
|
||||
61
data3/templates/agent/scripts/Alter-FirewallRulesForSQL.ps1
Normal file
61
data3/templates/agent/scripts/Alter-FirewallRulesForSQL.ps1
Normal file
@@ -0,0 +1,61 @@
|
||||
trap {
|
||||
&$TrapHandler
|
||||
}
|
||||
|
||||
|
||||
$FW_Rules = @{
|
||||
"SQL Server Data Connection" = "1433";
|
||||
"SQL Admin Connection" = "1434";
|
||||
"SQL Service Broker" = "4022";
|
||||
"SQL Debugger/RPC"="135";
|
||||
}
|
||||
|
||||
|
||||
$FW_Proto = "TCP"
|
||||
|
||||
|
||||
function Add-NetshFirewallRule {
|
||||
param (
|
||||
[HashTable] $hshRules,
|
||||
[String] $proto
|
||||
)
|
||||
|
||||
|
||||
foreach ($h in $hshRules.GetEnumerator()) {
|
||||
try {
|
||||
$command="advfirewall firewall add rule name=`"$($h.Name)`" dir=in action=allow protocol=$proto localport=$($h.Value)"
|
||||
Start-Process -FilePath netsh -ArgumentList $command -Wait
|
||||
}
|
||||
catch {
|
||||
$except= $_ | Out-String
|
||||
Write-LogError "Add rule $($h.Name) FAILS with $except"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function Remove-NetShFirewallRule {
|
||||
param (
|
||||
[HashTable] $hshRules
|
||||
)
|
||||
|
||||
foreach ($h in $hshRules.GetEnumerator()) {
|
||||
try {
|
||||
$command="advfirewall firewall delete rule name=`"$($h.Name)`""
|
||||
Start-Process -FilePath netsh -ArgumentList $command -Wait
|
||||
}
|
||||
catch {
|
||||
$except= $_ | Out-String
|
||||
Write-LogError "Delete rule $($h.Name) FAILS with $except"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function Enable-SQLExternalAccess {
|
||||
Add-NetshFirewallRule $FW_Rules $FW_Proto
|
||||
}
|
||||
|
||||
|
||||
function Disable-SQLExternalAccess {
|
||||
Remove-NetshFirewallRule $FW_Rules $FW_Proto
|
||||
}
|
||||
50
data3/templates/agent/scripts/CopyPrerequisites.ps1
Normal file
50
data3/templates/agent/scripts/CopyPrerequisites.ps1
Normal file
@@ -0,0 +1,50 @@
|
||||
|
||||
trap {
|
||||
&$TrapHandler
|
||||
}
|
||||
|
||||
|
||||
Function Copy-Prerequisites {
|
||||
param (
|
||||
[String] $Path = '',
|
||||
[String] $Destination = ''
|
||||
)
|
||||
begin {
|
||||
Show-InvocationInfo $MyInvocation
|
||||
}
|
||||
end {
|
||||
Show-InvocationInfo $MyInvocation -End
|
||||
}
|
||||
process {
|
||||
trap {
|
||||
&$TrapHandler
|
||||
}
|
||||
|
||||
Write-Log "--> Copy-Prerequisites"
|
||||
|
||||
if ($Destination -eq '') {
|
||||
throw("Copy-Prerequisites: Destination path not specified!")
|
||||
}
|
||||
|
||||
if ($Path -eq '') {
|
||||
$Path = [Environment]::GetEnvironmentVariable('MuranoFileShare')
|
||||
if ($Path -eq $null) {
|
||||
throw("Copy-Prerequisites: Unable to determine source path for prerequisites.")
|
||||
}
|
||||
}
|
||||
|
||||
Write-Log "Creating new PSDrive ..."
|
||||
New-PSDrive -Name 'P' -PSProvider 'FileSystem' -Root $Path | Out-Null
|
||||
|
||||
Write-Log "Creating destination folder ..."
|
||||
New-Item -Path $Destination -ItemType Container -Force | Out-Null
|
||||
|
||||
Write-Log "Copying items ..."
|
||||
Copy-Item -Path 'P:\Prerequisites\IIS' -Destination $Destination -Recurse -Force | Out-Null
|
||||
|
||||
Write-Log "Removing PSDrive ..."
|
||||
Remove-PSDrive -Name 'P' -PSProvider 'FileSystem' -Force | Out-Null
|
||||
|
||||
Write-Log "<-- Copy-Prerequisites"
|
||||
}
|
||||
}
|
||||
152
data3/templates/agent/scripts/DeployWebApp.ps1
Normal file
152
data3/templates/agent/scripts/DeployWebApp.ps1
Normal file
@@ -0,0 +1,152 @@
|
||||
|
||||
trap {
|
||||
&$TrapHandler
|
||||
}
|
||||
|
||||
|
||||
Function Register-WebApp {
|
||||
<#
|
||||
.LINKS
|
||||
|
||||
http://www.iis.net/learn/manage/powershell/powershell-snap-in-creating-web-sites-web-applications-virtual-directories-and-application-pools
|
||||
#>
|
||||
param (
|
||||
[String] $Source,
|
||||
[String] $Path = "C:\inetpub\wwwroot",
|
||||
[String] $Name = "",
|
||||
[String] $Username = "",
|
||||
[String] $Password = ""
|
||||
)
|
||||
begin {
|
||||
Show-InvocationInfo $MyInvocation
|
||||
}
|
||||
end {
|
||||
Show-InvocationInfo $MyInvocation -End
|
||||
}
|
||||
process {
|
||||
trap {
|
||||
&$TrapHandler
|
||||
}
|
||||
|
||||
Import-Module WebAdministration
|
||||
|
||||
if ($Name -eq "") {
|
||||
$Name = @([IO.Path]::GetDirectoryName($Source) -split '\\')[-1]
|
||||
if ($Name -eq "wwwroot") {
|
||||
throw("Application pool name couldn't be 'wwwroot'.")
|
||||
}
|
||||
}
|
||||
else {
|
||||
$Path = [IO.Path]::Combine($Path, $Name)
|
||||
}
|
||||
|
||||
$null = Copy-Item -Path $Source -Destination $Path -Recurse -Force
|
||||
|
||||
# Create new application pool
|
||||
$AppPool = New-WebAppPool -Name $Name -Force
|
||||
#$AppPool = Get-Item "IIS:\AppPools\$Name"
|
||||
$AppPool.managedRuntimeVersion = 'v4.0'
|
||||
$AppPool.managedPipelineMode = 'Classic'
|
||||
$AppPool.processModel.loadUserProfile = $true
|
||||
$AppPool.processModel.logonType = 'LogonBatch'
|
||||
|
||||
#Set Identity type
|
||||
if ($Username -eq "") {
|
||||
$AppPool.processModel.identityType = 'ApplicationPoolIdentity'
|
||||
}
|
||||
else {
|
||||
$AppPool.processModel.identityType = 'SpecificUser'
|
||||
$AppPool.processModel.userName = $Username
|
||||
$AppPool.processModel.password = $Password
|
||||
$null = $AppPool | Set-Item
|
||||
}
|
||||
|
||||
|
||||
# Create Website
|
||||
$WebSite = New-WebSite -Name $Name -Port 80 -HostHeader $Name -PhysicalPath $Path -Force
|
||||
#$WebSite = Get-Item "IIS:\Sites\$Name"
|
||||
|
||||
# Set the Application Pool
|
||||
$null = Set-ItemProperty "IIS:\Sites\$Name" 'ApplicationPool' $Name
|
||||
|
||||
#Turn on Directory Browsing
|
||||
#Set-WebConfigurationProperty -Filter '/system.webServer/directoryBrowse' -Name 'enabled' -Value $true -PSPath "IIS:\Sites\$Name"
|
||||
|
||||
# Update Authentication
|
||||
#Set-WebConfigurationProperty -Filter '/system.WebServer/security/authentication/AnonymousAuthentication' -Name 'enabled' -Value $true -Location $name
|
||||
#Set-WebConfigurationProperty -Filter '/system.WebServer/security/authentication/windowsAuthentication' -Name 'enabled' -Value $false -Location $Name
|
||||
#Set-WebConfigurationProperty -Filter '/system.WebServer/security/authentication/basicAuthentication' -Name 'enabled' -Value $false -Location $Name
|
||||
|
||||
$null = $WebSite.Start()
|
||||
|
||||
$null = Add-Content -Path "C:\Windows\System32\Drivers\etc\hosts" -Value "127.0.0.1 $Name"
|
||||
|
||||
# Remove standard IIS 'Hello World' application from localhost:80
|
||||
$null = Get-WebBinding 'Default Web Site' | Remove-WebBinding
|
||||
# Add new application on http://localhost:80
|
||||
$null = New-WebBinding -Name "$Name" -IP "*" -Port 80 -Protocol http
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Function Deploy-WebAppFromGit {
|
||||
param (
|
||||
[String] $URL,
|
||||
[String] $TempPath = [IO.Path]::Combine([IO.Path]::GetTempPath(), [IO.Path]::GetRandomFileName()),
|
||||
[String] $OutputPath = [IO.Path]::Combine([IO.Path]::GetTempPath(), [IO.Path]::GetRandomFileName())
|
||||
)
|
||||
begin {
|
||||
Show-InvocationInfo $MyInvocation
|
||||
}
|
||||
end {
|
||||
Show-InvocationInfo $MyInvocation -End
|
||||
}
|
||||
process {
|
||||
trap {
|
||||
&$TrapHandler
|
||||
}
|
||||
|
||||
Write-Log "TempPath = '$TempPath'"
|
||||
Write-Log "OutputPath = '$OutputPath'"
|
||||
|
||||
|
||||
# Fetch web application
|
||||
#----------------------
|
||||
Write-Log "Fetching sources from Git ..."
|
||||
|
||||
$null = New-Item -Path $TempPath -ItemType Container
|
||||
$null = Exec -FilePath 'git.exe' -ArgumentList @('clone', $URL) -WorkingDir $TempPath -RedirectStreams
|
||||
|
||||
$Path = @(Get-ChildItem $TempPath)[0].FullName
|
||||
#----------------------
|
||||
|
||||
|
||||
# Build web application
|
||||
#----------------------
|
||||
Write-Log "Building sources ..."
|
||||
|
||||
$msbuild = "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe"
|
||||
|
||||
$null = New-Item -Path $OutputPath -ItemType Container
|
||||
|
||||
$SlnFiles = @(Get-ChildItem -Path $Path -Filter *.sln -Recurse)
|
||||
|
||||
# Start new processs with additional env variables:
|
||||
#* VisualStudioVersion = "10.0"
|
||||
#* EnableNuGetPackageRestore = "true"
|
||||
$null = Exec -FilePath $msbuild `
|
||||
-ArgumentList @($SlnFiles[0].FullName, "/p:OutputPath=$OutputPath") `
|
||||
-Environment @{'VisualStudioVersion' = '10.0'; 'EnableNuGetPackageRestore' = 'true'} `
|
||||
-RedirectStreams
|
||||
|
||||
$AppFolder = @(Get-ChildItem ([IO.Path]::Combine($OutputPath, '_PublishedWebsites')))[0]
|
||||
#----------------------
|
||||
|
||||
|
||||
# Install web application
|
||||
#------------------------
|
||||
$null = Register-WebApp -Source $AppFolder.FullName -Name $AppFolder.Name
|
||||
#------------------------
|
||||
}
|
||||
}
|
||||
61
data3/templates/agent/scripts/Export-Function.ps1
Normal file
61
data3/templates/agent/scripts/Export-Function.ps1
Normal file
@@ -0,0 +1,61 @@
|
||||
|
||||
trap {
|
||||
&$TrapHandler
|
||||
}
|
||||
|
||||
function Export-Function {
|
||||
param (
|
||||
[String[]] $Name,
|
||||
|
||||
[Parameter(ValueFromPipeline=$true)]
|
||||
[String] $Path = [IO.Path]::GetTempFileName(),
|
||||
|
||||
[Switch] $All
|
||||
)
|
||||
|
||||
if ([IO.Path]::GetExtension($Path) -ne 'ps1') {
|
||||
$null = Rename-Item -Path $Path -NewName "$Path.ps1" -Force
|
||||
$Path = "$Path.ps1"
|
||||
}
|
||||
|
||||
$SystemFunctions = @(
|
||||
'A:', 'B:', 'C:', 'D:', 'E:', 'F:', 'G:', 'H:', 'I:', 'J:',
|
||||
'K:', 'L:', 'M:', 'N:', 'O:', 'P:', 'Q:', 'R:', 'S:', 'T:',
|
||||
'U:', 'V:', 'W:', 'X:', 'Y:', 'Z:',
|
||||
'cd..', 'cd\', 'help', 'mkdir', 'more', 'oss', 'prompt',
|
||||
'Clear-Host', 'Get-Verb', 'Pause', 'TabExpansion2'
|
||||
)
|
||||
|
||||
if ($All) {
|
||||
Get-ChildItem Function: |
|
||||
Where-Object {$_.ModuleName -eq ''} |
|
||||
Where-Object {$SystemFunctions -notcontains $_.Name} |
|
||||
ForEach-Object {
|
||||
Add-Content -Path $Path -Value @"
|
||||
|
||||
|
||||
function $($_.Name) {
|
||||
$($_.ScriptBlock)
|
||||
}
|
||||
|
||||
"@
|
||||
}
|
||||
}
|
||||
else {
|
||||
foreach ($FunctionName in $Name) {
|
||||
$FunctionObject = Get-ChildItem "Function:\$FunctionName"
|
||||
if ($FunctionObject -ne $null) {
|
||||
Add-Content -Path $Path -Value @"
|
||||
|
||||
|
||||
function $FunctionName {
|
||||
$($FunctionObject.ScriptBlock)
|
||||
}
|
||||
|
||||
"@
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $Path
|
||||
}
|
||||
239
data3/templates/agent/scripts/Failover-Cluster.ps1
Normal file
239
data3/templates/agent/scripts/Failover-Cluster.ps1
Normal file
@@ -0,0 +1,239 @@
|
||||
<#
|
||||
.DESCRIPTION
|
||||
|
||||
## Failover Cluster Input Data (from the UI)
|
||||
|
||||
* Domain Membership
|
||||
- [String] / [Select box] $DomainName - Domain name
|
||||
* Domain User Credentials
|
||||
- [String] $UserName - Username
|
||||
- [Password string] $UserPassword - User password
|
||||
* Shared Folder Information
|
||||
- [String] $ShareServer - Server which will host the folder
|
||||
- [String] $ShareName - Share name
|
||||
- [String] $SharePath - Shared folder internal path
|
||||
* Failover Cluster Members
|
||||
- [String] $ClusterName - Cluster name
|
||||
- [String] $ClusterIP - Static IP address that will be assigned to the cluster
|
||||
- [String[]] $ClusterNodes - List of node names
|
||||
|
||||
|
||||
|
||||
## Failover Cluster creation workflow
|
||||
|
||||
* Create AD domain
|
||||
* Join all the VMs to that domain
|
||||
* Prepare nodes
|
||||
- Install Failover Cluster prerequisites on all FC nodes
|
||||
* Create failover cluster
|
||||
- Create new cluster
|
||||
- Add members
|
||||
* Confugure FC quorum
|
||||
- Create new folder that will be shared
|
||||
- Share that folder with appropriate permissions
|
||||
- Configure quorum mode
|
||||
|
||||
|
||||
|
||||
## Helpful SmbShare* Functions
|
||||
|
||||
* New-SmbShare
|
||||
* Grant-SmbShareAccess
|
||||
|
||||
#>
|
||||
|
||||
trap {
|
||||
&$TrapHandler
|
||||
}
|
||||
|
||||
|
||||
|
||||
function Install-FailoverClusterPrerequisites {
|
||||
#Import-Module FailoverClusters
|
||||
|
||||
#Add-WindowsFeature Failover-Clustering, RSAT-Clustering-PowerShell
|
||||
}
|
||||
|
||||
|
||||
|
||||
function New-FailoverClusterSharedFolder {
|
||||
param (
|
||||
[String] $ClusterName,
|
||||
[String] $DomainName,
|
||||
[String] $ShareServer,
|
||||
[String] $SharePath = $($Env:SystemDrive + '\FCShare'),
|
||||
[String] $ShareName = 'FCShare',
|
||||
[String] $UserName,
|
||||
[String] $UserPassword,
|
||||
$Credential = $null
|
||||
)
|
||||
begin {
|
||||
Show-InvocationInfo $MyInvocation
|
||||
}
|
||||
end {
|
||||
Show-InvocationInfo $MyInvocation -End
|
||||
}
|
||||
process {
|
||||
trap {
|
||||
&$TrapHandler
|
||||
}
|
||||
|
||||
Write-Log "--> New-FailoverClusterSharedFolder"
|
||||
|
||||
Write-Log "Creating shared folder for Failover Cluster ..."
|
||||
|
||||
if ($Credential -eq $null) {
|
||||
$Credential = New-Credential -UserName "$DomainName\$UserName" -Password "$UserPassword"
|
||||
}
|
||||
|
||||
if ((Test-Connection -ComputerName $ShareServer -Count 1 -Quiet) -eq $false) {
|
||||
throw("Server '$ShareServer' is unreachable via ICMP.")
|
||||
}
|
||||
|
||||
$Session = New-PSSession -ComputerName $ShareServer -Credential $Credential
|
||||
|
||||
Write-Log "Creating folder on '$ShareServer' ..."
|
||||
Invoke-Command -Session $Session -ScriptBlock {
|
||||
param (
|
||||
[String] $SharePath,
|
||||
[String] $ShareName,
|
||||
[String] $ClusterAccount
|
||||
)
|
||||
|
||||
Remove-SmbShare -Name $ShareName -Force -ErrorAction 'SilentlyContinue'
|
||||
Remove-Item -Path $SharePath -Force -ErrorAction 'SilentlyContinue'
|
||||
|
||||
New-Item -Path $SharePath -ItemType Container -Force
|
||||
|
||||
New-SmbShare -Path $SharePath `
|
||||
-Name $ShareName `
|
||||
-FullAccess "$ClusterAccount", 'Everyone' `
|
||||
-Description "Shared folder for Failover Cluster."
|
||||
|
||||
} -ArgumentList $SharePath, $ShareName, "$DomainName\$ClusterName`$"
|
||||
|
||||
Write-Log "Confguring Failover Cluster to use shared folder as qourum resourse ..."
|
||||
|
||||
$null = Set-ClusterQuorum -NodeAndFileShareMajority "\\$ShareServer\$ShareName"
|
||||
|
||||
Write-Log "<-- New-FailoverClusterSharedFolder"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
function New-FailoverCluster {
|
||||
param (
|
||||
[String] $ClusterName,
|
||||
[String] $StaticAddress,
|
||||
[String[]] $ClusterNodes,
|
||||
[String] $DomainName,
|
||||
[String] $UserName,
|
||||
[String] $UserPassword,
|
||||
$Credential
|
||||
)
|
||||
begin {
|
||||
Show-InvocationInfo $MyInvocation
|
||||
}
|
||||
end {
|
||||
Show-InvocationInfo $MyInvocation -End
|
||||
}
|
||||
process {
|
||||
trap {
|
||||
&$TrapHandler
|
||||
}
|
||||
|
||||
Write-Log "ClusterNodes: $($ClusterNodes -join ', ')"
|
||||
|
||||
if ($Credential -eq $null) {
|
||||
$Credential = New-Credential -UserName "$DomainName\$UserName" -Password "$UserPassword"
|
||||
}
|
||||
|
||||
foreach ($Node in $ClusterNodes) {
|
||||
Write-LogDebug "Installing Failover Cluster modules on '$Node' ..."
|
||||
$null = Invoke-Command `
|
||||
-ComputerName $Node `
|
||||
-Credential $Credential `
|
||||
-ScriptBlock {
|
||||
Add-WindowsFeature Failover-Clustering, RSAT-Clustering-PowerShell
|
||||
}
|
||||
}
|
||||
|
||||
Import-Module FailoverClusters
|
||||
|
||||
if ((Get-Cluster $ClusterName -ErrorAction SilentlyContinue) -eq $null) {
|
||||
Write-Log "Creating new cluster '$ClusterName' ..."
|
||||
<#
|
||||
Start-PowerShellProcess -Command @"
|
||||
Import-Module FailoverClusters
|
||||
New-Cluster -Name '$ClusterName' -StaticAddress '$StaticAddress'
|
||||
"@ -Credential $Credential -NoBase64
|
||||
#>
|
||||
New-Cluster -Name "$ClusterName" -StaticAddress "$StaticAddress"
|
||||
Start-Sleep -Seconds 30
|
||||
}
|
||||
else {
|
||||
Write-Log "Cluster '$ClusterName' already exists."
|
||||
}
|
||||
|
||||
foreach ($Node in $ClusterNodes) {
|
||||
Write-Log "Adding node '$Node' to the cluster '$ClusterName' ..."
|
||||
if ((Get-ClusterNode $Node -ErrorAction SilentlyContinue) -eq $null) {
|
||||
Write-Log "Adding node ..."
|
||||
<#
|
||||
Start-PowerShellProcess -Command @"
|
||||
Import-Module FailoverClusters
|
||||
Add-ClusterNode -Cluster '$ClusterName' -Name '$Node'
|
||||
"@ -Credential $Credential -NoBase64
|
||||
#>
|
||||
Add-ClusterNode -Cluster "$ClusterName" -Name "$Node"
|
||||
}
|
||||
else {
|
||||
Write-Log "Node '$Node' already a part of the cluster '$ClusterName'."
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
<#
|
||||
|
||||
# Example
|
||||
|
||||
$DomainName = 'fc-acme.local'
|
||||
$DomainUser = 'Administrator'
|
||||
$DomainPassword = 'P@ssw0rd'
|
||||
|
||||
$ClusterName = 'fc-test'
|
||||
$ClusterIP = '10.200.0.60'
|
||||
$ClusterNodes = @('fc-node-01','fc-node-02','fc-node-03')
|
||||
|
||||
$ShareServer = 'fc-dc-01'
|
||||
$ShareName = 'FCShare'
|
||||
|
||||
$SharePath = "C:\$ShareName"
|
||||
|
||||
|
||||
|
||||
Import-Module CoreFunctions -Force
|
||||
|
||||
$Creds = New-Credential `
|
||||
-UserName "$DomainName\$DomainUser" `
|
||||
-Password "$DomainPassword"
|
||||
|
||||
New-FailoverCluster `
|
||||
-ClusterName $ClusterName `
|
||||
-StaticAddress $ClusterIP `
|
||||
-ClusterNodes $ClusterNodes `
|
||||
-Credential $Creds
|
||||
|
||||
New-FailoverClusterSharedFolder `
|
||||
-ClusterName $ClusterName `
|
||||
-DomainName $DomainName `
|
||||
-ShareServer $ShareServer `
|
||||
-SharePath "$SharePath" `
|
||||
-ShareName "$ShareName" `
|
||||
-Credential $Creds
|
||||
|
||||
#>
|
||||
@@ -0,0 +1,7 @@
|
||||
|
||||
function Get-DnsListeningIpAddress {
|
||||
Import-Module DnsServer
|
||||
|
||||
(Get-DNSServer -ComputerName localhost).ServerSetting.ListeningIpAddress |
|
||||
Where-Object { $_ -match "\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}" }
|
||||
}
|
||||
68
data3/templates/agent/scripts/ImportCoreFunctions.ps1
Normal file
68
data3/templates/agent/scripts/ImportCoreFunctions.ps1
Normal file
@@ -0,0 +1,68 @@
|
||||
|
||||
Import-Module CoreFunctions -Force
|
||||
Initialize-Logger 'MuranoAgent' 'C:\Murano\PowerShell.log'
|
||||
|
||||
|
||||
function Show-InvocationInfo {
|
||||
param (
|
||||
$Invocation,
|
||||
[Switch] $End
|
||||
)
|
||||
|
||||
if ($End) {
|
||||
Write-LogDebug "</function name='$($Invocation.MyCommand.Name)'>"
|
||||
}
|
||||
else {
|
||||
Write-LogDebug "<function name='$($Invocation.MyCommand.Name)'>"
|
||||
Write-LogDebug "<param>"
|
||||
foreach ($Parameter in $Invocation.MyCommand.Parameters) {
|
||||
foreach ($Key in $Parameter.Keys) {
|
||||
$Type = $Parameter[$Key].ParameterType.FullName
|
||||
foreach ($Value in $Invocation.BoundParameters[$Key]) {
|
||||
Write-LogDebug "[$Type] $Key = '$Value'"
|
||||
}
|
||||
}
|
||||
}
|
||||
Write-LogDebug "</param>"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$TrapHandler = {
|
||||
Write-LogError "<exception>"
|
||||
Write-LogError $_ -EntireObject
|
||||
Write-LogError "</exception>"
|
||||
break
|
||||
}
|
||||
|
||||
|
||||
trap {
|
||||
&$TrapHandler
|
||||
}
|
||||
|
||||
$ErrorActionPreference = 'Stop'
|
||||
|
||||
|
||||
<#
|
||||
# Usage example for Show-InvocationInfo
|
||||
|
||||
function MyFunction {
|
||||
param (
|
||||
[String] $Value1,
|
||||
[String] $Value2,
|
||||
[Int] $Int1
|
||||
)
|
||||
begin {
|
||||
Show-InvocationInfo $MyInvocation
|
||||
}
|
||||
end {
|
||||
Show-InvocationInfo $MyInvocation -End
|
||||
}
|
||||
process {
|
||||
trap {
|
||||
&$TrapHandler
|
||||
}
|
||||
# Main code here
|
||||
}
|
||||
}
|
||||
#>
|
||||
@@ -0,0 +1,43 @@
|
||||
|
||||
trap {
|
||||
&$TrapHandler
|
||||
}
|
||||
|
||||
|
||||
Function Install-RolePrimaryDomainController {
|
||||
param (
|
||||
[String] $DomainName,
|
||||
[String] $SafeModePassword
|
||||
)
|
||||
begin {
|
||||
Show-InvocationInfo $MyInvocation
|
||||
}
|
||||
end {
|
||||
Show-InvocationInfo $MyInvocation -End
|
||||
}
|
||||
process {
|
||||
trap {
|
||||
&$TrapHandler
|
||||
}
|
||||
|
||||
Add-WindowsFeatureWrapper `
|
||||
-Name "DNS","AD-Domain-Services","RSAT-DFS-Mgmt-Con" `
|
||||
-IncludeManagementTools `
|
||||
-NotifyRestart
|
||||
|
||||
Write-Log "Creating first domain controller ..."
|
||||
|
||||
$SMAP = ConvertTo-SecureString -String $SafeModePassword -AsPlainText -Force
|
||||
|
||||
$null = Install-ADDSForest `
|
||||
-DomainName $DomainName `
|
||||
-SafeModeAdministratorPassword $SMAP `
|
||||
-DomainMode Default `
|
||||
-ForestMode Default `
|
||||
-NoRebootOnCompletion `
|
||||
-Force
|
||||
|
||||
Write-Log "Waiting 60 seconds for reboot ..."
|
||||
Start-Sleep -Seconds 60
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
|
||||
trap {
|
||||
&$TrapHandler
|
||||
}
|
||||
|
||||
|
||||
Function Install-RoleSecondaryDomainController
|
||||
{
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Install additional (secondary) domain controller.
|
||||
|
||||
#>
|
||||
param
|
||||
(
|
||||
[String]
|
||||
# Domain name to join to.
|
||||
$DomainName,
|
||||
|
||||
[String]
|
||||
# Domain user who is allowed to join computer to domain.
|
||||
$UserName,
|
||||
|
||||
[String]
|
||||
# User's password.
|
||||
$Password,
|
||||
|
||||
[String]
|
||||
# Domain controller recovery mode password.
|
||||
$SafeModePassword
|
||||
)
|
||||
begin {
|
||||
Show-InvocationInfo $MyInvocation
|
||||
}
|
||||
end {
|
||||
Show-InvocationInfo $MyInvocation -End
|
||||
}
|
||||
process {
|
||||
trap {
|
||||
&$TrapHandler
|
||||
}
|
||||
|
||||
$Credential = New-Credential -UserName "$DomainName\$UserName" -Password $Password
|
||||
|
||||
# Add required windows features
|
||||
Add-WindowsFeatureWrapper `
|
||||
-Name "DNS","AD-Domain-Services","RSAT-DFS-Mgmt-Con" `
|
||||
-IncludeManagementTools `
|
||||
-NotifyRestart
|
||||
|
||||
|
||||
Write-Log "Adding secondary domain controller ..."
|
||||
|
||||
$SMAP = ConvertTo-SecureString -String $SafeModePassword -AsPlainText -Force
|
||||
|
||||
Install-ADDSDomainController `
|
||||
-DomainName $DomainName `
|
||||
-SafeModeAdministratorPassword $SMAP `
|
||||
-Credential $Credential `
|
||||
-NoRebootOnCompletion `
|
||||
-Force `
|
||||
-ErrorAction Stop | Out-Null
|
||||
|
||||
Write-Log "Waiting for restart ..."
|
||||
# Stop-Execution -ExitCode 3010 -ExitString "Computer must be restarted to finish domain controller promotion."
|
||||
# Write-Log "Restarting computer ..."
|
||||
# Restart-Computer -Force
|
||||
}
|
||||
}
|
||||
72
data3/templates/agent/scripts/InstallIIS.ps1
Normal file
72
data3/templates/agent/scripts/InstallIIS.ps1
Normal file
@@ -0,0 +1,72 @@
|
||||
|
||||
trap {
|
||||
&$TrapHandler
|
||||
}
|
||||
|
||||
|
||||
Function Install-WebServer {
|
||||
param (
|
||||
[String] $PrerequisitesPath
|
||||
)
|
||||
begin {
|
||||
Show-InvocationInfo $MyInvocation
|
||||
}
|
||||
end {
|
||||
Show-InvocationInfo $MyInvocation -End
|
||||
}
|
||||
process {
|
||||
trap {
|
||||
&$TrapHandler
|
||||
}
|
||||
|
||||
Write-Log "--> Install-WebServer"
|
||||
|
||||
$FeatureList = @(
|
||||
'Web-Server',
|
||||
'Web-Net-Ext45',
|
||||
'Web-ASP',
|
||||
'Web-Asp-Net45',
|
||||
'Web-ISAPI-Ext',
|
||||
'Web-ISAPI-Filter',
|
||||
'Web-Includes'
|
||||
)
|
||||
|
||||
$PrerequisitesList = @(
|
||||
'AspNetMvc4Setup.exe',
|
||||
'WebApplications.exe'
|
||||
)
|
||||
|
||||
$PrerequisitesPath = [IO.Path]::Combine($PrerequisitesPath, 'IIS')
|
||||
|
||||
Write-Log "Validating prerequisites based on the list ..."
|
||||
foreach ($FileName in $PrerequisitesList) {
|
||||
$FilePath = [IO.Path]::Combine($PrerequisitesPath, $FileName)
|
||||
if (-not (Test-Path -Path $FilePath -PathType Leaf)) {
|
||||
throw("Prerequisite file not found: '$FilePath'")
|
||||
}
|
||||
}
|
||||
|
||||
Import-Module ServerManager
|
||||
|
||||
Write-Log "Installing Web Server ..."
|
||||
Install-WindowsFeature $FeatureList -IncludeManagementTools
|
||||
|
||||
Write-Log "Installing AspNetMvp4 ..."
|
||||
$Exec = Exec -FilePath $([IO.Path]::Combine($PrerequisitesPath, 'AspNetMvc4Setup.exe')) -ArgumentList '/q' -PassThru
|
||||
if ($Exec.ExitCode -ne 0) {
|
||||
throw("Installation of 'AspNetMvc4Setup.exe' failed. Process exit code '$($Exec.ExitCode)'")
|
||||
}
|
||||
|
||||
# Extract WebApplications folder with *.target files to
|
||||
# C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0
|
||||
Write-Log "Installing WebApplication targets ..."
|
||||
$WebApplicationsTargetsRoot = 'C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0'
|
||||
$null = New-Item -Path $WebApplicationsTargetsRoot -ItemType Container
|
||||
$Exec = Exec -FilePath $([IO.Path]::Combine($PrerequisitesPath, 'WebApplications.exe')) -ArgumentList @("-o`"$WebApplicationsTargetsRoot`"", '-y') -PassThru
|
||||
if ($Exec.ExitCode -ne 0) {
|
||||
throw("Installation of 'WebApplications.exe' failed. Process exit code '$($Exec.ExitCode)'")
|
||||
}
|
||||
|
||||
Write-Log "<-- Install-WebServer"
|
||||
}
|
||||
}
|
||||
67
data3/templates/agent/scripts/Join-Domain.ps1
Normal file
67
data3/templates/agent/scripts/Join-Domain.ps1
Normal file
@@ -0,0 +1,67 @@
|
||||
|
||||
trap {
|
||||
&$TrapHandler
|
||||
}
|
||||
|
||||
|
||||
Function Join-Domain {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Executes "Join domain" action.
|
||||
|
||||
Requires 'CoreFunctions' module.
|
||||
#>
|
||||
param (
|
||||
[String] $DomainName = '',
|
||||
[String] $UserName = '',
|
||||
[String] $Password = '',
|
||||
[String] $OUPath = '',
|
||||
[Switch] $AllowRestart
|
||||
)
|
||||
begin {
|
||||
Show-InvocationInfo $MyInvocation
|
||||
}
|
||||
end {
|
||||
Show-InvocationInfo $MyInvocation -End
|
||||
}
|
||||
process {
|
||||
trap {
|
||||
&$TrapHandler
|
||||
}
|
||||
|
||||
if ($UserName -eq '') {
|
||||
$UserName = 'Administrator'
|
||||
}
|
||||
|
||||
$Credential = New-Credential -UserName "$DomainName\$UserName" -Password $Password
|
||||
|
||||
|
||||
if (Test-ComputerName -DomainName $DomainName -ErrorAction 'SilentlyContinue') {
|
||||
Write-LogWarning "Computer already joined to domain '$DomainName'"
|
||||
}
|
||||
else {
|
||||
Write-Log "Joining computer to domain '$DomainName' ..."
|
||||
|
||||
if ($OUPath -eq '') {
|
||||
Add-Computer -DomainName $DomainName -Credential $Credential -Force
|
||||
}
|
||||
else {
|
||||
Add-Computer -DomainName $DomainName -Credential $Credential -OUPath $OUPath -Force
|
||||
}
|
||||
|
||||
$null = Exec 'ipconfig' @('/registerdns') -RedirectStreams
|
||||
|
||||
Write-Log "Waiting 30 seconds to restart ..."
|
||||
Start-Sleep -Seconds 30
|
||||
<#
|
||||
if ($AllowRestart) {
|
||||
Write-Log "Restarting computer ..."
|
||||
Restart-Computer -Force
|
||||
}
|
||||
else {
|
||||
Write-Log "Please restart the computer now."
|
||||
}
|
||||
#>
|
||||
}
|
||||
}
|
||||
}
|
||||
204
data3/templates/agent/scripts/Linux/common.sh
Normal file
204
data3/templates/agent/scripts/Linux/common.sh
Normal file
@@ -0,0 +1,204 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
DEBUGLVL=3
|
||||
LOGFILE=/tmp/muranodeployment.log
|
||||
PIPAPPS="pip python-pip pip-python"
|
||||
PIPCMD=""
|
||||
if [ "$DEBUGLVL" -eq 4 ]; then
|
||||
set -x
|
||||
fi
|
||||
function log {
|
||||
if [ "$DEBUGLVL" -gt 0 ]; then
|
||||
chars=$(echo "@$" | wc -c)
|
||||
case $DEBUGLVL in
|
||||
1 )
|
||||
echo -e "LOG:>$@"
|
||||
;;
|
||||
2)
|
||||
echo -e "$(date +"%m-%d-%Y %H:%M") LOG:>$@" | tee --append $LOGFILE
|
||||
;;
|
||||
3)
|
||||
echo -e "$(date +"%m-%d-%Y %H:%M") LOG:>$@" >> $LOGFILE
|
||||
;;
|
||||
4)
|
||||
echo -e "$(date +"%m-%d-%Y %H:%M") LOG:>$@" | tee --append $LOGFILE
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
}
|
||||
function lowercase(){
|
||||
echo "$1" | sed "y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/"
|
||||
}
|
||||
function find_pip()
|
||||
{
|
||||
for cmd in $PIPAPPS
|
||||
do
|
||||
_cmd=$(which $cmd 2>/dev/null)
|
||||
if [ $? -eq 0 ];then
|
||||
break
|
||||
fi
|
||||
done
|
||||
if [ -z $_cmd ];then
|
||||
echo "Can't find \"pip\" in system, please install it first, exiting!"
|
||||
exit 1
|
||||
else
|
||||
PIPCMD=$_cmd
|
||||
fi
|
||||
}
|
||||
OPTIND=1 # Reset if getopts used previously
|
||||
function collect_args(){
|
||||
_n=$1
|
||||
shift
|
||||
ARGS=''
|
||||
while true
|
||||
do
|
||||
if [[ "$_n" == -* ]] || [ -z "$_n" ]; then
|
||||
OPTIND=$((OPTIND - 1))
|
||||
break
|
||||
fi
|
||||
#echo "_n=$_n ; $OPTIND"
|
||||
if [ -z "$ARGS" ]; then
|
||||
ARGS=$OPTARG
|
||||
else
|
||||
ARGS="$ARGS $_n"
|
||||
fi
|
||||
eval _n=\$$OPTIND
|
||||
OPTIND=$((OPTIND + 1))
|
||||
#sleep 1
|
||||
done
|
||||
echo $ARGS
|
||||
unset _n
|
||||
unset ARGS
|
||||
}
|
||||
function get_os(){
|
||||
KERNEL=$(uname -r)
|
||||
MACH=$(uname -m)
|
||||
OS=$(uname)
|
||||
if [ "${OS}" = "Linux" ] ; then
|
||||
if [ -f /etc/redhat-release ] ; then
|
||||
DistroBasedOn='RedHat'
|
||||
Packager='yum'
|
||||
DIST=$(cat /etc/redhat-release |sed s/\ release.*//)
|
||||
PSUEDONAME=$(cat /etc/redhat-release | sed s/.*\(// | sed s/\)//)
|
||||
REV=$(cat /etc/redhat-release | sed s/.*release\ // | sed s/\ .*//)
|
||||
elif [ -f /etc/SuSE-release ] ; then
|
||||
DistroBasedOn='SuSe'
|
||||
Packager='zypper'
|
||||
PSUEDONAME=$(cat /etc/SuSE-release | tr "\n" ' '| sed s/VERSION.*//)
|
||||
REV=$(cat /etc/SuSE-release | tr "\n" ' ' | sed s/.*=\ //)
|
||||
elif [ -f /etc/mandrake-release ] ; then
|
||||
DistroBasedOn='Mandrake'
|
||||
Packager='urpmi urpme'
|
||||
PSUEDONAME=$(cat /etc/mandrake-release | sed s/.*\(// | sed s/\)//)
|
||||
REV=$(cat /etc/mandrake-release | sed s/.*release\ // | sed s/\ .*//)
|
||||
elif [ -f /etc/debian_version ] ; then
|
||||
DistroBasedOn='Debian'
|
||||
Packager='apt-get'
|
||||
DIST=$(cat /etc/lsb-release | grep '^DISTRIB_ID' | awk -F= '{ print $2 }')
|
||||
PSUEDONAME=$(cat /etc/lsb-release | grep '^DISTRIB_CODENAME' | awk -F= '{ print $2 }')
|
||||
REV=$(cat /etc/lsb-release | grep '^DISTRIB_RELEASE' | awk -F= '{ print $2 }')
|
||||
fi
|
||||
if [ -f /etc/UnitedLinux-release ] ; then
|
||||
DIST="${DIST}[$(cat /etc/UnitedLinux-release | tr "\n" ' ' | sed s/VERSION.*//)]"
|
||||
fi
|
||||
OS=$(lowercase $OS)
|
||||
DistroBasedOn=$(lowercase $DistroBasedOn)
|
||||
readonly OS
|
||||
readonly DIST
|
||||
readonly DistroBasedOn
|
||||
readonly PSUEDONAME
|
||||
readonly REV
|
||||
readonly KERNEL
|
||||
readonly MACH
|
||||
#readonly Packager
|
||||
else
|
||||
OS=unknown
|
||||
readonly OS
|
||||
log "OS:$OS"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
function add_fw_rule(){
|
||||
_rule_string=$@
|
||||
_tmp_fw_port=$(echo $_rule_string | grep -o -e "dport [0-9]*\s")
|
||||
_tmp_fw_proto=$(echo $_rule_string | grep -o -e "-p \w*\s")
|
||||
_fw_port=$(echo $_tmp_fw_port | awk '{print $2}')
|
||||
_fw_proto=$(echo $_tmp_fw_proto |awk '{print $2}')
|
||||
_fw_reload=""
|
||||
#find iptables and add rule
|
||||
case $DIST in
|
||||
"Fedora")
|
||||
_fw_cmd=$(which firewall-cmd)
|
||||
_fw_port=$(echo $_rule_string | grep -o -e "dport [0-9]*\s" | awk '{print $2}')
|
||||
_fw_proto=$(echo $_rule_string | grep -o -e "-p \w*\s" | awk '{print $2}')
|
||||
_fw_rule="--permanent --add-port=$_fw_port/$_fw_proto"
|
||||
_fw_enable_rules="$_fw_cmd --reload"
|
||||
;;
|
||||
*)
|
||||
_fw_cmd=$(which iptables)
|
||||
_fw_rule=$_rule_string
|
||||
_fw_enable_rules="service $_fw_cmd save"
|
||||
;;
|
||||
esac
|
||||
iptcmdsave=$(which iptables-save)
|
||||
if [[ "$_fw_cmd" != '' ]] && [[ "$iptcmdsave" != '' ]]; then
|
||||
eval "$iptcmdsave | grep -e \"$_tmp_fw_port\" | grep -e \"$_tmp_fw_proto\"" > /dev/null 2>&1
|
||||
if [ $? -ne 0 ]; then
|
||||
eval $_fw_cmd $_fw_rule
|
||||
if [ $? -ne 0 ]; then
|
||||
log "Can't set firewall rules, exiting..."
|
||||
exit 1
|
||||
else
|
||||
if [ -n "$_fw_enable_rules" ]; then
|
||||
log "Running \"$_fw_enable_rules\""
|
||||
$_fw_enable_rules > /dev/null
|
||||
fi
|
||||
log "$_fw_cmd rule with $_fw_rule set."
|
||||
fi
|
||||
else
|
||||
log "$_fw_cmd rule exists."
|
||||
fi
|
||||
else
|
||||
log "There are no fw found..."
|
||||
fi
|
||||
}
|
||||
function enable_init(){
|
||||
_initctrl=""
|
||||
_init_suffix=""
|
||||
_service=$1
|
||||
case $DistroBasedOn in
|
||||
"debian")
|
||||
_initctrl="update-rc.d"
|
||||
_init_suffix="defaults"
|
||||
;;
|
||||
*)
|
||||
_initctrl="chkconfig"
|
||||
_init_suffix="on"
|
||||
;;
|
||||
esac
|
||||
$_initctrl $_service $_init_suffix
|
||||
if [ $? -ne 0 ]; then
|
||||
log "$_initctrl $_service $_init_suffix - fails!"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
function restart_service(){
|
||||
_service=$1
|
||||
service $_service restart > /dev/null 2>&1
|
||||
if [ $? -ne 0 ]; then
|
||||
log "Can't start $_service service!"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
function package_renamer(){
|
||||
_pkg=$1
|
||||
case $DistroBasedOn in
|
||||
"debian")
|
||||
_pkg=$(echo $_pkg | sed 's/-devel$/-dev/')
|
||||
;;
|
||||
*)
|
||||
_pkg=$(echo $_pkg | sed 's/-dev$/-devel/')
|
||||
;;
|
||||
esac
|
||||
echo $_pkg
|
||||
}
|
||||
142
data3/templates/agent/scripts/Linux/installer.sh
Normal file
142
data3/templates/agent/scripts/Linux/installer.sh
Normal file
@@ -0,0 +1,142 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
INSTALLER_OPTS=""
|
||||
UNINSTALLER_OPTS=""
|
||||
PMGR=""
|
||||
PMGR_LIST_OPTS=""
|
||||
|
||||
function include(){
|
||||
curr_dir=$(cd $(dirname "$0") && pwd)
|
||||
inc_file_Path=$curr_dir/$1
|
||||
if [ -f "$inc_file_Path" ]; then
|
||||
. $inc_file_Path
|
||||
else
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
function set_install_options(){
|
||||
case $1 in
|
||||
apt-get )
|
||||
INSTALLER_OPTS="-y -q install"
|
||||
UNINSTALLER_OPTS="-y -q remove"
|
||||
PMGR="dpkg"
|
||||
PMGR_LIST_OPTS="-s"
|
||||
;;
|
||||
yum )
|
||||
INSTALLER_OPTS="--assumeyes install"
|
||||
UNINSTALLER_OPTS="--assumeyes erase"
|
||||
PMGR="rpm"
|
||||
PMGR_LIST_OPTS="-q"
|
||||
;;
|
||||
urpm* )
|
||||
INSTALLER_OPTS="-y"
|
||||
UNINSTALLER_OPTS=""
|
||||
PMGR="rpm"
|
||||
PMGR_LIST_OPTS="-q"
|
||||
;;
|
||||
zypper )
|
||||
INSTALLER_OPTS="install"
|
||||
UNINSTALLER_OPTS="remove --quiet"
|
||||
PMGR="rpm"
|
||||
PMGR_LIST_OPTS="-q"
|
||||
;;
|
||||
pip )
|
||||
INSTALLER_OPTS="install"
|
||||
UNINSTALLER_OPTS="uninstall --yes"
|
||||
find_pip
|
||||
PACKAGER=$PIPCMD
|
||||
PMGR=$PIPCMD
|
||||
PMGR_LIST_OPTS="freeze | grep"
|
||||
;;
|
||||
* )
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
PACKAGER=$(which $1)
|
||||
if [ $? -ne 0 ]; then
|
||||
log "Can't find \"$1\", exiting!"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
function package_install(){
|
||||
PKG=$1
|
||||
eval "$PMGR $PMGR_LIST_OPTS $PKG" > /dev/null 2>&1
|
||||
if [ $? -eq 0 ]; then
|
||||
log "\"$PKG\" already installed"
|
||||
else
|
||||
log "Installing \"$PKG\" ..."
|
||||
$PACKAGER $INSTALLER_OPTS $PKG > /dev/null 2>&1
|
||||
if [ $? -ne 0 ]; then
|
||||
log "\"$PKG\" installation fails, exiting!"
|
||||
exit 1
|
||||
else
|
||||
log "\t\t...success"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
function package_uninstall(){
|
||||
PKG=$1
|
||||
eval "$PMGR $PMGR_LIST_OPTS $PKG" > /dev/null 2>&1
|
||||
if [ $? -eq 1 ]; then
|
||||
log "\"$PKG\" not installed"
|
||||
else
|
||||
log "Unnstalling \"$PKG\" ..."
|
||||
$PACKAGER $UNINSTALLER_OPTS $PKG > /dev/null 2>&1
|
||||
if [ $? -ne 0 ]; then
|
||||
log "\"$PKG\" uninstallation fails, exiting!"
|
||||
exit 1
|
||||
else
|
||||
log "\t\t...success"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
function run_install(){
|
||||
for PKG in $@
|
||||
do
|
||||
package_install $PKG
|
||||
done
|
||||
}
|
||||
function run_uninstall(){
|
||||
for PKG in $@
|
||||
do
|
||||
package_uninstall $PKG
|
||||
done
|
||||
}
|
||||
# Main workflow
|
||||
include "common.sh"
|
||||
if [ $# -eq 0 ]; then
|
||||
script=$(basename $0)
|
||||
echo -e "Usage:\n\t* install packages -- ./$script -p package_manager -i package0 [packageN]\n\t* remove packages -- ./$script -p package_manager -r package0 [packageN]"
|
||||
exit 1
|
||||
fi
|
||||
Packager=''
|
||||
get_os
|
||||
if [ $? -ne 0 ]; then
|
||||
log "Unsupported *nix version ($DistroBasedOn - $DIST/$PSUEDONAME/$REV/$MACH)"
|
||||
exit 1
|
||||
fi
|
||||
while getopts ":p:i:r:" opt ; do
|
||||
case "$opt" in
|
||||
p)
|
||||
if [[ "$OPTARG" != sys ]]; then
|
||||
Packager=$OPTARG
|
||||
fi
|
||||
set_install_options $Packager
|
||||
;;
|
||||
i)
|
||||
n=$OPTARG
|
||||
run_install $(collect_args $n $@)
|
||||
break;
|
||||
;;
|
||||
r)
|
||||
n=$OPTARG
|
||||
run_uninstall $(collect_args $n $@)
|
||||
break;
|
||||
;;
|
||||
\?)
|
||||
log "Invalid option: -$OPTARG" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
shift $((OPTIND-1))
|
||||
37
data3/templates/agent/scripts/Linux/runApacheDeploy.sh
Normal file
37
data3/templates/agent/scripts/Linux/runApacheDeploy.sh
Normal file
@@ -0,0 +1,37 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
function include(){
|
||||
curr_dir=$(cd $(dirname "$0") && pwd)
|
||||
inc_file_path=$curr_dir/$1
|
||||
if [ -f "$inc_file_path" ]; then
|
||||
. $inc_file_path
|
||||
else
|
||||
echo -e "$inc_file_path not found!"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
include "common.sh"
|
||||
# FirewallRules
|
||||
FW_RULE1='-I INPUT 1 -p tcp -m tcp --dport 443 -j ACCEPT -m comment --comment "by murano, Apache server access on HTTPS port 443"'
|
||||
FW_RULE2='-I INPUT 1 -p tcp -m tcp --dport 80 -j ACCEPT -m comment --comment "by murano, Apache server access on HTTP port 80"'
|
||||
APP=''
|
||||
get_os
|
||||
[[ $? -ne 0 ]] && exit 1
|
||||
case $DistroBasedOn in
|
||||
"debian")
|
||||
APP="apache2"
|
||||
;;
|
||||
"redhat")
|
||||
APP="httpd"
|
||||
;;
|
||||
esac
|
||||
_php=""
|
||||
if [[ "$1" == "True" ]]; then
|
||||
_php="php"
|
||||
fi
|
||||
APPS_TO_INSTALL="$APP $_php $FW_BOOT_PKG"
|
||||
bash installer.sh -p sys -i $APPS_TO_INSTALL
|
||||
enable_init $APP
|
||||
service $APP start > /dev/null 2>&1
|
||||
add_fw_rule $FW_RULE1
|
||||
add_fw_rule $FW_RULE2
|
||||
63
data3/templates/agent/scripts/Linux/runTelnetDeploy.sh
Normal file
63
data3/templates/agent/scripts/Linux/runTelnetDeploy.sh
Normal file
@@ -0,0 +1,63 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
function include(){
|
||||
curr_dir=$(cd $(dirname "$0") && pwd)
|
||||
inc_file_path=$curr_dir/$1
|
||||
if [ -f "$inc_file_Path" ]; then
|
||||
. $inc_file_path
|
||||
else
|
||||
echo -e "$inc_file_path not found!"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
include "common.sh"
|
||||
# FirewallRules
|
||||
FW_RULE1='-I INPUT 1 -p tcp -m tcp --dport 23 -j ACCEPT -m comment --comment "by murano, Telnet server access on port 23"'
|
||||
APP=''
|
||||
get_os
|
||||
[[ $? -ne 0 ]] && exit 1
|
||||
case $DistroBasedOn in
|
||||
"debian")
|
||||
APP="telnetd"
|
||||
;;
|
||||
"redhat")
|
||||
APP="telnet-server"
|
||||
;;
|
||||
esac
|
||||
APPS_TO_INSTALL="$APP"
|
||||
bash installer.sh -p sys -i $APPS_TO_INSTALL
|
||||
xinetd_tlnt_cfg="/etc/xinetd.d/telnet"
|
||||
if [ -f "$xinetd_tlnt_cfg" ]; then
|
||||
sed -i '/disable.*=/ s/yes/no/' $xinetd_tlnt_cfg
|
||||
if [ $? -ne 0 ]; then
|
||||
log "can't modify $xinetd_tlnt_cfg"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
log "$APP startup config not found under $xinetd_tlnt_cfg"
|
||||
fi
|
||||
#security tty for telnet
|
||||
setty=/etc/securetty
|
||||
lines=$(sed -ne '/^pts\/[0-9]/,/^pts\/[0-9]/ =' $setty)
|
||||
if [ -z "$lines" ]; then
|
||||
cat >> $setty << "EOF"
|
||||
pts/0
|
||||
pts/1
|
||||
pts/2
|
||||
pts/3
|
||||
pts/4
|
||||
pts/5
|
||||
pts/6
|
||||
pts/7
|
||||
pts/8
|
||||
pts/9
|
||||
EOF
|
||||
if [ $? -ne 0 ]; then
|
||||
log "Error occured during $setty changing..."
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
echo "$setty has pts/0-9 options..."
|
||||
fi
|
||||
restart_service xinetd
|
||||
add_fw_rule $FW_RULE1
|
||||
64
data3/templates/agent/scripts/New-SqlServerSystemAccount.ps1
Normal file
64
data3/templates/agent/scripts/New-SqlServerSystemAccount.ps1
Normal file
@@ -0,0 +1,64 @@
|
||||
|
||||
trap {
|
||||
&$TrapHandler
|
||||
}
|
||||
|
||||
|
||||
|
||||
function New-SqlServerSystemAccount {
|
||||
param (
|
||||
# (REQUIRED) Domain Name
|
||||
[Parameter(Mandatory=$true)]
|
||||
[String] $DomainName,
|
||||
|
||||
# (REQUIRED) User name who has permissions to create and modify userPassword
|
||||
# Usually this is the domain administrator '$domainName\Administrator' account
|
||||
[Parameter(Mandatory=$true)]
|
||||
[String] $UserName,
|
||||
|
||||
# (REQUIRED) Password for that user
|
||||
[Parameter(Mandatory=$true)]
|
||||
[String] $UserPassword,
|
||||
|
||||
# (REQUIRED) User name for a new account that will be used to run SQL Server
|
||||
[Parameter(Mandatory=$true)]
|
||||
[String] $SQLServiceUserName,
|
||||
|
||||
# (REQUIRED) Password for that user
|
||||
[Parameter(Mandatory=$true)]
|
||||
[String] $SQLServiceUserPassword,
|
||||
|
||||
[String] $PrimaryNode = ' '
|
||||
)
|
||||
begin {
|
||||
Show-InvocationInfo $MyInvocation
|
||||
}
|
||||
end {
|
||||
Show-InvocationInfo $MyInvocation -End
|
||||
}
|
||||
process {
|
||||
trap {
|
||||
&$TrapHandler
|
||||
}
|
||||
|
||||
if ($PrimaryNode.ToLower() -ne ($Env:ComputerName).ToLower()) {
|
||||
Write-Log "THis function runs on AOAG primary node only."
|
||||
Write-Log "Exiting."
|
||||
return
|
||||
}
|
||||
|
||||
Write-Log "Installing 'RSAT-AD-PowerShell' ... "
|
||||
Add-WindowsFeature RSAT-AD-PowerShell
|
||||
|
||||
Import-Module ActiveDirectory
|
||||
|
||||
$Creds = New-Credential -UserName "$DomainName\$UserName" -Password "$UserPassword"
|
||||
|
||||
Write-Log "Adding new user ..."
|
||||
$null = New-ADUser `
|
||||
-Name $SQLServiceUserName `
|
||||
-AccountPassword $(ConvertTo-SecureString -String $SQLServiceUserPassword -AsPlainText -Force) `
|
||||
-Credential $Creds `
|
||||
-ErrorAction 'Stop'
|
||||
}
|
||||
}
|
||||
280
data3/templates/agent/scripts/OptionParser.ps1
Normal file
280
data3/templates/agent/scripts/OptionParser.ps1
Normal file
@@ -0,0 +1,280 @@
|
||||
function New-Option ([string]$Name, [switch]$Switch, [switch]$Boolean, [switch]$String, [switch]$List, $Constraints=$null) {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Creates Option object
|
||||
|
||||
.DESCRIPTION
|
||||
Option object is a virtual object represtnting typed command line option. These objects encapsulate escaping and
|
||||
validation matters.
|
||||
|
||||
One and only one of the switches 'Switch', 'Boolean', 'String' or 'List' should be provided.
|
||||
|
||||
.PARAMETER Name
|
||||
Option name as it appears in the command line.
|
||||
|
||||
.PARAMETER Switch
|
||||
Use this switch to create valueless option (a switch).
|
||||
|
||||
.PARAMETER Boolean
|
||||
Use this switch to create boolean option. Its value is always converted to "1" or "0"
|
||||
|
||||
.PARAMETER String
|
||||
Use this switch to create string option. Its value will be properly quoted if necessary.
|
||||
|
||||
.PARAMETER List
|
||||
Use this switch to create option with list value. Values will be put into command line using valid value delemiter (a comma)
|
||||
|
||||
.PARAMETER Constraints
|
||||
When this parameter is specified, option values are limited to options from that list.
|
||||
|
||||
#>
|
||||
|
||||
$Option = New-Object -TypeName PSObject
|
||||
|
||||
# Fields
|
||||
$Option | Add-Member NoteProperty Type -value $null
|
||||
$Option | Add-Member NoteProperty Name -value $null
|
||||
$Option | Add-Member NoteProperty AllowedValues -value $null
|
||||
|
||||
# Init
|
||||
|
||||
$Option | Add-Member ScriptMethod __init__ {
|
||||
param([string]$Name, $Switch, $Boolean, $String, $List)
|
||||
|
||||
$this.Name = $Name
|
||||
|
||||
# With respect for our developers we do not check for double type selected
|
||||
if ($Switch) {
|
||||
AugmentOptionSwitch($this)
|
||||
} elseif ($Boolean) {
|
||||
AugmentOptionBoolean($this)
|
||||
} elseif ($String) {
|
||||
AugmentOptionString($this)
|
||||
} elseif ($List) {
|
||||
AugmentOptionList($this)
|
||||
} else {
|
||||
throw "Switch, Boolean, String or List option type must be provided for option '$Name'"
|
||||
}
|
||||
}
|
||||
|
||||
$Option | Add-Member ScriptMethod __post_init__ {
|
||||
param($Constraints=$null)
|
||||
if ($Constraints -ne $null) {
|
||||
$this.AllowedValues = @()
|
||||
$this.AllowedValues = $this.AllowedValues + $Constraints
|
||||
} else {
|
||||
$Constraints = $null
|
||||
}
|
||||
}
|
||||
|
||||
# Methods
|
||||
|
||||
$Option | Add-Member -Force ScriptMethod Validate {
|
||||
if ($this.AllowedValues -ne $null) {
|
||||
if (-not($this.AllowedValues -contains $this.Value)) {
|
||||
$Cts = $this.AllowedValues -join ','
|
||||
throw "Option '$($this.Name)' may have values ($Cts) but not '$($this.Value)'"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$Option | Add-Member -Force ScriptMethod ToString {
|
||||
return "/$($this.Name)"
|
||||
}
|
||||
|
||||
# invoke constructor
|
||||
|
||||
$Option.__init__($Name, $Switch, $Boolean, $String, $List)
|
||||
$Option.__post_init__($Constraints)
|
||||
|
||||
return $Option
|
||||
}
|
||||
|
||||
function AugmentOptionSwitch($Option) {
|
||||
}
|
||||
|
||||
function AugmentOptionBoolean($Option) {
|
||||
# Fields
|
||||
$Option | Add-Member NoteProperty Value -value $false
|
||||
|
||||
# Methods
|
||||
|
||||
$Option | Add-Member -Force ScriptMethod ToString {
|
||||
if ($this.Value) {
|
||||
return "/$($this.Name)=1"
|
||||
} else {
|
||||
return "/$($this.Name)=0"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function AugmentOptionString($Option) {
|
||||
# Fields
|
||||
$Option | Add-Member NoteProperty Value -value ""
|
||||
|
||||
# Methods
|
||||
|
||||
$Option | Add-Member -Force ScriptMethod ToString {
|
||||
$v = "$($this.Value)"
|
||||
if ($v -match '.* .*') {
|
||||
# TODO: Escape double quote characters if possible
|
||||
return "/$($this.Name)=`"$v`""
|
||||
} else {
|
||||
return "/$($this.Name)=$v"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function AugmentOptionList($Option) {
|
||||
# Fields
|
||||
$Option | Add-Member NoteProperty Value -value @()
|
||||
|
||||
# Methods
|
||||
|
||||
$Option | Add-Member -Force ScriptMethod Validate {
|
||||
if ($this.AllowedValues -ne $null) {
|
||||
foreach ($V in $this.Value) {
|
||||
if (-not($this.AllowedValues -contains $V)) {
|
||||
$Cts = $this.AllowedValues -join ','
|
||||
throw "Option '$($this.Name)' may have values ($Cts) but not '$V'"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$Option | Add-Member -Force ScriptMethod ToString {
|
||||
return "/$($this.Name)=$($this.Value -join ',')"
|
||||
}
|
||||
}
|
||||
|
||||
function New-OptionParser() {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Creates OptionParser object.
|
||||
|
||||
.DESCRIPTION
|
||||
OptionParser object leverages Option objects capabilities and builds valid command line using specified options.
|
||||
An application may also be invoked with OptionParser.
|
||||
|
||||
#>
|
||||
|
||||
$OptionParser = New-Object -TypeName PSObject
|
||||
|
||||
# Fields
|
||||
$OptionParser | Add-Member NoteProperty Options -value @{}
|
||||
$OptionParser | Add-Member NoteProperty Defaults -value @{}
|
||||
$OptionParser | Add-Member NoteProperty RequiredOptions -value @()
|
||||
|
||||
# Methods
|
||||
|
||||
$OptionParser | Add-Member ScriptMethod AddOption {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Adds supported option into OptionParser.
|
||||
|
||||
.DESCRIPTION
|
||||
OptionParser does not allow using unrecognized options. Use this method to fill OptionParser with recognized options
|
||||
|
||||
.PARAMETER Option
|
||||
Option object
|
||||
|
||||
.PARAMETER Required
|
||||
Required option switch
|
||||
|
||||
.PARAMETER Default
|
||||
Option default value
|
||||
#>
|
||||
param($Option, [bool]$Required=$false, $Default=$null)
|
||||
$this.Options.Add($Option.Name, $Option)
|
||||
if ($Required) {
|
||||
$this.RequiredOptions = $this.RequiredOptions + $Option.Name
|
||||
if ($Option | Get-Member "Value") {
|
||||
if ($Default) {
|
||||
$this.Defaults.Add($Option.Name, $Default)
|
||||
}
|
||||
} else {
|
||||
$this.Defaults.Add($Option.Name, $null)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$OptionParser | Add-Member ScriptMethod Parse {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Parses supplied options and returns command line parameters array.
|
||||
|
||||
.DESCRIPTION
|
||||
This method verifies that only supported options are provided, all mandatory options are in place,
|
||||
all option meet constraints if any. Unspecified options with default values are added to command line.
|
||||
So, mandatory option with default value never causes exception.
|
||||
|
||||
.PARAMETER Options
|
||||
A hash map of options to parse. Option names should be mapped to corresponding values.
|
||||
#>
|
||||
param([hashtable]$Options)
|
||||
|
||||
$CommandLine = @()
|
||||
foreach ($RequiredOptionName in $this.RequiredOptions) {
|
||||
if (-not $Options.ContainsKey($RequiredOptionName)) {
|
||||
$Default = $this.Defaults.Get_Item($RequiredOptionName)
|
||||
if ($this.Defaults.ContainsKey($RequiredOptionName)) {
|
||||
$Options.Add($RequiredOptionName, $this.Defaults.Get_Item($RequiredOptionName))
|
||||
} else {
|
||||
throw "Required option '$RequiredOptionName' is missing"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($OptionName in $($Options.keys)) {
|
||||
$Option = $this.Options.Get_Item($OptionName)
|
||||
if ($Option -eq $null) {
|
||||
throw "Option '$OptionName' is not allowed"
|
||||
}
|
||||
if ($Option | Get-Member "Value") {
|
||||
$Option.Value = $Options.Get_Item($OptionName)
|
||||
}
|
||||
$Option.Validate()
|
||||
$CommandLine = $CommandLine + $Option.ToString()
|
||||
}
|
||||
return $CommandLine
|
||||
}
|
||||
|
||||
$OptionParser | Add-Member ScriptMethod ExecuteBinary {
|
||||
param($Binary, [hashtable]$Options = @{}, $CommandLineSuffix = @())
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Executes binary with a command line constructed from provided options. An arbitrary suffix may be
|
||||
appended to the command line.
|
||||
|
||||
.DESCRIPTION
|
||||
This method uses OptionParser.Parse method to construct command line. If there a command line suffix
|
||||
was supplied, it is appended to the end of command line. Normally command line suffix should contain
|
||||
leading space character.
|
||||
|
||||
Method waits for executable process to complete and returns its exit code.
|
||||
|
||||
.PARAMETER Binary
|
||||
Full or relative path to the executable to run.
|
||||
|
||||
.PARAMETER Options
|
||||
A hash map of options to pass to the executable.
|
||||
|
||||
.PARAMETER CommandLineSuffix
|
||||
Arbitrary command line suffix. Normally it shoud have leading space character.
|
||||
#>
|
||||
|
||||
$Binary = Get-Item $Binary
|
||||
$CommandLine = $this.Parse($Options)
|
||||
if ($CommandLineSuffix) {
|
||||
$CommandLine = $CommandLine + $CommandLineSuffix
|
||||
}
|
||||
|
||||
Write-Log "Executing: $($Binary.FullName) $($CommandLine -join ' ')"
|
||||
$process = [System.Diagnostics.Process]::Start($Binary, $CommandLine)
|
||||
$process.WaitForExit()
|
||||
$process.Refresh()
|
||||
return $process.ExitCode
|
||||
}
|
||||
|
||||
return $OptionParser
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
|
||||
trap {
|
||||
&$TrapHandler
|
||||
}
|
||||
|
||||
|
||||
|
||||
Function ConvertTo-Boolean {
|
||||
param (
|
||||
$InputObject,
|
||||
[Boolean] $Default = $false
|
||||
)
|
||||
try {
|
||||
[System.Convert]::ToBoolean($InputObject)
|
||||
}
|
||||
catch {
|
||||
$Default
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Function Show-Environment {
|
||||
foreach ($item in (Get-ChildItem Env:)) {
|
||||
Write-Log ("'{0}' --> '{1}'" -f $item.Name, $item.Value)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Function Install-SqlServer {
|
||||
param (
|
||||
[String] $SetupRoot = '',
|
||||
[String] $SAPassword = '',
|
||||
[String] $MuranoFileShare = '',
|
||||
[Switch] $MixedModeAuth = $false,
|
||||
[Switch] $UpdateEnabled = $false
|
||||
)
|
||||
begin {
|
||||
Show-InvocationInfo $MyInvocation
|
||||
}
|
||||
end {
|
||||
Show-InvocationInfo $MyInvocation -End
|
||||
}
|
||||
process {
|
||||
trap {
|
||||
&$TrapHandler
|
||||
}
|
||||
|
||||
if ($SetupRoot -eq '') {
|
||||
if ($MuranoFileShare -eq '') {
|
||||
$MuranoFileShare = [Environment]::GetEnvironmentVariable('MuranoFileShare')
|
||||
if ($MuranoFileShare -eq '') {
|
||||
throw("Unable to find MuranoFileShare path.")
|
||||
}
|
||||
}
|
||||
|
||||
$SetupRoot = [IO.Path]::Combine($MuranoFileShare, 'Prerequisites\SQL Server\2012')
|
||||
}
|
||||
|
||||
#$MixedModeAuthSwitch = ConvertTo-Boolean $MixedModeAuth
|
||||
|
||||
$ExtraOptions = @{}
|
||||
|
||||
if ($MixedModeAuth -eq $true) {
|
||||
$ExtraOptions += @{'SECURITYMODE' = 'SQL'}
|
||||
if ($SAPassword -eq '') {
|
||||
throw("SAPassword must be set when MixedModeAuth is requisted!")
|
||||
}
|
||||
}
|
||||
|
||||
if ($SAPassword -ne '') {
|
||||
$ExtraOptions += @{'SAPWD' = $SAPassword}
|
||||
}
|
||||
|
||||
if (-not $UpdateEnabled) {
|
||||
$ExtraOptions += @{'UpdateEnabled' = $false}
|
||||
}
|
||||
|
||||
Show-Environment
|
||||
|
||||
New-SqlServer -SetupRoot $SetupRoot -ExtraOptions $ExtraOptions
|
||||
}
|
||||
}
|
||||
1373
data3/templates/agent/scripts/SQLServer/SQLServerInstaller.ps1
Normal file
1373
data3/templates/agent/scripts/SQLServer/SQLServerInstaller.ps1
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,367 @@
|
||||
function New-OptionParserInstall {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Creates an option parser for MS SQL Server 2012 setup "INSTALL" action.
|
||||
|
||||
.DESCRIPTION
|
||||
Use this cmdlet to create an option parser for MS SQL Server 2012 setup "INSTALL" action.
|
||||
All documented option are supported. See the following link for details:
|
||||
http://msdn.microsoft.com/en-us/library/ms144259.aspx
|
||||
#>
|
||||
$OptionParser = New-OptionParser
|
||||
|
||||
$IsPartOfDomain = (Get-WmiObject Win32_ComputerSystem).PartOfDomain
|
||||
|
||||
$OptionParser.AddOption((New-Option "ACTION" -String -Constraints "INSTALL"), $true, "INSTALL")
|
||||
$OptionParser.AddOption((New-Option "IACCEPTSQLSERVERLICENSETERMS" -Switch), $true)
|
||||
$OptionParser.AddOption((New-Option "ENU" -Switch))
|
||||
#$OptionParser.AddOption((New-Option "UpdateEnabled" -Switch))
|
||||
$OptionParser.AddOption((New-Option "UpdateEnabled" -Boolean))
|
||||
$OptionParser.AddOption((New-Option "UpdateSource" -String))
|
||||
$OptionParser.AddOption((New-Option "CONFIGURATIONFILE" -String))
|
||||
$OptionParser.AddOption((New-Option "ERRORREPORTING" -Boolean))
|
||||
$OptionParser.AddOption((New-Option "FEATURES" -List -Constraints ("SQL","SQLEngine","Replication","FullText","DQ","AS","RS","DQC","IS","MDS","Tools","BC","BOL","BIDS","Conn","SSMS","ADV_SSMS","DREPLAY_CTLR","DREPLAY_CLT","SNAC_SDK","SDK","LocalDB")))
|
||||
$OptionParser.AddOption((New-Option "ROLE" -String -Constraints ("SPI_AS_ExistingFarm", "SPI_AS_NewFarm", "AllFeatures_WithDefaults")))
|
||||
$OptionParser.AddOption((New-Option "INDICATEPROGRESS" -Switch))
|
||||
$OptionParser.AddOption((New-Option "INSTALLSHAREDDIR" -String))
|
||||
$OptionParser.AddOption((New-Option "INSTALLSHAREDWOWDIR" -String))
|
||||
$OptionParser.AddOption((New-Option "INSTANCEDIR" -String))
|
||||
$OptionParser.AddOption((New-Option "INSTANCEID" -String))
|
||||
$OptionParser.AddOption((New-Option "INSTANCENAME" -String), $true, "MSSQLSERVER")
|
||||
$OptionParser.AddOption((New-Option "PID" -String))
|
||||
$OptionParser.AddOption((New-Option "Q" -Switch))
|
||||
$OptionParser.AddOption((New-Option "QS" -Switch))
|
||||
$OptionParser.AddOption((New-Option "UIMODE" -String -Constraints ("Normal", "AutoAdvance")))
|
||||
$OptionParser.AddOption((New-Option "SQMREPORTING" -Boolean))
|
||||
$OptionParser.AddOption((New-Option "HIDECONSOLE" -Switch))
|
||||
$OptionParser.AddOption((New-Option "AGTSVCACCOUNT" -String), $true, "NT AUTHORITY\Network Service")
|
||||
$OptionParser.AddOption((New-Option "AGTSVCPASSWORD" -String))
|
||||
$OptionParser.AddOption((New-Option "AGTSVCSTARTUPTYPE" -String -Constraints ("Manual", "Automatic", "Disabled")))
|
||||
$OptionParser.AddOption((New-Option "ASBACKUPDIR" -String))
|
||||
$OptionParser.AddOption((New-Option "ASCOLLATION" -String))
|
||||
$OptionParser.AddOption((New-Option "ASCONFIGDIR" -String))
|
||||
$OptionParser.AddOption((New-Option "ASDATADIR" -String))
|
||||
$OptionParser.AddOption((New-Option "ASLOGDIR" -String))
|
||||
$OptionParser.AddOption((New-Option "ASSERVERMODE" -String -Constraints ("MULTIDIMENSIONAL", "POWERPIVOT", "TABULAR")))
|
||||
$OptionParser.AddOption((New-Option "ASSVCACCOUNT" -String), $true, "NT AUTHORITY\Network Service")
|
||||
$OptionParser.AddOption((New-Option "ASSVCPASSWORD" -String))
|
||||
$OptionParser.AddOption((New-Option "ASSVCSTARTUPTYPE" -String -Constraints ("Manual", "Automatic", "Disabled")))
|
||||
|
||||
#$OptionParser.AddOption((New-Option "ASSYSADMINACCOUNTS" -String), $true, "$ENV:USERDOMAIN\$ENV:USERNAME")
|
||||
if ($IsPartOfDomain) {
|
||||
$OptionParser.AddOption((New-Option "ASSYSADMINACCOUNTS" -String), $true, "$Env:USERDOMAIN\Administrator")
|
||||
}
|
||||
else {
|
||||
$OptionParser.AddOption((New-Option "ASSYSADMINACCOUNTS" -String), $true, "$Env:COMPUTERNAME\Administrator")
|
||||
}
|
||||
|
||||
$OptionParser.AddOption((New-Option "ASTEMPDIR" -String))
|
||||
$OptionParser.AddOption((New-Option "ASPROVIDERMSOLAP" -Boolean))
|
||||
$OptionParser.AddOption((New-Option "FARMACCOUNT" -String))
|
||||
$OptionParser.AddOption((New-Option "FARMPASSWORD" -String))
|
||||
$OptionParser.AddOption((New-Option "PASSPHRASE" -String))
|
||||
$OptionParser.AddOption((New-Option "FARMADMINIPORT" -String))
|
||||
$OptionParser.AddOption((New-Option "BROWSERSVCSTARTUPTYPE" -String -Constraints ("Manual", "Automatic", "Disabled")))
|
||||
$OptionParser.AddOption((New-Option "ENABLERANU" -Switch))
|
||||
$OptionParser.AddOption((New-Option "INSTALLSQLDATADIR" -String))
|
||||
$OptionParser.AddOption((New-Option "SAPWD" -String))
|
||||
$OptionParser.AddOption((New-Option "SECURITYMODE" -String -Constrainrs ("SQL")))
|
||||
$OptionParser.AddOption((New-Option "SQLBACKUPDIR" -String))
|
||||
$OptionParser.AddOption((New-Option "SQLCOLLATION" -String))
|
||||
$OptionParser.AddOption((New-Option "ADDCURRENTUSERASSQLADMIN" -Switch))
|
||||
$OptionParser.AddOption((New-Option "SQLSVCACCOUNT" -String), $true, "NT AUTHORITY\Network Service")
|
||||
$OptionParser.AddOption((New-Option "SQLSVCPASSWORD" -String))
|
||||
$OptionParser.AddOption((New-Option "SQLSVCSTARTUPTYPE" -String -Constraints ("Manual", "Automatic", "Disabled")))
|
||||
|
||||
#$OptionParser.AddOption((New-Option "SQLSYSADMINACCOUNTS" -String), $true, "$ENV:USERDOMAIN\$ENV:USERNAME")
|
||||
if ($IsPartOfDomain) {
|
||||
$OptionParser.AddOption((New-Option "SQLSYSADMINACCOUNTS" -String), $true, "$ENV:USERDOMAIN\Administrator")
|
||||
}
|
||||
else {
|
||||
$OptionParser.AddOption((New-Option "SQLSYSADMINACCOUNTS" -String), $true, "$ENV:COMPUTERNAME\Administrator")
|
||||
}
|
||||
|
||||
$OptionParser.AddOption((New-Option "SQLTEMPDBDIR" -String))
|
||||
$OptionParser.AddOption((New-Option "SQLTEMPDBLOGDIR" -String))
|
||||
$OptionParser.AddOption((New-Option "SQLUSERDBDIR" -String))
|
||||
$OptionParser.AddOption((New-Option "SQLUSERDBLOGDIR" -String))
|
||||
$OptionParser.AddOption((New-Option "FILESTREAMLEVEL" -String -Constraints ("0", "1", "2", "3")))
|
||||
$OptionParser.AddOption((New-Option "FILESTREAMSHARENAME" -String))
|
||||
$OptionParser.AddOption((New-Option "FTSVCACCOUNT" -String))
|
||||
$OptionParser.AddOption((New-Option "FTSVCPASSWORD" -String))
|
||||
$OptionParser.AddOption((New-Option "ISSVCACCOUNT" -String), $true, "NT AUTHORITY\Network Service")
|
||||
$OptionParser.AddOption((New-Option "ISSVCPASSWORD" -String))
|
||||
$OptionParser.AddOption((New-Option "ISSVCStartupType" -String -Constraints ("Manual", "Automatic", "Disabled")))
|
||||
$OptionParser.AddOption((New-Option "NPENABLED" -Boolean))
|
||||
$OptionParser.AddOption((New-Option "TCPENABLED" -Boolean))
|
||||
$OptionParser.AddOption((New-Option "RSINSTALLMODE" -String -Constraints ("SharePointFilesOnlyMode", "DefaultNativeMode", "FilesOnlyMode")))
|
||||
$OptionParser.AddOption((New-Option "RSSVCACCOUNT" -String), $true, "NT AUTHORITY\Network Service")
|
||||
$OptionParser.AddOption((New-Option "RSSVCPASSWORD" -String))
|
||||
$OptionParser.AddOption((New-Option "RSSVCStartupType" -String -Constraints ("Manual", "Automatic", "Disabled")))
|
||||
|
||||
return $OptionParser
|
||||
}
|
||||
|
||||
function New-OptionParserPrepareImage {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Creates an option parser for MS SQL Server 2012 setup "PrepareImage" action.
|
||||
|
||||
.DESCRIPTION
|
||||
Use this cmdlet to create an option parser for MS SQL Server 2012 setup "PrepareImage" action.
|
||||
|
||||
Note that for installer version of MS SQL Server prior to 2012 SP1 Cumulative Update 2 only the
|
||||
following features are supported: SQLEngine, Replication, FullText, RS
|
||||
|
||||
All documented option are supported. See the following link for details:
|
||||
http://msdn.microsoft.com/en-us/library/ms144259.aspx
|
||||
#>
|
||||
$OptionParser = New-OptionParser
|
||||
|
||||
$OptionParser.AddOption((New-Option "ACTION" -String -Constraints "PrepareImage"), $true, "PrepareImage")
|
||||
$OptionParser.AddOption((New-Option "IACCEPTSQLSERVERLICENSETERMS" -Switch), $true)
|
||||
$OptionParser.AddOption((New-Option "ENU" -Switch))
|
||||
$OptionParser.AddOption((New-Option "UpdateEnabled" -Switch))
|
||||
$OptionParser.AddOption((New-Option "UpdateSource" -String))
|
||||
$OptionParser.AddOption((New-Option "CONFIGURATIONFILE" -String))
|
||||
# $OptionParser.AddOption((New-Option "FEATURES" -List -Constraints ("SQLEngine","Replication","FullText","RS")))
|
||||
$OptionParser.AddOption((New-Option "FEATURES" -List -Constraints ("SQL","SQLEngine","Replication","FullText","DQ","AS","RS","DQC","IS","MDS","Tools","BC","BOL","BIDS","Conn","SSMS","ADV_SSMS","DREPLAY_CTLR","DREPLAY_CLT","SNAC_SDK","SDK","LocalDB")))
|
||||
$OptionParser.AddOption((New-Option "HIDECONSOLE" -Switch))
|
||||
$OptionParser.AddOption((New-Option "INDICATEPROGRESS" -Switch))
|
||||
$OptionParser.AddOption((New-Option "INSTALLSHAREDDIR" -String))
|
||||
$OptionParser.AddOption((New-Option "INSTANCEDIR" -String))
|
||||
$OptionParser.AddOption((New-Option "INSTANCEID" -String), $true, "MSSQLSERVER")
|
||||
$OptionParser.AddOption((New-Option "Q" -Switch))
|
||||
$OptionParser.AddOption((New-Option "QS" -Switch))
|
||||
|
||||
return $OptionParser
|
||||
}
|
||||
|
||||
function New-OptionParserPrepareImageSP1U2 {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Creates an option parser for MS SQL Server 2012 setup "PrepareImage" action.
|
||||
|
||||
.DESCRIPTION
|
||||
Use this cmdlet to create an option parser for MS SQL Server 2012 setup "PrepareImage" action.
|
||||
|
||||
This cmdlet should be used only for MS SQL Server 2012 SP1 Cimilative Update 2 or later.
|
||||
|
||||
Note that for installer version of MS SQL Server prior to 2012 SP1 Cimilative Update 2 only the
|
||||
following features are supported: SQLEngine, Replication, FullText, RS
|
||||
|
||||
All documented option are supported. See the following link for details:
|
||||
http://msdn.microsoft.com/en-us/library/ms144259.aspx
|
||||
#>
|
||||
$OptionParser = New-OptionParser
|
||||
|
||||
$OptionParser.AddOption((New-Option "ACTION" -String -Constraints "PrepareImage"), $true, "PrepareImage")
|
||||
$OptionParser.AddOption((New-Option "IACCEPTSQLSERVERLICENSETERMS" -Switch), $true)
|
||||
$OptionParser.AddOption((New-Option "ENU" -Switch))
|
||||
$OptionParser.AddOption((New-Option "UpdateEnabled" -Switch))
|
||||
$OptionParser.AddOption((New-Option "UpdateSource" -String))
|
||||
$OptionParser.AddOption((New-Option "CONFIGURATIONFILE" -String))
|
||||
$OptionParser.AddOption((New-Option "FEATURES" -List -Constraints ("SQL","SQLEngine","Replication","FullText","DQ","AS","RS","DQC","IS","MDS","Tools","BC","BOL","BIDS","Conn","SSMS","ADV_SSMS","SNAC_SDK","SDK","LocalDB")))
|
||||
$OptionParser.AddOption((New-Option "HIDECONSOLE" -Switch))
|
||||
$OptionParser.AddOption((New-Option "INDICATEPROGRESS" -Switch))
|
||||
$OptionParser.AddOption((New-Option "INSTALLSHAREDDIR" -String))
|
||||
$OptionParser.AddOption((New-Option "INSTANCEDIR" -String))
|
||||
$OptionParser.AddOption((New-Option "INSTANCEID" -String), $true, "MSSQLSERVER")
|
||||
$OptionParser.AddOption((New-Option "Q" -Switch))
|
||||
$OptionParser.AddOption((New-Option "QS" -Switch))
|
||||
|
||||
return $OptionParser
|
||||
}
|
||||
|
||||
function New-OptionParserCompleteImage {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Creates an option parser for MS SQL Server 2012 setup "CompleteImage" action.
|
||||
|
||||
.DESCRIPTION
|
||||
Use this cmdlet to create an option parser for MS SQL Server 2012 setup "CompleteImage" action.
|
||||
|
||||
Note that INSTANCEID parameter value MUST be the same as specified on "PrepareImage" phase.
|
||||
|
||||
All documented option are supported. See the following link for details:
|
||||
http://msdn.microsoft.com/en-us/library/ms144259.aspx
|
||||
#>
|
||||
$OptionParser = New-OptionParser
|
||||
|
||||
$OptionParser.AddOption((New-Option "ACTION" -String -Constraints "CompleteImage"), $true, "CompleteImage")
|
||||
$OptionParser.AddOption((New-Option "IACCEPTSQLSERVERLICENSETERMS" -Switch), $true)
|
||||
$OptionParser.AddOption((New-Option "ENU" -Switch))
|
||||
$OptionParser.AddOption((New-Option "CONFIGURATIONFILE" -String))
|
||||
$OptionParser.AddOption((New-Option "ERRORREPORTING" -Boolean))
|
||||
$OptionParser.AddOption((New-Option "INDICATEPROGRESS" -Switch))
|
||||
$OptionParser.AddOption((New-Option "INSTANCEID" -String), $true, "MSSQLSERVER")
|
||||
$OptionParser.AddOption((New-Option "INSTANCENAME" -String), $true, "MSSQLSERVER")
|
||||
$OptionParser.AddOption((New-Option "PID" -String))
|
||||
$OptionParser.AddOption((New-Option "Q" -Switch))
|
||||
$OptionParser.AddOption((New-Option "QS" -Switch))
|
||||
$OptionParser.AddOption((New-Option "SQMREPORTING" -Boolean))
|
||||
$OptionParser.AddOption((New-Option "HIDECONSOLE" -Switch))
|
||||
$OptionParser.AddOption((New-Option "AGTSVCACCOUNT" -String), $true, "NT AUTHORITY\Network Service")
|
||||
$OptionParser.AddOption((New-Option "AGTSVCPASSWORD" -String))
|
||||
$OptionParser.AddOption((New-Option "AGTSVCSTARTUPTYPE" -String -Constraints ("Manual", "Automatic", "Disabled")))
|
||||
$OptionParser.AddOption((New-Option "BROWSERSVCSTARTUPTYPE" -String -Constraints ("Manual", "Automatic", "Disabled")))
|
||||
$OptionParser.AddOption((New-Option "ENABLERANU" -Switch))
|
||||
$OptionParser.AddOption((New-Option "INSTALLSQLDATADIR" -String))
|
||||
$OptionParser.AddOption((New-Option "SAPWD" -String))
|
||||
$OptionParser.AddOption((New-Option "SECURITYMODE" -String -Constrainrs ("SQL")))
|
||||
$OptionParser.AddOption((New-Option "SQLBACKUPDIR" -String))
|
||||
$OptionParser.AddOption((New-Option "SQLCOLLATION" -String))
|
||||
$OptionParser.AddOption((New-Option "SQLSVCACCOUNT" -String), $true, "NT AUTHORITY\Network Service")
|
||||
$OptionParser.AddOption((New-Option "SQLSVCPASSWORD" -String))
|
||||
$OptionParser.AddOption((New-Option "SQLSVCSTARTUPTYPE" -String -Constraints ("Manual", "Automatic", "Disabled")))
|
||||
$OptionParser.AddOption((New-Option "SQLSYSADMINACCOUNTS" -String), $true, "$ENV:USERDOMAIN\$ENV:USERNAME")
|
||||
$OptionParser.AddOption((New-Option "SQLTEMPDBDIR" -String))
|
||||
$OptionParser.AddOption((New-Option "SQLTEMPDBLOGDIR" -String))
|
||||
$OptionParser.AddOption((New-Option "SQLUSERDBDIR" -String))
|
||||
$OptionParser.AddOption((New-Option "SQLUSERDBLOGDIR" -String))
|
||||
$OptionParser.AddOption((New-Option "FILESTREAMLEVEL" -String -Constraints ("0", "1", "2", "3")))
|
||||
$OptionParser.AddOption((New-Option "FILESTREAMSHARENAME" -String))
|
||||
$OptionParser.AddOption((New-Option "FTSVCACCOUNT" -String))
|
||||
$OptionParser.AddOption((New-Option "FTSVCPASSWORD" -String))
|
||||
$OptionParser.AddOption((New-Option "NPENABLED" -Boolean))
|
||||
$OptionParser.AddOption((New-Option "TCPENABLED" -Boolean))
|
||||
$OptionParser.AddOption((New-Option "RSINSTALLMODE" -String -Constraints ("SharePointFilesOnlyMode", "DefaultNativeMode", "FilesOnlyMode")))
|
||||
$OptionParser.AddOption((New-Option "RSSVCACCOUNT" -String), $true, "NT AUTHORITY\Network Service")
|
||||
$OptionParser.AddOption((New-Option "RSSVCPASSWORD" -String))
|
||||
$OptionParser.AddOption((New-Option "RSSVCStartupType" -String -Constraints ("Manual", "Automatic", "Disabled")))
|
||||
|
||||
return $OptionParser
|
||||
}
|
||||
|
||||
function New-OptionParserCompleteImageSP1U2 {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Creates an option parser for MS SQL Server 2012 setup "CompleteImage" action.
|
||||
|
||||
.DESCRIPTION
|
||||
Use this cmdlet to create an option parser for MS SQL Server 2012 setup "CompleteImage" action.
|
||||
|
||||
This cmdlet should be used only for MS SQL Server 2012 SP1 Cimilative Update 2 or later.
|
||||
|
||||
All documented option are supported. See the following link for details:
|
||||
http://msdn.microsoft.com/en-us/library/ms144259.aspx
|
||||
#>
|
||||
$OptionParser = New-OptionParser
|
||||
|
||||
$OptionParser.AddOption((New-Option "ACTION" -String -Constraints "CompleteImage"), $true, "CompleteImage")
|
||||
$OptionParser.AddOption((New-Option "IACCEPTSQLSERVERLICENSETERMS" -Switch), $true)
|
||||
$OptionParser.AddOption((New-Option "ENU" -Switch))
|
||||
$OptionParser.AddOption((New-Option "CONFIGURATIONFILE" -String))
|
||||
$OptionParser.AddOption((New-Option "ERRORREPORTING" -Boolean))
|
||||
$OptionParser.AddOption((New-Option "INDICATEPROGRESS" -Switch))
|
||||
$OptionParser.AddOption((New-Option "INSTANCEID" -String))
|
||||
$OptionParser.AddOption((New-Option "INSTANCENAME" -String))
|
||||
$OptionParser.AddOption((New-Option "PID" -String))
|
||||
$OptionParser.AddOption((New-Option "Q" -Switch))
|
||||
$OptionParser.AddOption((New-Option "QS" -Switch))
|
||||
$OptionParser.AddOption((New-Option "SQMREPORTING" -Boolean))
|
||||
$OptionParser.AddOption((New-Option "HIDECONSOLE" -Switch))
|
||||
$OptionParser.AddOption((New-Option "AGTSVCACCOUNT" -String), $true, "NT AUTHORITY\Network Service")
|
||||
$OptionParser.AddOption((New-Option "AGTSVCPASSWORD" -String))
|
||||
$OptionParser.AddOption((New-Option "AGTSVCSTARTUPTYPE" -String -Constraints ("Manual", "Automatic", "Disabled")))
|
||||
$OptionParser.AddOption((New-Option "BROWSERSVCSTARTUPTYPE" -String -Constraints ("Manual", "Automatic", "Disabled")))
|
||||
$OptionParser.AddOption((New-Option "ENABLERANU" -Switch))
|
||||
$OptionParser.AddOption((New-Option "INSTALLSQLDATADIR" -String))
|
||||
$OptionParser.AddOption((New-Option "SAPWD" -String))
|
||||
$OptionParser.AddOption((New-Option "SECURITYMODE" -String -Constrainrs ("SQL")))
|
||||
$OptionParser.AddOption((New-Option "SQLBACKUPDIR" -String))
|
||||
$OptionParser.AddOption((New-Option "SQLCOLLATION" -String))
|
||||
$OptionParser.AddOption((New-Option "SQLSVCACCOUNT" -String), $true, "NT AUTHORITY\Network Service")
|
||||
$OptionParser.AddOption((New-Option "SQLSVCPASSWORD" -String))
|
||||
$OptionParser.AddOption((New-Option "SQLSVCSTARTUPTYPE" -String -Constraints ("Manual", "Automatic", "Disabled")))
|
||||
$OptionParser.AddOption((New-Option "SQLSYSADMINACCOUNTS" -String), $true, "$ENV:USERDOMAIN\$ENV:USERNAME")
|
||||
$OptionParser.AddOption((New-Option "SQLTEMPDBDIR" -String))
|
||||
$OptionParser.AddOption((New-Option "SQLTEMPDBLOGDIR" -String))
|
||||
$OptionParser.AddOption((New-Option "SQLUSERDBDIR" -String))
|
||||
$OptionParser.AddOption((New-Option "SQLUSERDBLOGDIR" -String))
|
||||
$OptionParser.AddOption((New-Option "FILESTREAMLEVEL" -String -Constraints ("0", "1", "2", "3")))
|
||||
$OptionParser.AddOption((New-Option "FILESTREAMSHARENAME" -String))
|
||||
$OptionParser.AddOption((New-Option "FTSVCACCOUNT" -String))
|
||||
$OptionParser.AddOption((New-Option "FTSVCPASSWORD" -String))
|
||||
$OptionParser.AddOption((New-Option "NPENABLED" -Boolean))
|
||||
$OptionParser.AddOption((New-Option "TCPENABLED" -Boolean))
|
||||
$OptionParser.AddOption((New-Option "RSINSTALLMODE" -String -Constraints ("SharePointFilesOnlyMode", "DefaultNativeMode", "FilesOnlyMode")))
|
||||
$OptionParser.AddOption((New-Option "RSSVCACCOUNT" -String), $true, "NT AUTHORITY\Network Service")
|
||||
$OptionParser.AddOption((New-Option "RSSVCPASSWORD" -String))
|
||||
$OptionParser.AddOption((New-Option "RSSVCStartupType" -String -Constraints ("Manual", "Automatic", "Disabled")))
|
||||
|
||||
return $OptionParser
|
||||
}
|
||||
|
||||
function New-OptionParserUpgrade {
|
||||
# ToDo: Implement
|
||||
throw "Not yet implemented"
|
||||
}
|
||||
|
||||
function New-OptionParserEditionUpgrade {
|
||||
# ToDo: Implement
|
||||
throw "Not yet implemented"
|
||||
}
|
||||
|
||||
function New-OptionParserRepair {
|
||||
# ToDo: Implement
|
||||
throw "Not yet implemented"
|
||||
}
|
||||
|
||||
function New-OptionParserRebuilddatabase {
|
||||
# ToDo: Implement
|
||||
throw "Not yet implemented"
|
||||
}
|
||||
|
||||
function New-OptionParserUninstall {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Creates an option parser for MS SQL Server 2012 setup "INSTALL" action.
|
||||
|
||||
.DESCRIPTION
|
||||
Use this cmdlet to create an option parser for MS SQL Server 2012 setup "INSTALL" action.
|
||||
All documented option are supported. See the following link for details:
|
||||
http://msdn.microsoft.com/en-us/library/ms144259.aspx
|
||||
#>
|
||||
$OptionParser = New-OptionParser
|
||||
|
||||
$OptionParser.AddOption((New-Option "ACTION" -String -Constraints "UNINSTALL"), $true, "UNINSTALL")
|
||||
$OptionParser.AddOption((New-Option "CONFIGURATIONFILE" -String))
|
||||
$OptionParser.AddOption((New-Option "FEATURES" -List -Constraints ("SQL","SQLEngine","Replication","FullText","DQ","AS","RS","DQC","IS","MDS","Tools","BC","BOL","BIDS","Conn","SSMS","ADV_SSMS","DREPLAY_CTLR","DREPLAY_CLT","SNAC_SDK","SDK","LocalDB")), $true)
|
||||
$OptionParser.AddOption((New-Option "INDICATEPROGRESS" -Switch))
|
||||
$OptionParser.AddOption((New-Option "INSTANCENAME" -String), $true, "MSSQLSERVER")
|
||||
$OptionParser.AddOption((New-Option "Q" -Switch))
|
||||
$OptionParser.AddOption((New-Option "HIDECONSOLE" -Switch))
|
||||
|
||||
return $OptionParser
|
||||
}
|
||||
|
||||
function New-OptionParserInstallFailoverCluster {
|
||||
# ToDo: Implement
|
||||
throw "Not yet implemented"
|
||||
}
|
||||
|
||||
function New-OptionParserPrepareFailoverCluster {
|
||||
# ToDo: Implement
|
||||
throw "Not yet implemented"
|
||||
}
|
||||
|
||||
function New-OptionParserCompleteFailoverCluster {
|
||||
# ToDo: Implement
|
||||
throw "Not yet implemented"
|
||||
}
|
||||
|
||||
function New-OptionParserUpgrade {
|
||||
# ToDo: Implement
|
||||
throw "Not yet implemented"
|
||||
}
|
||||
|
||||
function New-OptionParserAddNode {
|
||||
# ToDo: Implement
|
||||
throw "Not yet implemented"
|
||||
}
|
||||
|
||||
function New-OptionParserRemoveNode {
|
||||
# ToDo: Implement
|
||||
throw "Not yet implemented"
|
||||
}
|
||||
37
data3/templates/agent/scripts/Set-LocalUserPassword.ps1
Normal file
37
data3/templates/agent/scripts/Set-LocalUserPassword.ps1
Normal file
@@ -0,0 +1,37 @@
|
||||
|
||||
trap {
|
||||
&$TrapHandler
|
||||
}
|
||||
|
||||
|
||||
Function Set-LocalUserPassword {
|
||||
param (
|
||||
[String] $UserName,
|
||||
[String] $Password,
|
||||
[Switch] $Force
|
||||
)
|
||||
begin {
|
||||
Show-InvocationInfo $MyInvocation
|
||||
}
|
||||
end {
|
||||
Show-InvocationInfo $MyInvocation -End
|
||||
}
|
||||
process {
|
||||
trap {
|
||||
&$TrapHandler
|
||||
}
|
||||
|
||||
if ((Get-WmiObject Win32_UserAccount -Filter "LocalAccount = 'True' AND Name='$UserName'") -eq $null) {
|
||||
throw "Unable to find local user account '$UserName'"
|
||||
}
|
||||
|
||||
if ($Force) {
|
||||
Write-Log "Changing password for user '$UserName' to '*****'" # :)
|
||||
$null = ([ADSI] "WinNT://./$UserName").SetPassword($Password)
|
||||
}
|
||||
else {
|
||||
Write-LogWarning "You are trying to change password for user '$UserName'. To do this please run the command again with -Force parameter."
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
151
data3/templates/agent/scripts/Start-PowerShellProcess.ps1
Normal file
151
data3/templates/agent/scripts/Start-PowerShellProcess.ps1
Normal file
@@ -0,0 +1,151 @@
|
||||
|
||||
trap {
|
||||
&$TrapHandler
|
||||
}
|
||||
|
||||
|
||||
|
||||
function Select-CliXmlBlock {
|
||||
param (
|
||||
[String] $Path,
|
||||
[String] $OutFile = [IO.Path]::GetTempFileName()
|
||||
)
|
||||
|
||||
$TagFound = $false
|
||||
Get-Content $Path |
|
||||
ForEach-Object {
|
||||
if ($_ -eq '#< CLIXML') {
|
||||
$TagFound = $true
|
||||
}
|
||||
if ($TagFound) {
|
||||
Add-Content -Path $OutFile -Value $_
|
||||
}
|
||||
}
|
||||
$OutFile
|
||||
}
|
||||
|
||||
|
||||
|
||||
function Start-PowerShellProcess {
|
||||
param (
|
||||
[String] $Command,
|
||||
$Credential = $null,
|
||||
[Switch] $IgnoreStdErr,
|
||||
[Switch] $NoBase64
|
||||
)
|
||||
begin {
|
||||
Show-InvocationInfo $MyInvocation
|
||||
}
|
||||
end {
|
||||
Show-InvocationInfo $MyInvocation -End
|
||||
}
|
||||
process {
|
||||
trap {
|
||||
&$TrapHandler
|
||||
}
|
||||
|
||||
$StdOut = [IO.Path]::GetTempFileName()
|
||||
$StdErr = [IO.Path]::GetTempFileName()
|
||||
|
||||
$ArgumentList = @('-OutputFormat', 'XML')
|
||||
|
||||
if ($NoBase64) {
|
||||
$TmpScript = [IO.Path]::GetTempFileName()
|
||||
Rename-Item -Path "$TmpScript" -NewName "$TmpScript.ps1" -Force
|
||||
$TmpScript = "$TmpScript.ps1"
|
||||
|
||||
Write-LogDebug $TmpScript
|
||||
|
||||
$Command | Out-File $TmpScript
|
||||
|
||||
$ArgumentList += @('-File', "$TmpScript")
|
||||
}
|
||||
else {
|
||||
$Bytes = [Text.Encoding]::Unicode.GetBytes($Command)
|
||||
$EncodedCommand = [Convert]::ToBase64String($Bytes)
|
||||
|
||||
Write-LogDebug $EncodedCommand
|
||||
|
||||
$ArgumentList += @('-EncodedCommand', $EncodedCommand)
|
||||
}
|
||||
|
||||
Write-LogDebug $ArgumentList
|
||||
|
||||
Write-Log "Starting external PowerShell process ..."
|
||||
|
||||
if ($Credential -eq $null) {
|
||||
$Process = Start-Process -FilePath 'powershell.exe' `
|
||||
-ArgumentList @($ArgumentList) `
|
||||
-RedirectStandardOutput $StdOut `
|
||||
-RedirectStandardError $StdErr `
|
||||
-NoNewWindow `
|
||||
-Wait `
|
||||
-PassThru
|
||||
}
|
||||
else {
|
||||
$Process = Start-Process -FilePath 'powershell.exe' `
|
||||
-ArgumentList @($ArgumentList) `
|
||||
-RedirectStandardOutput $StdOut `
|
||||
-RedirectStandardError $StdErr `
|
||||
-Credential $Credential `
|
||||
-NoNewWindow `
|
||||
-Wait `
|
||||
-PassThru
|
||||
}
|
||||
|
||||
Write-Log "External PowerShell process exited with exit code '$($Process.ExitCode)'."
|
||||
|
||||
#if ($ArgumentList -contains '-File') {
|
||||
# Remove-Item -Path $TmpScript -Force
|
||||
#}
|
||||
|
||||
$ErrorActionPreferenceSaved = $ErrorActionPreference
|
||||
$ErrorActionPreference = 'SilentlyContinue'
|
||||
|
||||
Write-LogDebug "StdOut file is '$StdOut'"
|
||||
Write-LogDebug "StdErr file is '$StdErr'"
|
||||
|
||||
if ((Get-Item $StdOut).Length -gt 0) {
|
||||
try {
|
||||
Write-LogDebug "Loading StdOut from '$StdOut'"
|
||||
$TmpFile = Select-CliXmlBlock $StdOut
|
||||
$StdOutObject = Import-Clixml $TmpFile
|
||||
Write-LogDebug "<StdOut>"
|
||||
Write-LogDebug ($StdOutObject)
|
||||
Write-LogDebug "</StdOut>"
|
||||
$StdOutObject
|
||||
#Remove-Item -Path $TmpFile -Force
|
||||
}
|
||||
catch {
|
||||
Write-LogDebug "An error occured while loading StdOut from '$TmpFile'"
|
||||
}
|
||||
}
|
||||
|
||||
if ((Get-Item $StdErr).Length -gt 0) {
|
||||
try {
|
||||
Write-LogDebug "Loading StdErr ..."
|
||||
$TmpFile = Select-CliXmlBlock $StdErr
|
||||
$StdErrObject = Import-Clixml $TmpFile
|
||||
Write-LogDebug "<StdErr>"
|
||||
Write-LogDebug ($StdErrObject)
|
||||
Write-LogDebug "</StdErr>"
|
||||
if (-not $IgnoreStdErr) {
|
||||
$StdErrObject
|
||||
}
|
||||
#Remove-Item -Path $TmpFile -Force
|
||||
}
|
||||
catch {
|
||||
Write-LogDebug "An error occured while loading StdErr from '$TmpFile'"
|
||||
}
|
||||
}
|
||||
|
||||
$ErrorActionPreference = $ErrorActionPreferenceSaved
|
||||
|
||||
if ($Process.ExitCode -ne 0) {
|
||||
throw("External PowerShell process exited with code '$($Process.ExitCode)'")
|
||||
}
|
||||
|
||||
#Remove-Item $StdOut -Force
|
||||
#Remove-Item $StdErr -Force
|
||||
}
|
||||
}
|
||||
60
data3/templates/agent/scripts/Update-ServiceConfig.ps1
Normal file
60
data3/templates/agent/scripts/Update-ServiceConfig.ps1
Normal file
@@ -0,0 +1,60 @@
|
||||
|
||||
trap {
|
||||
&$TrapHandler
|
||||
}
|
||||
|
||||
|
||||
|
||||
function Update-ServiceConfig {
|
||||
param (
|
||||
[String] $Name,
|
||||
[String] $RunAsUser = '',
|
||||
[String] $DomainName = '.',
|
||||
[String] $Password = '',
|
||||
[Switch] $RunAsLocalService
|
||||
)
|
||||
begin {
|
||||
Show-InvocationInfo $MyInvocation
|
||||
}
|
||||
end {
|
||||
Show-InvocationInfo $MyInvocation -End
|
||||
}
|
||||
process {
|
||||
trap {
|
||||
&$TrapHandler
|
||||
}
|
||||
|
||||
$ArgumentList = @('config', "`"$Name`"")
|
||||
|
||||
if ($RunAsLocalService) {
|
||||
$ArgumentList += @("obj=", "`"NT AUTHORITY\LocalService`"")
|
||||
}
|
||||
elseif ($RunAsUser -ne '') {
|
||||
$ArgumentList += @("obj=", "`"$DomainName\$RunAsUser`"", "password=", "`"$Password`"")
|
||||
}
|
||||
|
||||
$Process = Exec 'sc.exe' $ArgumentList -PassThru -RedirectStreams
|
||||
|
||||
if ($Process.ExitCode -ne 0) {
|
||||
throw "Command 'sc.exe' returned exit code '$($Process.ExitCode)'"
|
||||
}
|
||||
|
||||
$NtRights = "C:\Murano\Tools\ntrights.exe"
|
||||
|
||||
if (-not ([IO.File]::Exists($NtRights))) {
|
||||
throw "File '$NtRights' not found."
|
||||
}
|
||||
|
||||
$Process = Exec $NtRights @('-u', "$DomainName\$RunAsUser", '+r', 'SeServiceLogonRight') -RedirectStreams -PassThru
|
||||
|
||||
if ($Process.ExitCode -ne 0) {
|
||||
throw "Command '$NtRights' returned exit code '$($Process.ExitCode)'"
|
||||
}
|
||||
|
||||
$Process = Exec $NtRights @('-u', "$DomainName\$RunAsUser", '+r', 'SeBatchLogonRight') -RedirectStreams -PassThru
|
||||
|
||||
if ($Process.ExitCode -ne 0) {
|
||||
throw "Command '$NtRights' returned exit code '$($Process.ExitCode)'"
|
||||
}
|
||||
}
|
||||
}
|
||||
45
data3/templates/cf/IISSecurity.template
Normal file
45
data3/templates/cf/IISSecurity.template
Normal file
@@ -0,0 +1,45 @@
|
||||
{
|
||||
"Resources": {
|
||||
"$instanceName": {
|
||||
"Properties": {
|
||||
"SecurityGroups": [
|
||||
{
|
||||
"Ref": "IISSecurityGroup"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"IISSecurityGroup": {
|
||||
"Type": "AWS::EC2::SecurityGroup",
|
||||
"Properties": {
|
||||
"SecurityGroupIngress": [
|
||||
{
|
||||
"ToPort": "8172",
|
||||
"IpProtocol": "tcp",
|
||||
"FromPort": "8172",
|
||||
"CidrIp": "0.0.0.0/0"
|
||||
},
|
||||
{
|
||||
"ToPort": "80",
|
||||
"IpProtocol": "tcp",
|
||||
"FromPort": "80",
|
||||
"CidrIp": "0.0.0.0/0"
|
||||
},
|
||||
{
|
||||
"ToPort": "433",
|
||||
"IpProtocol": "tcp",
|
||||
"FromPort": "433",
|
||||
"CidrIp": "0.0.0.0/0"
|
||||
},
|
||||
{
|
||||
"ToPort": "21",
|
||||
"IpProtocol": "tcp",
|
||||
"FromPort": "21",
|
||||
"CidrIp": "0.0.0.0/0"
|
||||
}
|
||||
],
|
||||
"GroupDescription": "Enable access to IIS Management Console, HTTP, HTTPS and FTP protocols"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
70
data3/templates/cf/Linux.template
Normal file
70
data3/templates/cf/Linux.template
Normal file
@@ -0,0 +1,70 @@
|
||||
{
|
||||
"AWSTemplateFormatVersion": "2010-09-09",
|
||||
|
||||
"Parameters": {
|
||||
"KeyName": {
|
||||
"Description": "Key Pair name for Load Balancer",
|
||||
"Type": "String",
|
||||
"Default": "murano-lb-key"
|
||||
}
|
||||
},
|
||||
|
||||
"Resources": {
|
||||
"$instanceName": {
|
||||
"Type": "AWS::EC2::Instance",
|
||||
"Properties": {
|
||||
"BootFromVolume": true,
|
||||
"InstanceType": "$instanceType",
|
||||
"ImageId": "$imageName",
|
||||
"AvailabilityZone": "$availabilityZone",
|
||||
"UserData": "$userData",
|
||||
"SecurityGroups": [
|
||||
{
|
||||
"Ref": "MuranoDefaultSecurityGroup"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"MuranoDefaultSecurityGroup": {
|
||||
"Type": "AWS::EC2::SecurityGroup",
|
||||
"Properties": {
|
||||
"SecurityGroupIngress": [
|
||||
{
|
||||
"ToPort": "22",
|
||||
"IpProtocol": "tcp",
|
||||
"FromPort": "22",
|
||||
"CidrIp": "0.0.0.0/0"
|
||||
},
|
||||
{
|
||||
"ToPort": "23",
|
||||
"IpProtocol": "tcp",
|
||||
"FromPort": "23",
|
||||
"CidrIp": "0.0.0.0/0"
|
||||
},
|
||||
{
|
||||
"ToPort": "-1",
|
||||
"IpProtocol": "icmp",
|
||||
"FromPort": "-1",
|
||||
"CidrIp": "0.0.0.0/0"
|
||||
},
|
||||
{
|
||||
"IpProtocol": "tcp",
|
||||
"FromPort" : "1",
|
||||
"ToPort": "65535",
|
||||
"CidrIp": "10.0.0.0/24"
|
||||
},
|
||||
{
|
||||
"IpProtocol": "udp",
|
||||
"FromPort" : "1",
|
||||
"ToPort": "65535",
|
||||
"CidrIp": "10.0.0.0/24"
|
||||
}
|
||||
],
|
||||
"GroupDescription": "Default security group for Linux Murano Environments"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
"Outputs": {
|
||||
}
|
||||
}
|
||||
22
data3/templates/cf/LoadBalancer.template
Normal file
22
data3/templates/cf/LoadBalancer.template
Normal file
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"Resources" : {
|
||||
"$lbName" : {
|
||||
"Type" : "AWS::ElasticLoadBalancing::LoadBalancer",
|
||||
"Properties" : {
|
||||
"AvailabilityZones" : { "Fn::GetAZs" : "" },
|
||||
"Instances" : [{"Ref": "$instanceName"}],
|
||||
"Listeners" : [ {
|
||||
"LoadBalancerPort" : "$lbPort",
|
||||
"InstancePort" : "80",
|
||||
"Protocol" : "HTTP"
|
||||
}]
|
||||
}
|
||||
}
|
||||
},
|
||||
"Outputs": {
|
||||
"${lbName}-LoadBalancerIP": {
|
||||
"Value": { "Fn::GetAtt": [ "$lbName", "DNSName" ] },
|
||||
"Description": ""
|
||||
}
|
||||
}
|
||||
}
|
||||
45
data3/templates/cf/SQL-security.template
Normal file
45
data3/templates/cf/SQL-security.template
Normal file
@@ -0,0 +1,45 @@
|
||||
{
|
||||
"Resources": {
|
||||
"$instanceName": {
|
||||
"Properties": {
|
||||
"SecurityGroups": [
|
||||
{
|
||||
"Ref": "MsSqlSecurityGroup"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"MsSqlSecurityGroup": {
|
||||
"Type": "AWS::EC2::SecurityGroup",
|
||||
"Properties": {
|
||||
"SecurityGroupIngress": [
|
||||
{
|
||||
"ToPort": "4022",
|
||||
"IpProtocol": "tcp",
|
||||
"FromPort": "4022",
|
||||
"CidrIp": "0.0.0.0/0"
|
||||
},
|
||||
{
|
||||
"ToPort": "135",
|
||||
"IpProtocol": "tcp",
|
||||
"FromPort": "135",
|
||||
"CidrIp": "0.0.0.0/0"
|
||||
},
|
||||
{
|
||||
"ToPort": "1433",
|
||||
"IpProtocol": "tcp",
|
||||
"FromPort": "1433",
|
||||
"CidrIp": "0.0.0.0/0"
|
||||
},
|
||||
{
|
||||
"ToPort": "1434",
|
||||
"IpProtocol": "tcp",
|
||||
"FromPort": "1434",
|
||||
"CidrIp": "0.0.0.0/0"
|
||||
}
|
||||
],
|
||||
"GroupDescription": "Enable MS SQL access"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
45
data3/templates/cf/SQLCluster.template
Normal file
45
data3/templates/cf/SQLCluster.template
Normal file
@@ -0,0 +1,45 @@
|
||||
{
|
||||
"Resources": {
|
||||
"$instanceName": {
|
||||
"Properties": {
|
||||
"SecurityGroups": [
|
||||
{
|
||||
"Ref": "MsSqlSecurityGroup"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"MsSqlSecurityGroup": {
|
||||
"Type": "AWS::EC2::SecurityGroup",
|
||||
"Properties": {
|
||||
"SecurityGroupIngress": [
|
||||
{
|
||||
"ToPort": "4022",
|
||||
"IpProtocol": "tcp",
|
||||
"FromPort": "4022",
|
||||
"CidrIp": "0.0.0.0/0"
|
||||
},
|
||||
{
|
||||
"ToPort": "135",
|
||||
"IpProtocol": "tcp",
|
||||
"FromPort": "135",
|
||||
"CidrIp": "0.0.0.0/0"
|
||||
},
|
||||
{
|
||||
"ToPort": "1433",
|
||||
"IpProtocol": "tcp",
|
||||
"FromPort": "1433",
|
||||
"CidrIp": "0.0.0.0/0"
|
||||
},
|
||||
{
|
||||
"ToPort": "1434",
|
||||
"IpProtocol": "tcp",
|
||||
"FromPort": "1434",
|
||||
"CidrIp": "0.0.0.0/0"
|
||||
}
|
||||
],
|
||||
"GroupDescription": "Enable MS SQL access"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
70
data3/templates/cf/Windows.template
Normal file
70
data3/templates/cf/Windows.template
Normal file
@@ -0,0 +1,70 @@
|
||||
{
|
||||
"AWSTemplateFormatVersion": "2010-09-09",
|
||||
|
||||
"Parameters": {
|
||||
"KeyName": {
|
||||
"Description": "Key Pair name for Load Balancer",
|
||||
"Type": "String",
|
||||
"Default": "murano-lb-key"
|
||||
}
|
||||
},
|
||||
|
||||
"Resources": {
|
||||
"$instanceName": {
|
||||
"Type": "AWS::EC2::Instance",
|
||||
"Properties": {
|
||||
"BootFromVolume": true,
|
||||
"InstanceType": "$instanceType",
|
||||
"ImageId": "$imageName",
|
||||
"AvailabilityZone": "$availabilityZone",
|
||||
"UserData": "$userData",
|
||||
"SecurityGroups": [
|
||||
{
|
||||
"Ref": "MuranoDefaultSecurityGroup"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"MuranoDefaultSecurityGroup": {
|
||||
"Type": "AWS::EC2::SecurityGroup",
|
||||
"Properties": {
|
||||
"SecurityGroupIngress": [
|
||||
{
|
||||
"ToPort": "3389",
|
||||
"IpProtocol": "tcp",
|
||||
"FromPort": "3389",
|
||||
"CidrIp": "0.0.0.0/0"
|
||||
},
|
||||
{
|
||||
"ToPort": "22",
|
||||
"IpProtocol": "tcp",
|
||||
"FromPort": "22",
|
||||
"CidrIp": "0.0.0.0/0"
|
||||
},
|
||||
{
|
||||
"ToPort": "-1",
|
||||
"IpProtocol": "icmp",
|
||||
"FromPort": "-1",
|
||||
"CidrIp": "0.0.0.0/0"
|
||||
},
|
||||
{
|
||||
"IpProtocol": "tcp",
|
||||
"FromPort" : "1",
|
||||
"ToPort": "65535",
|
||||
"CidrIp": "10.0.0.0/24"
|
||||
},
|
||||
{
|
||||
"IpProtocol": "udp",
|
||||
"FromPort" : "1",
|
||||
"ToPort": "65535",
|
||||
"CidrIp": "10.0.0.0/24"
|
||||
}
|
||||
],
|
||||
"GroupDescription": "Default security group for Windows Murano Environments"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
"Outputs": {
|
||||
}
|
||||
}
|
||||
320
data3/workflows/AD.xml
Normal file
320
data3/workflows/AD.xml
Normal file
@@ -0,0 +1,320 @@
|
||||
<workflow>
|
||||
<rule match="$.services[?(@.type == 'activeDirectory' and @.domain)].units[?(not @.isMaster)]"
|
||||
desc="Slave units of AD services">
|
||||
<set path="domain">
|
||||
<select path="::domain"/>
|
||||
</set>
|
||||
<mute/>
|
||||
</rule>
|
||||
|
||||
<rule match="$.services[?(@.type == 'activeDirectory' and @.osImage.name)].units[?(@.state.hostname and not @.temp.instanceName)]"
|
||||
desc="Units of AD services which have got hostname and image assigned, but instances not deployed yet">
|
||||
<report entity="unit">
|
||||
<parameter name="id"><select path="id"/></parameter>
|
||||
<parameter name="text">Creating instance <select path="state.hostname"/> (<select path="name"/>)</parameter>
|
||||
</report>
|
||||
<update-cf-stack template="Windows" error="exception">
|
||||
<parameter name="mappings">
|
||||
<map>
|
||||
<mapping name="instanceName"><select path="state.hostname"/></mapping>
|
||||
<mapping name="environmentId"><select path="/id"/></mapping>
|
||||
<mapping name="userData">
|
||||
<prepare-user-data>
|
||||
<parameter name="hostname"><select path="state.hostname"/></parameter>
|
||||
<parameter name="unit"><select path="id"/></parameter>
|
||||
<parameter name="service"><select path="::id"/></parameter>
|
||||
</prepare-user-data>
|
||||
</mapping>
|
||||
<mapping name="instanceType"><select path="::flavor" default="m1.medium"/></mapping>
|
||||
<mapping name="imageName"><select path="::osImage.name"/></mapping>
|
||||
<mapping name="availabilityZone"><select path="::availabilityZone" default="nova"/></mapping>
|
||||
</map>
|
||||
</parameter>
|
||||
|
||||
<success>
|
||||
<set path="temp.instanceName"><select path="name"/></set>
|
||||
<report entity="unit">
|
||||
<parameter name="id"><select path="id"/></parameter>
|
||||
<parameter name="text">Instance <select path="state.hostname"/> (<select path="name"/>) created</parameter>
|
||||
</report>
|
||||
</success>
|
||||
<failure>
|
||||
<report entity="unit" level="error">
|
||||
<parameter name="id"><select path="id"/></parameter>
|
||||
<parameter name="text">Unable to deploy instance <select path="state.hostname"/> (<select path="name"/>) due to <format-error error="exception"/></parameter>
|
||||
</report>
|
||||
<stop/>
|
||||
</failure>
|
||||
</update-cf-stack>
|
||||
</rule>
|
||||
|
||||
<rule match="$.services[?(@.type == 'activeDirectory')].units[?(@.temp.instanceName and @.adminPassword and @.adminPassword != @.state.adminPassword)]"
|
||||
desc="Units of AD services which have got instances deployed but the local admin passwords not set yet">
|
||||
<send-command template="SetPassword" error="exception">
|
||||
<parameter name="unit">
|
||||
<select path="id"/>
|
||||
</parameter>
|
||||
<parameter name="service">
|
||||
<select path="::id"/>
|
||||
</parameter>
|
||||
<parameter name="mappings">
|
||||
<map>
|
||||
<mapping name="adminPassword">
|
||||
<select path="adminPassword"/>
|
||||
</mapping>
|
||||
</map>
|
||||
</parameter>
|
||||
<success>
|
||||
<set path="state.adminPassword">
|
||||
<select path="adminPassword"/>
|
||||
</set>
|
||||
</success>
|
||||
<failure>
|
||||
<report entity="unit" level="warning">
|
||||
<parameter name="id"><select path="id"/></parameter>
|
||||
<parameter name="text">Unable to set admin password on unit <select path="state.hostname"/> (<select path="name"/>) due to <format-error error="exception"/></parameter>
|
||||
</report>
|
||||
<mute/>
|
||||
</failure>
|
||||
</send-command>
|
||||
</rule>
|
||||
|
||||
<rule match="$.services[?(@.type == 'activeDirectory' and @.adminPassword and @.adminPassword != @.state.domainAdminPassword)].units[?(@.temp.instanceName and @.isMaster)]"
|
||||
desc="Deployed master-units of AD services for which the domain admin password is not set yet">
|
||||
<send-command template="SetPassword" error="exception">
|
||||
<parameter name="unit">
|
||||
<select path="id"/>
|
||||
</parameter>
|
||||
<parameter name="service">
|
||||
<select path="::id"/>
|
||||
</parameter>
|
||||
<parameter name="mappings">
|
||||
<map>
|
||||
<mapping name="adminPassword">
|
||||
<select path="::adminPassword"/>
|
||||
</mapping>
|
||||
</map>
|
||||
</parameter>
|
||||
<success>
|
||||
<set path="::state.domainAdminPassword">
|
||||
<select path="::adminPassword"/>
|
||||
</set>
|
||||
</success>
|
||||
<failure>
|
||||
<report entity="unit" level="error">
|
||||
<parameter name="id"><select path="id"/></parameter>
|
||||
<parameter name="text">Unable to set domain administrator password on unit <select path="state.hostname"/> (<select path="name"/>) due to <format-error error="exception"/></parameter>
|
||||
</report>
|
||||
<stop/>
|
||||
</failure>
|
||||
</send-command>
|
||||
</rule>
|
||||
|
||||
<rule match="$.services[?(@.type == 'activeDirectory' and @.state.primaryDc is None)].units[?(@.temp.instanceName and @.isMaster)]"
|
||||
desc="Deployed master-units of AD services on which the Primary DC has not been installed yet ">
|
||||
<report entity="unit">
|
||||
<parameter name="id"><select path="id"/></parameter>
|
||||
<parameter name="text">Creating Primary Domain Controller on unit <select path="state.hostname"/> (<select path="name"/>)</parameter>
|
||||
</report>
|
||||
<send-command template="CreatePrimaryDC" error="exception">
|
||||
<parameter name="unit">
|
||||
<select path="id"/>
|
||||
</parameter>
|
||||
<parameter name="service">
|
||||
<select path="::id"/>
|
||||
</parameter>
|
||||
<parameter name="mappings">
|
||||
<map>
|
||||
<mapping name="domain">
|
||||
<select path="::domain"/>
|
||||
</mapping>
|
||||
<mapping name="recoveryPassword">
|
||||
<select path="recoveryPassword"/>
|
||||
</mapping>
|
||||
</map>
|
||||
</parameter>
|
||||
<success>
|
||||
<set path="::state.primaryDc"><select path="name"/></set>
|
||||
<report entity="unit">
|
||||
<parameter name="id"><select path="id"/></parameter>
|
||||
<parameter name="text">Primary Domain Controller created</parameter>
|
||||
</report>
|
||||
</success>
|
||||
<failure>
|
||||
<report entity="unit" level="error">
|
||||
<parameter name="id"><select path="id"/></parameter>
|
||||
<parameter name="text">Unable to create a Primary DC on unit <select path="state.hostname"/> (<select path="name"/>) due to <format-error error="exception"/></parameter>
|
||||
</report>
|
||||
<stop/>
|
||||
</failure>
|
||||
</send-command>
|
||||
</rule>
|
||||
|
||||
<rule match="$.services[?(@.type == 'activeDirectory' and @.state.primaryDc and not @.state.primaryDcIp)].units[?(@.temp.instanceName and @.isMaster)]"
|
||||
desc="Master Units of AD services on which the Primary Domain Controller has been configured but DNS ip has not been asked for">
|
||||
<send-command template="AskDnsIp" result="ip" error="exception">
|
||||
<parameter name="unit">
|
||||
<select path="id"/>
|
||||
</parameter>
|
||||
<parameter name="service">
|
||||
<select path="::id"/>
|
||||
</parameter>
|
||||
<success>
|
||||
<set path="::state.primaryDcIp">
|
||||
<select source="ip" path="0.Result.0"/>
|
||||
</set>
|
||||
</success>
|
||||
<failure>
|
||||
<report entity="unit" level="error">
|
||||
<parameter name="id"><select path="id"/></parameter>
|
||||
<parameter name="text">Unable assign DNS IP on unit <select path="state.hostname"/> (<select path="name"/>) due to <format-error error="exception"/></parameter>
|
||||
</report>
|
||||
<stop/>
|
||||
</failure>
|
||||
</send-command>
|
||||
</rule>
|
||||
|
||||
<rule match="$.services[?(@.type != 'activeDirectory')].units[?(@.state.domain and not @.domain)]"
|
||||
desc="Any non-AD services of the environment which has been part of the domain but needs to leave it">
|
||||
<send-command template="LeaveDomain" error="exception">
|
||||
<parameter name="unit">
|
||||
<select path="id" source="unit"/>
|
||||
</parameter>
|
||||
<parameter name="service">
|
||||
<select path="::id"/>
|
||||
</parameter>
|
||||
<parameter name="mappings">
|
||||
<map>
|
||||
<mapping name="domain">
|
||||
<select path="state.domain"/>
|
||||
</mapping>
|
||||
</map>
|
||||
</parameter>
|
||||
|
||||
<success>
|
||||
<report entity="unit">
|
||||
<parameter name="id"><select path="id" source="unit"/></parameter>
|
||||
<parameter name="text">Unit <select path="state.hostname" source="unit"/> (<select path="name" source="unit"/>) has left domain <select path="state.domain"/></parameter>
|
||||
</report>
|
||||
<set path="state.domain"><null/></set>
|
||||
</success>
|
||||
<failure>
|
||||
<report entity="unit" level="error">
|
||||
<parameter name="id"><select path="id"/></parameter>
|
||||
<parameter name="text">Unit <select path="state.hostname" source="unit"/> (<select path="name" source="unit"/>) was unable to leave the domain due to <format-error error="exception"/></parameter>
|
||||
</report>
|
||||
<stop/>
|
||||
</failure>
|
||||
</send-command>
|
||||
</rule>
|
||||
|
||||
<rule match="$..units[?(@.temp.instanceName and @.domain and @.domain != @.state.domain)]"
|
||||
desc="Any deployed unit which need to enter the domain">
|
||||
<set path="#unit">
|
||||
<select/>
|
||||
</set>
|
||||
<set path="#service">
|
||||
<select path="::"/>
|
||||
</set>
|
||||
<rule desc="Domain controller exists with the assigned DNS IP">
|
||||
<parameter name="match">/$.services[?(@.type == 'activeDirectory' and @.domain == '<select path="domain"/>' and @.state.primaryDcIp)]</parameter>
|
||||
<send-command template="JoinDomain" error="exception">
|
||||
<parameter name="unit">
|
||||
<select path="id" source="unit"/>
|
||||
</parameter>
|
||||
<parameter name="service">
|
||||
<select path="id" source="service"/>
|
||||
</parameter>
|
||||
<parameter name="mappings">
|
||||
<map>
|
||||
<mapping name="domain">
|
||||
<select path="domain"/>
|
||||
</mapping>
|
||||
<mapping name="domainPassword">
|
||||
<select path="adminPassword"/>
|
||||
</mapping>
|
||||
<mapping name="dnsIp">
|
||||
<select path="state.primaryDcIp"/>
|
||||
</mapping>
|
||||
<mapping name="domainUser">
|
||||
<select path="adminAccountName" default="Administrator"/>
|
||||
</mapping>
|
||||
<mapping name="ouPath"></mapping>
|
||||
</map>
|
||||
</parameter>
|
||||
|
||||
<success>
|
||||
<set path="state.domain" target="unit">
|
||||
<select path="domain"/>
|
||||
</set>
|
||||
<set path="state.domainIp" target="unit">
|
||||
<select path="state.primaryDcIp"/>
|
||||
</set>
|
||||
<report entity="unit">
|
||||
<parameter name="id"><select path="id" source="unit"/></parameter>
|
||||
<parameter name="text">Unit <select path="state.hostname" source="unit"/> (<select path="name" source="unit"/>) has joined domain <select path="domain"/></parameter>
|
||||
</report>
|
||||
</success>
|
||||
<failure>
|
||||
<report entity="unit" level="error">
|
||||
<parameter name="id"><select path="id"/></parameter>
|
||||
<parameter name="text">Unit <select path="state.hostname" source="unit"/> (<select path="name" source="unit"/>) was unable to join the domain due to <format-error error="exception"/></parameter>
|
||||
</report>
|
||||
<stop/>
|
||||
</failure>
|
||||
</send-command>
|
||||
</rule>
|
||||
</rule>
|
||||
|
||||
|
||||
<rule match="$.services[?(@.type == 'activeDirectory')].units[?(@.state.domain and not @.isMaster and not @.state.installed)]"
|
||||
desc="Slave units of AD services which has not got secondary DC installed yet">
|
||||
<report entity="unit">
|
||||
<parameter name="id"><select path="id"/></parameter>
|
||||
<parameter name="text">Creating Secondary Domain Controller on unit <select path="state.hostname"/> (<select path="name"/>)</parameter>
|
||||
</report>
|
||||
<send-command template="CreateSecondaryDC" error="exception">
|
||||
<parameter name="unit">
|
||||
<select path="id"/>
|
||||
</parameter>
|
||||
<parameter name="service">
|
||||
<select path="::id"/>
|
||||
</parameter>
|
||||
<parameter name="mappings">
|
||||
<map>
|
||||
<mapping name="recoveryPassword">
|
||||
<select path="recoveryPassword"/>
|
||||
</mapping>
|
||||
<mapping name="domainPassword">
|
||||
<select path="::adminPassword"/>
|
||||
</mapping>
|
||||
<mapping name="domain">
|
||||
<select path="::domain"/>
|
||||
</mapping>
|
||||
</map>
|
||||
</parameter>
|
||||
<success>
|
||||
<set path="state.installed"><true/></set>
|
||||
<report entity="unit">
|
||||
<parameter name="id"><select path="id"/></parameter>
|
||||
<parameter name="text">Secondary Domain Controller created</parameter>
|
||||
</report>
|
||||
<report entity="service">
|
||||
<parameter name="id"><select path="::id"/></parameter>
|
||||
<parameter name="text">Domain <select path="::domain"/> created</parameter>
|
||||
</report>
|
||||
</success>
|
||||
<failure>
|
||||
<report entity="unit" level="error">
|
||||
<parameter name="id"><select path="id"/></parameter>
|
||||
<parameter name="text">Unable to create Secondary Domain Controller on unit <select path="state.hostname" /> (<select path="name" />) due to <select source="exception" path="0.messages.0" default="unknown Agent error"/> </parameter>
|
||||
</report>
|
||||
<report entity="service" level="error">
|
||||
<parameter name="id"><select path="::id"/></parameter>
|
||||
<parameter name="text">Unable to create domain <select path="::domain"/></parameter>
|
||||
</report>
|
||||
<stop/>
|
||||
</failure>
|
||||
</send-command>
|
||||
</rule>
|
||||
</workflow>
|
||||
198
data3/workflows/AspNetApps.xml
Normal file
198
data3/workflows/AspNetApps.xml
Normal file
@@ -0,0 +1,198 @@
|
||||
<workflow>
|
||||
<rule match="$.services[?(@.type in ('webServer', 'aspNetApp', 'webServerFarm', 'aspNetAppFarm') and @.domain)].units[*]"
|
||||
desc='Units of web services with domain'>
|
||||
<set path="domain">
|
||||
<select path="::domain"/>
|
||||
</set>
|
||||
<mute/>
|
||||
</rule>
|
||||
|
||||
<rule match="$.services[?(@.type in ('webServer', 'aspNetApp', 'webServerFarm', 'aspNetAppFarm') and @.osImage.name)].units[?(@.state.hostname and not @.temp.instanceName)]"
|
||||
desc="Units of web services having hostname and image names assigned but without instances">
|
||||
<report entity="unit">
|
||||
<parameter name="id"><select path="id"/></parameter>
|
||||
<parameter name="text">Creating instance <select path="state.hostname"/> (<select path="name"/>)</parameter>
|
||||
</report>
|
||||
<update-cf-stack template="Windows" error="exception">
|
||||
<parameter name="mappings">
|
||||
<map>
|
||||
<mapping name="instanceName"><select path="state.hostname"/></mapping>
|
||||
<mapping name="environmentId"><select path="/id"/></mapping>
|
||||
<mapping name="userData">
|
||||
<prepare-user-data>
|
||||
<parameter name="hostname"><select path="state.hostname"/></parameter>
|
||||
<parameter name="unit"><select path="id"/></parameter>
|
||||
<parameter name="service"><select path="::id"/></parameter>
|
||||
</prepare-user-data>
|
||||
</mapping>
|
||||
<mapping name="instanceType"><select path="::flavor" default="m1.medium"/></mapping>
|
||||
<mapping name="imageName"><select path="::osImage.name"/></mapping>
|
||||
<mapping name="availabilityZone"><select path="::availabilityZone" default="nova"/></mapping>
|
||||
</map>
|
||||
</parameter>
|
||||
<success>
|
||||
<set path="temp.instanceName"><select path="name"/></set>
|
||||
<report entity="unit">
|
||||
<parameter name="id"><select path="id"/></parameter>
|
||||
<parameter name="text">Instance <select path="state.hostname"/> (<select path="name"/>) created</parameter>
|
||||
</report>
|
||||
</success>
|
||||
<failure>
|
||||
<report entity="unit" level="error">
|
||||
<parameter name="id"><select path="id"/></parameter>
|
||||
<parameter name="text">Unable to deploy instance <select path="state.hostname"/> (<select path="name"/>) due to <format-error error="exception"/></parameter>
|
||||
</report>
|
||||
<stop/>
|
||||
</failure>
|
||||
</update-cf-stack>
|
||||
|
||||
<report entity="unit">
|
||||
<parameter name="id"><select path="id"/></parameter>
|
||||
<parameter name="text">Configuring security groups on <select path="state.hostname"/> (<select path="name"/>)</parameter>
|
||||
</report>
|
||||
<update-cf-stack template="IISSecurity" error="exception">
|
||||
<parameter name="mappings">
|
||||
<map>
|
||||
<mapping name="instanceName"><select path="state.hostname"/></mapping>
|
||||
</map>
|
||||
</parameter>
|
||||
<success>
|
||||
<report entity="unit">
|
||||
<parameter name="id"><select path="id"/></parameter>
|
||||
<parameter name="text">Security groups configuration on instance <select path="state.hostname"/> (<select path="name"/>) is successful</parameter>
|
||||
</report>
|
||||
</success>
|
||||
<failure>
|
||||
<report entity="unit" level="error">
|
||||
<parameter name="id"><select path="id"/></parameter>
|
||||
<parameter name="text">Unable to configure security groups on instance <select path="state.hostname"/> (<select path="name"/>) due to <format-error error="exception"/></parameter>
|
||||
</report>
|
||||
<stop/>
|
||||
</failure>
|
||||
</update-cf-stack>
|
||||
</rule>
|
||||
|
||||
<rule match="$.services[?(@.type in ('webServerFarm', 'aspNetAppFarm'))].units[?(@.state.hostname and not @.temp.registeredWithLB)]"
|
||||
desc="Units of web-farms services which have a hostname assigned but are not registered with LB">
|
||||
<update-cf-stack template="LoadBalancer" result="outputs" error="exception">
|
||||
<parameter name="mappings">
|
||||
<map>
|
||||
<mapping name="instanceName"><select path="state.hostname"/></mapping>
|
||||
<mapping name="lbPort"><select path="::loadBalancerPort"/></mapping>
|
||||
<mapping name="lbName"><select path="::name"/></mapping>
|
||||
</map>
|
||||
</parameter>
|
||||
<success>
|
||||
<set path="temp.registeredWithLB"><true/></set>
|
||||
<set path="::uri">http://<select source="outputs"><parameter name="path"><select path="::name"/>-LoadBalancerIP</parameter></select>:<select path="::loadBalancerPort"/></set>
|
||||
</success>
|
||||
<failure>
|
||||
<report entity="unit" level="error">
|
||||
<parameter name="id"><select path="id"/></parameter>
|
||||
<parameter name="text">Unable to create a Server Farm load balancer on unit <select path="state.hostname"/> (<select path="name"/>) due to <format-error error="exception"/></parameter>
|
||||
</report>
|
||||
<stop/>
|
||||
</failure>
|
||||
</update-cf-stack>
|
||||
</rule>
|
||||
|
||||
<rule match="$.services[?(@.type in ('webServer', 'aspNetApp', 'webServerFarm', 'aspNetAppFarm') and @.adminPassword and @.adminPassword != @.state.adminPassword)].units[?(@.temp.instanceName)]"
|
||||
desc="Units of web services which have got an instance deployed but has not got a correct admin password ">
|
||||
<send-command template="SetPassword" error='exception'>
|
||||
<parameter name="unit">
|
||||
<select path="id"/>
|
||||
</parameter>
|
||||
<parameter name="service">
|
||||
<select path="::id"/>
|
||||
</parameter>
|
||||
<parameter name="mappings">
|
||||
<map>
|
||||
<mapping name="adminPassword">
|
||||
<select path="::adminPassword"/>
|
||||
</mapping>
|
||||
</map>
|
||||
</parameter>
|
||||
<success>
|
||||
<set path="::state.adminPassword">
|
||||
<select path="::adminPassword"/>
|
||||
</set>
|
||||
</success>
|
||||
<failure>
|
||||
<report entity="unit" level="warning">
|
||||
<parameter name="id"><select path="id"/></parameter>
|
||||
<parameter name="text">Unable to set admin password on unit <select path="state.hostname"/> (<select path="name"/>) <format-error error="exception"/></parameter>
|
||||
</report>
|
||||
<mute/>
|
||||
</failure>
|
||||
</send-command>
|
||||
</rule>
|
||||
|
||||
|
||||
<rule match="$.services[?(@.type in ('webServer', 'aspNetApp', 'webServerFarm', 'aspNetAppFarm'))].units[?(@.temp.instanceName and not @.state.iisInstalled)]"
|
||||
desc="Units of web services which have got an instance deployed but have not got an IIS installed">
|
||||
<report entity="unit">
|
||||
<parameter name="id"><select path="id"/></parameter>
|
||||
<parameter name="text">Creating IIS Web Server on unit <select path="state.hostname"/> (<select path="name"/>)</parameter>
|
||||
</report>
|
||||
<send-command template="InstallIIS" error='exception'>
|
||||
<parameter name="unit">
|
||||
<select path="id"/>
|
||||
</parameter>
|
||||
<parameter name="service">
|
||||
<select path="::id"/>
|
||||
</parameter>
|
||||
<success>
|
||||
<set path="state.iisInstalled"><true/></set>
|
||||
<report entity="unit">
|
||||
<parameter name="id"><select path="id"/></parameter>
|
||||
<parameter name="text">IIS <select path="state.hostname"/> (<select path="name"/>) has started</parameter>
|
||||
</report>
|
||||
</success>
|
||||
<failure>
|
||||
<report entity="unit" level="error">
|
||||
<parameter name="id"><select path="id"/></parameter>
|
||||
<parameter name="text">Unable to install IIS on <select path="state.hostname"/> (<select path="name"/>) <format-error error="exception"/></parameter>
|
||||
</report>
|
||||
<stop/>
|
||||
</failure>
|
||||
</send-command>
|
||||
</rule>
|
||||
|
||||
<rule match="$.services[?(@.type in ('aspNetApp', 'aspNetAppFarm'))].units[?(@.state.iisInstalled and not @.state.webAppDeployed)]"
|
||||
desc="Units of ASP.NET app services which have got IIS installed but not the WebApplication deployed">
|
||||
<report entity="unit">
|
||||
<parameter name="id"><select path="id"/></parameter>
|
||||
<parameter name="text">Deploying WebApp <select path="::name"/> on unit <select path="state.hostname"/> (<select path="name"/>)</parameter>
|
||||
</report>
|
||||
<send-command template="DeployWebApp" error="exception">
|
||||
<parameter name="unit">
|
||||
<select path="id"/>
|
||||
</parameter>
|
||||
<parameter name="service">
|
||||
<select path="::id"/>
|
||||
</parameter>
|
||||
<parameter name="mappings">
|
||||
<map>
|
||||
<mapping name="repository">
|
||||
<select path="::repository"/>
|
||||
</mapping>
|
||||
</map>
|
||||
</parameter>
|
||||
<success>
|
||||
<set path="state.webAppDeployed"><true/></set>
|
||||
<report entity="unit">
|
||||
<parameter name="id"><select path="id"/></parameter>
|
||||
<parameter name="text">WebApp <select path="::name"/> has been deployed on unit <select path="state.hostname"/> (<select path="name"/>)</parameter>
|
||||
</report>
|
||||
</success>
|
||||
<failure>
|
||||
<report entity="unit" level="error">
|
||||
<parameter name="id"><select path="id"/></parameter>
|
||||
<parameter name="text">Unable to deploy WebApp on <select path="state.hostname"/> (<select path="name"/>) <format-error error="exception"/></parameter>
|
||||
</report>
|
||||
<stop/>
|
||||
</failure>
|
||||
</send-command>
|
||||
</rule>
|
||||
|
||||
</workflow>
|
||||
25
data3/workflows/Common.xml
Normal file
25
data3/workflows/Common.xml
Normal file
@@ -0,0 +1,25 @@
|
||||
<workflow>
|
||||
|
||||
<rule match="$.services[*].units[?(@.state.hostname is None)]" desc="Units with no hostname">
|
||||
<set path="state.hostname">
|
||||
<generate-hostname>
|
||||
<parameter name="pattern"><select path="::unitNamingPattern"/></parameter>
|
||||
<parameter name="service_id"><select path="::id"/></parameter>
|
||||
</generate-hostname>
|
||||
</set>
|
||||
</rule>
|
||||
|
||||
<rule match="$[?(not @.state.deleted)]" desc="Search through all the environments..">
|
||||
<rule match="$.services[*].units[*]" desc="If any units exists" limit="1">
|
||||
<mute/>
|
||||
<empty>
|
||||
<delete-cf-stack>
|
||||
<success>
|
||||
<set path="/state.deleted"><true/></set>
|
||||
</success>
|
||||
</delete-cf-stack>
|
||||
</empty>
|
||||
</rule>
|
||||
</rule>
|
||||
|
||||
</workflow>
|
||||
77
data3/workflows/Demo.xml
Normal file
77
data3/workflows/Demo.xml
Normal file
@@ -0,0 +1,77 @@
|
||||
<workflow>
|
||||
<rule match="$.services[?(@.type == 'demoService')].units[*]"
|
||||
desc='Service for demo purpose'>
|
||||
</rule>
|
||||
|
||||
<rule match="$.services[?(@.type == 'demoService')].units[?(@.state.hostname and not @.temp.instanceName)]"
|
||||
desc="Units of demo service having hostname and image names assigned but without instances">
|
||||
<report entity="unit">
|
||||
<parameter name="id"><select path="id"/></parameter>
|
||||
<parameter name="text">Creating instance <select path="state.hostname"/> (<select path="name"/>)</parameter>
|
||||
</report>
|
||||
<update-cf-stack template="Linux" error="exception">
|
||||
<parameter name="mappings">
|
||||
<map>
|
||||
<mapping name="instanceName"><select path="state.hostname"/></mapping>
|
||||
<mapping name="environmentId"><select path="/id"/></mapping>
|
||||
<mapping name="userData">
|
||||
<prepare-user-data template="Demo" initFile="demo_init.sh">
|
||||
<parameter name="hostname"><select path="state.hostname"/></parameter>
|
||||
<parameter name="unit"><select path="id"/></parameter>
|
||||
<parameter name="service"><select path="::id"/></parameter>
|
||||
</prepare-user-data>
|
||||
</mapping>
|
||||
<mapping name="instanceType"><select path="::flavor" default="m1.medium"/></mapping>
|
||||
<mapping name="imageName"><select path="::osImage.name"/></mapping>
|
||||
<mapping name="availabilityZone"><select path="::availabilityZone" default="nova"/></mapping>
|
||||
</map>
|
||||
</parameter>
|
||||
<success>
|
||||
<set path="temp.instanceName"><select path="name"/></set>
|
||||
<report entity="unit">
|
||||
<parameter name="id"><select path="id"/></parameter>
|
||||
<parameter name="text">Instance <select path="state.hostname"/> (<select path="name"/>) created!</parameter>
|
||||
</report>
|
||||
</success>
|
||||
<failure>
|
||||
<report entity="unit" level="error">
|
||||
<parameter name="id"><select path="id"/></parameter>
|
||||
<parameter name="text">Unable to deploy instance <select path="state.hostname"/> (<select path="name"/>) due to <format-error error="exception"/> </parameter>
|
||||
</report>
|
||||
<stop/>
|
||||
</failure>
|
||||
</update-cf-stack>
|
||||
</rule>
|
||||
|
||||
|
||||
<rule match="$.services[?(@.type == 'demoService')].units[?(@.temp.instanceName and not @.state.demoInstalled)]"
|
||||
desc="Units of demo service which have got an instance deployed but have not got demo service installed">
|
||||
<report entity="unit">
|
||||
<parameter name="id"><select path="id"/></parameter>
|
||||
<parameter name="text">Creating demo service on unit <select path="state.hostname"/> (<select path="name"/>)</parameter>
|
||||
</report>
|
||||
<send-command template="Demo" error='exception'>
|
||||
<parameter name="unit">
|
||||
<select path="id"/>
|
||||
</parameter>
|
||||
<parameter name="service">
|
||||
<select path="::id"/>
|
||||
</parameter>
|
||||
<success>
|
||||
<set path="state.demoInstalled"><true/></set>
|
||||
<report entity="unit">
|
||||
<parameter name="id"><select path="id"/></parameter>
|
||||
<parameter name="text">Demo service <select path="state.hostname"/> (<select path="name"/>) has started</parameter>
|
||||
</report>
|
||||
</success>
|
||||
<failure>
|
||||
<report entity="unit" level="error">
|
||||
<parameter name="id"><select path="id"/></parameter>
|
||||
<parameter name="text">Unable to install demo service on <select path="state.hostname"/> (<select path="name"/>) due to <format-error error="exception"/></parameter>
|
||||
</report>
|
||||
<stop/>
|
||||
</failure>
|
||||
</send-command>
|
||||
</rule>
|
||||
|
||||
</workflow>
|
||||
96
data3/workflows/ExternalAD.xml.example
Normal file
96
data3/workflows/ExternalAD.xml.example
Normal file
@@ -0,0 +1,96 @@
|
||||
<workflow>
|
||||
<rule match="$.services[?(@.type != 'activeDirectory' and @.availabilityZone)].units[?(@.temp.instanceName and @.state.hostname and not @.domain)]"
|
||||
desc="Units of Non-AD services with availability zone specified which are deployed and are not part of the domain">
|
||||
<set path="#externalADmap">
|
||||
<map>
|
||||
|
||||
|
||||
<!-- ======================================================================= -->
|
||||
<!-- Specify here parameters of domain controllers at each availability zone -->
|
||||
<!-- ======================================================================= -->
|
||||
|
||||
<mapping name="nova">
|
||||
<map>
|
||||
<mapping name="domain">domain1</mapping>
|
||||
<mapping name="domainUser">Administrator</mapping>
|
||||
<mapping name="domainPassword">password1</mapping>
|
||||
<mapping name="dnsIp">ip1</mapping>
|
||||
<mapping name="ou"></mapping>
|
||||
</map>
|
||||
</mapping>
|
||||
|
||||
<mapping name="AnotherAvailabilityZone">
|
||||
<map>
|
||||
<mapping name="domain">domain2</mapping>
|
||||
<mapping name="domainUser">Administrator</mapping>
|
||||
<mapping name="domainPassword">password2</mapping>
|
||||
<mapping name="dnsIp">ip2</mapping>
|
||||
<mapping name="ou"></mapping>
|
||||
</map>
|
||||
</mapping>
|
||||
|
||||
<!-- ======================================================================= -->
|
||||
|
||||
|
||||
</map>
|
||||
</set>
|
||||
<set path="#ad">
|
||||
<select source="externalADmap">
|
||||
<parameter name="path"><select path="::availabilityZone"/></parameter>
|
||||
</select>
|
||||
</set>
|
||||
<rule>
|
||||
<parameter name="match">$[?(@.state.domain != '<select path="domain" source="ad"/>')]</parameter>
|
||||
<parameter name="desc">Units which are not part of the target domain but need to join</parameter>
|
||||
|
||||
<send-command template="JoinDomain" error="exception">
|
||||
<parameter name="unit">
|
||||
<select path="id"/>
|
||||
</parameter>
|
||||
<parameter name="service">
|
||||
<select path="::id"/>
|
||||
</parameter>
|
||||
<parameter name="mappings">
|
||||
<map>
|
||||
<mapping name="domain">
|
||||
<select path="domain" source="ad"/>
|
||||
</mapping>
|
||||
<mapping name="domainUser">
|
||||
<select path="domainUser" source="ad"/>
|
||||
</mapping>
|
||||
<mapping name="domainPassword">
|
||||
<select path="domainPassword" source="ad"/>
|
||||
</mapping>
|
||||
<mapping name="dnsIp">
|
||||
<select path="dnsIp" source="ad"/>
|
||||
</mapping>
|
||||
<mapping name="ouPath">
|
||||
<select path="ou" source="ad"/>
|
||||
</mapping>
|
||||
</map>
|
||||
</parameter>
|
||||
|
||||
<success>
|
||||
<set path="state.domain">
|
||||
<select path="domain" source="ad"/>
|
||||
</set>
|
||||
<set path="state.domainIp">
|
||||
<select path="dnsIp" source="ad"/>
|
||||
</set>
|
||||
<report entity="unit">
|
||||
<parameter name="id"><select path="id"/></parameter>
|
||||
<parameter name="text">Unit <select path="state.hostname"/> (<select path="name"/>) has joined domain <select path="domain" source="ad"/></parameter>
|
||||
</report>
|
||||
</success>
|
||||
<failure>
|
||||
<report entity="unit" level="error">
|
||||
<parameter name="id"><select path="id"/></parameter>
|
||||
<parameter name="text">Unit <select path="state.hostname"/> (<select path="name"/>) was unable to join the domain due to <format-error error="exception"/></parameter>
|
||||
</report>
|
||||
<stop/>
|
||||
</failure>
|
||||
</send-command>
|
||||
</rule>
|
||||
</rule>
|
||||
|
||||
</workflow>
|
||||
79
data3/workflows/LinuxTelnet.xml
Normal file
79
data3/workflows/LinuxTelnet.xml
Normal file
@@ -0,0 +1,79 @@
|
||||
<workflow>
|
||||
|
||||
<rule match="$.services[?(@.type == 'linuxTelnetService')].units[?(@.state.hostname and not @.temp.instanceName)]"
|
||||
desc="Units of Linux Telnet service having hostname and image names assigned but without instances">
|
||||
<report entity="unit">
|
||||
<parameter name="id"><select path="id"/></parameter>
|
||||
<parameter name="text">Creating Linux instance <select path="state.hostname"/> (<select path="name"/>)</parameter>
|
||||
</report>
|
||||
<update-cf-stack template="Linux" error="exception">
|
||||
<parameter name="mappings">
|
||||
<map>
|
||||
<mapping name="instanceName"><select path="state.hostname"/></mapping>
|
||||
<mapping name="environmentId"><select path="/id"/></mapping>
|
||||
<mapping name="userData">
|
||||
<prepare-user-data template="Linux" initFile="linux_init.sh">
|
||||
<parameter name="hostname"><select path="state.hostname"/></parameter>
|
||||
<parameter name="unit"><select path="id"/></parameter>
|
||||
<parameter name="service"><select path="::id"/></parameter>
|
||||
</prepare-user-data>
|
||||
</mapping>
|
||||
<mapping name="instanceType"><select path="::flavor" default="m1.medium"/></mapping>
|
||||
<mapping name="imageName"><select path="::osImage.name"/></mapping>
|
||||
<mapping name="availabilityZone"><select path="::availabilityZone" default="nova"/></mapping>
|
||||
</map>
|
||||
</parameter>
|
||||
<success>
|
||||
<set path="temp.instanceName"><select path="name"/></set>
|
||||
<report entity="unit">
|
||||
<parameter name="id"><select path="id"/></parameter>
|
||||
<parameter name="text">Linux instance <select path="state.hostname"/> (<select path="name"/>) created</parameter>
|
||||
</report>
|
||||
</success>
|
||||
<failure>
|
||||
<report entity="unit" level="error">
|
||||
<parameter name="id"><select path="id"/></parameter>
|
||||
<parameter name="text">Unable to deploy Linux instance <select path="state.hostname"/> (<select path="name"/>) due to <format-error error="exception"/> </parameter>
|
||||
</report>
|
||||
<stop/>
|
||||
</failure>
|
||||
</update-cf-stack>
|
||||
</rule>
|
||||
|
||||
|
||||
<rule match="$.services[?(@.type == 'linuxTelnetService')].units[?(@.temp.instanceName and not @.state.TelnetInstalled)]"
|
||||
desc="Units of Linux Telnet service which have got an instance deployed but have not got telnet service installed">
|
||||
<report entity="unit">
|
||||
<parameter name="id"><select path="id"/></parameter>
|
||||
<parameter name="text">yum-ing telnet on unit <select path="state.hostname"/> (<select path="name"/>)</parameter>
|
||||
</report>
|
||||
<send-command template="DeployTelnet" error='exception'>
|
||||
<parameter name="unit">
|
||||
<select path="id"/>
|
||||
</parameter>
|
||||
<parameter name="service">
|
||||
<select path="::id"/>
|
||||
</parameter>
|
||||
<parameter name="mappings">
|
||||
<map>
|
||||
<mapping name="appName">telnet-server</mapping>
|
||||
</map>
|
||||
</parameter>
|
||||
<success>
|
||||
<set path="state.TelnetInstalled"><true/></set>
|
||||
<report entity="unit">
|
||||
<parameter name="id"><select path="id"/></parameter>
|
||||
<parameter name="text">Telnet deployed on <select path="state.hostname"/> (<select path="name"/>)</parameter>
|
||||
</report>
|
||||
</success>
|
||||
<failure>
|
||||
<report entity="unit" level="error">
|
||||
<parameter name="id"><select path="id"/></parameter>
|
||||
<parameter name="text">Unable to deploy Telnet on <select path="state.hostname"/> (<select path="name"/>) due to <format-error error="exception"/></parameter>
|
||||
</report>
|
||||
<stop/>
|
||||
</failure>
|
||||
</send-command>
|
||||
</rule>
|
||||
|
||||
</workflow>
|
||||
148
data3/workflows/MsSqlServer.xml
Normal file
148
data3/workflows/MsSqlServer.xml
Normal file
@@ -0,0 +1,148 @@
|
||||
<workflow>
|
||||
<rule match="$.services[?(@.type == 'msSqlServer' and @.domain)].units[*]"
|
||||
desc="Units of SQL Server services which are part of the domain">
|
||||
<set path="domain">
|
||||
<select path="::domain"/>
|
||||
</set>
|
||||
<mute/>
|
||||
</rule>
|
||||
|
||||
<rule match="$.services[?(@.type == 'msSqlServer' and @.osImage.name)].units[?(@.state.hostname and not @.temp.instanceName)]"
|
||||
desc="Units of SQL Server services having hostname and image names assigned but without instances">
|
||||
<report entity="unit">
|
||||
<parameter name="id"><select path="id"/></parameter>
|
||||
<parameter name="text">Creating instance <select path="state.hostname"/> (<select path="name"/>)</parameter>
|
||||
</report>
|
||||
<update-cf-stack template="Windows" error="exception">
|
||||
<parameter name="mappings">
|
||||
<map>
|
||||
<mapping name="instanceName"><select path="state.hostname"/></mapping>
|
||||
<mapping name="environmentId"><select path="/id"/></mapping>
|
||||
<mapping name="userData">
|
||||
<prepare-user-data>
|
||||
<parameter name="hostname"><select path="state.hostname"/></parameter>
|
||||
<parameter name="unit"><select path="id"/></parameter>
|
||||
<parameter name="service"><select path="::id"/></parameter>
|
||||
</prepare-user-data>
|
||||
</mapping>
|
||||
<mapping name="instanceType"><select path="::flavor" default="m1.medium"/></mapping>
|
||||
<mapping name="imageName"><select path="::osImage.name"/></mapping>
|
||||
<mapping name="availabilityZone"><select path="::availabilityZone" default="nova"/></mapping>
|
||||
</map>
|
||||
</parameter>
|
||||
<success>
|
||||
<set path="temp.instanceName"><select path="name"/></set>
|
||||
<report entity="unit">
|
||||
<parameter name="id"><select path="id"/></parameter>
|
||||
<parameter name="text">Instance <select path="state.hostname"/> (<select path="name"/>) created</parameter>
|
||||
</report>
|
||||
</success>
|
||||
<failure>
|
||||
<report entity="unit" level="error">
|
||||
<parameter name="id"><select path="id"/></parameter>
|
||||
<parameter name="text">Unable to deploy instance <select path="state.hostname"/> (<select path="name"/>) due to <format-error error="exception"/></parameter>
|
||||
</report>
|
||||
<stop/>
|
||||
</failure>
|
||||
</update-cf-stack>
|
||||
|
||||
<report entity="unit">
|
||||
<parameter name="id"><select path="id"/></parameter>
|
||||
<parameter name="text">Opening SQL ports on <select path="state.hostname"/> (<select path="name"/>)</parameter>
|
||||
</report>
|
||||
<update-cf-stack template="SQL-security" error="exception">
|
||||
<parameter name="mappings">
|
||||
<map>
|
||||
<mapping name="instanceName"><select path="state.hostname"/></mapping>
|
||||
</map>
|
||||
</parameter>
|
||||
<success>
|
||||
<report entity="unit">
|
||||
<parameter name="id"><select path="id"/></parameter>
|
||||
<parameter name="text">SQL ports open on <select path="state.hostname"/> (<select path="name"/>)</parameter>
|
||||
</report>
|
||||
</success>
|
||||
<failure>
|
||||
<report entity="unit" level="error">
|
||||
<parameter name="id"><select path="id"/></parameter>
|
||||
<parameter name="text">Unable to open SQL ports on instance <select path="state.hostname"/> (<select path="name"/>) due to <format-error error="exception"/></parameter>
|
||||
</report>
|
||||
<stop/>
|
||||
</failure>
|
||||
</update-cf-stack>
|
||||
</rule>
|
||||
|
||||
<rule match="$.services[?(@.type == 'msSqlServer' and @.adminPassword and @.adminPassword != @.state.adminPassword)].units[?(@.temp.instanceName)]"
|
||||
desc="Units of SQL Server services which have got an instance deployed but has not got a correct admin password">
|
||||
<send-command template="SetPassword" error="exception">
|
||||
<parameter name="unit">
|
||||
<select path="id"/>
|
||||
</parameter>
|
||||
<parameter name="service">
|
||||
<select path="::id"/>
|
||||
</parameter>
|
||||
<parameter name="mappings">
|
||||
<map>
|
||||
<mapping name="adminPassword">
|
||||
<select path="::adminPassword"/>
|
||||
</mapping>
|
||||
</map>
|
||||
</parameter>
|
||||
<success>
|
||||
<set path="::state.adminPassword">
|
||||
<select path="::adminPassword"/>
|
||||
</set>
|
||||
</success>
|
||||
<failure>
|
||||
<report entity="unit" level="warning">
|
||||
<parameter name="id"><select path="id"/></parameter>
|
||||
<parameter name="text">Unable to set admin password on unit <select path="state.hostname"/> (<select path="name"/>) due to <format-error error="exception"/></parameter>
|
||||
</report>
|
||||
<mute/>
|
||||
</failure>
|
||||
</send-command>
|
||||
</rule>
|
||||
|
||||
|
||||
<rule match="$.services[?(@.type == 'msSqlServer')].units[?(@.temp.instanceName and not @.state.msSqlServerInstalled and (not @.domain or @.domain == @.state.domain))]"
|
||||
desc="Units of SQL Server services which have got an instance deployed but have not got an SQL Server installed">
|
||||
<report entity="unit">
|
||||
<parameter name="id"><select path="id"/></parameter>
|
||||
<parameter name="text">Creating MS SQL Server on unit <select path="state.hostname"/> (<select path="name"/>)</parameter>
|
||||
</report>
|
||||
<send-command template="InstallMsSqlServer" error="exception">
|
||||
<parameter name="unit">
|
||||
<select path="id"/>
|
||||
</parameter>
|
||||
<parameter name="service">
|
||||
<select path="::id"/>
|
||||
</parameter>
|
||||
<parameter name="mappings">
|
||||
<map>
|
||||
<mapping name="saPassword">
|
||||
<select path="::saPassword"/>
|
||||
</mapping>
|
||||
<mapping name="mixedModeAuth">
|
||||
<select path="::mixedModeAuth"/>
|
||||
</mapping>
|
||||
</map>
|
||||
</parameter>
|
||||
|
||||
<success>
|
||||
<set path="state.msSqlServerInstalled"><true/></set>
|
||||
<report entity="unit">
|
||||
<parameter name="id"><select path="id"/></parameter>
|
||||
<parameter name="text">MS SQL Server <select path="state.hostname"/> (<select path="name"/>) has started</parameter>
|
||||
</report>
|
||||
</success>
|
||||
<failure>
|
||||
<report entity="unit" level="error">
|
||||
<parameter name="id"><select path="id"/></parameter>
|
||||
<parameter name="text">Unable to install MS SQL Server on unit <select path="state.hostname"/> (<select path="name"/>) due to <format-error error="exception"/></parameter>
|
||||
</report>
|
||||
<stop/>
|
||||
</failure>
|
||||
</send-command>
|
||||
</rule>
|
||||
|
||||
</workflow>
|
||||
11
data5/demo_init.sh
Normal file
11
data5/demo_init.sh
Normal file
@@ -0,0 +1,11 @@
|
||||
#!/bin/sh
|
||||
|
||||
AgentConfigBase64='%AGENT_CONFIG_BASE64%'
|
||||
|
||||
mkdir /etc/murano
|
||||
|
||||
echo $AgentConfigBase64 | base64 -d > /etc/murano/agent.config
|
||||
|
||||
chmod 664 /etc/murano/agent.config
|
||||
sleep 10
|
||||
reboot
|
||||
68
data5/init.ps1
Normal file
68
data5/init.ps1
Normal file
@@ -0,0 +1,68 @@
|
||||
#ps1
|
||||
|
||||
$WindowsAgentConfigBase64 = '%AGENT_CONFIG_BASE64%'
|
||||
$WindowsAgentConfigFile = "C:\Murano\Agent\WindowsAgent.exe.config"
|
||||
$WindowsAgentLogFile = "C:\Murano\Agent\log.txt"
|
||||
|
||||
$NewComputerName = '%INTERNAL_HOSTNAME%'
|
||||
$MuranoFileShare = '\\%MURANO_SERVER_ADDRESS%\share'
|
||||
|
||||
$CaRootCertBase64 = "%CA_ROOT_CERT_BASE64%"
|
||||
$CaRootCertFile = "C:\Murano\ca.cert"
|
||||
|
||||
$RestartRequired = $false
|
||||
|
||||
Import-Module CoreFunctions
|
||||
Initialize-Logger 'CloudBase-Init' 'C:\Murano\PowerShell.log'
|
||||
|
||||
$ErrorActionPreference = 'Stop'
|
||||
|
||||
trap {
|
||||
Write-LogError '<exception>'
|
||||
Write-LogError $_ -EntireObject
|
||||
Write-LogError '</exception>'
|
||||
exit 1
|
||||
}
|
||||
|
||||
Write-Log "Importing CA certificate ..."
|
||||
if ($CaRootCertBase64 -eq '') {
|
||||
Write-Log "Importing CA certificate ... skipped"
|
||||
}
|
||||
else {
|
||||
ConvertFrom-Base64String -Base64String $CaRootCertBase64 -Path $CaRootCertFile
|
||||
$cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2 $CaRootCertFile
|
||||
$store = New-Object System.Security.Cryptography.X509Certificates.X509Store("AuthRoot","LocalMachine")
|
||||
$store.Open("MaxAllowed")
|
||||
$store.Add($cert)
|
||||
$store.Close()
|
||||
Write-Log "Importing CA certificate ... done"
|
||||
}
|
||||
|
||||
Write-Log "Updating Murano Windows Agent."
|
||||
Stop-Service "Murano Agent"
|
||||
Backup-File $WindowsAgentConfigFile
|
||||
Remove-Item $WindowsAgentConfigFile -Force
|
||||
Remove-Item $WindowsAgentLogFile -Force
|
||||
ConvertFrom-Base64String -Base64String $WindowsAgentConfigBase64 -Path $WindowsAgentConfigFile
|
||||
Exec sc.exe 'config','"Murano Agent"','start=','delayed-auto'
|
||||
Write-Log "Service has been updated."
|
||||
|
||||
Write-Log "Adding environment variable 'MuranoFileShare' = '$MuranoFileShare' ..."
|
||||
[Environment]::SetEnvironmentVariable('MuranoFileShare', $MuranoFileShare, [EnvironmentVariableTarget]::Machine)
|
||||
Write-Log "Environment variable added."
|
||||
|
||||
Write-Log "Renaming computer to '$NewComputerName' ..."
|
||||
$null = Rename-Computer -NewName $NewComputerName -Force
|
||||
|
||||
Write-Log "New name assigned, restart required."
|
||||
$RestartRequired = $true
|
||||
|
||||
|
||||
Write-Log 'All done!'
|
||||
if ( $RestartRequired ) {
|
||||
Write-Log "Restarting computer ..."
|
||||
Restart-Computer -Force
|
||||
}
|
||||
else {
|
||||
Start-Service 'Murano Agent'
|
||||
}
|
||||
6
data5/linux_init.sh
Normal file
6
data5/linux_init.sh
Normal file
@@ -0,0 +1,6 @@
|
||||
#!/bin/sh
|
||||
|
||||
AgentConfigBase64='%AGENT_CONFIG_BASE64%'
|
||||
service murano-agent stop
|
||||
echo $AgentConfigBase64 | base64 -d > /etc/murano-agent.conf
|
||||
service murano-agent start
|
||||
36
data5/templates/agent-config/Default.template
Normal file
36
data5/templates/agent-config/Default.template
Normal file
@@ -0,0 +1,36 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<configuration>
|
||||
<configSections>
|
||||
<section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog"/>
|
||||
</configSections>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
|
||||
</startup>
|
||||
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<targets>
|
||||
<target name="file" xsi:type="File" fileName="${basedir}/log.txt"
|
||||
layout="${date} ${level}: <${logger:shortName=true}> ${message} ${exception:format=tostring}"/>
|
||||
</targets>
|
||||
|
||||
<rules>
|
||||
<logger name="*" minlevel="Debug" writeTo="file" />
|
||||
</rules>
|
||||
</nlog>
|
||||
<appSettings>
|
||||
<add key="rabbitmq.host" value="%RABBITMQ_HOST%"/>
|
||||
<add key="rabbitmq.port" value="%RABBITMQ_PORT%"/>
|
||||
<add key="rabbitmq.user" value="%RABBITMQ_USER%"/>
|
||||
<add key="rabbitmq.password" value="%RABBITMQ_PASSWORD%"/>
|
||||
<add key="rabbitmq.vhost" value="%RABBITMQ_VHOST%"/>
|
||||
<add key="rabbitmq.inputQueue" value="%RABBITMQ_INPUT_QUEUE%"/>
|
||||
<add key="rabbitmq.resultExchange" value=""/>
|
||||
<add key="rabbitmq.resultRoutingKey" value="%RESULT_QUEUE%"/>
|
||||
<add key="rabbitmq.durableMessages" value="true"/>
|
||||
|
||||
<add key="rabbitmq.ssl" value="%RABBITMQ_SSL%"/>
|
||||
<add key="rabbitmq.allowInvalidCA" value="true"/>
|
||||
<add key="rabbitmq.sslServerName" value=""/>
|
||||
|
||||
</appSettings>
|
||||
</configuration>
|
||||
8
data5/templates/agent-config/Demo.template
Normal file
8
data5/templates/agent-config/Demo.template
Normal file
@@ -0,0 +1,8 @@
|
||||
RABBITMQ_HOST = "%RABBITMQ_HOST%"
|
||||
RABBITMQ_PORT = "%RABBITMQ_PORT%"
|
||||
RABBITMQ_USERNAME = "%RABBITMQ_USER%"
|
||||
RABBITMQ_PASSWORD = "%RABBITMQ_PASSWORD%"
|
||||
RABBITMQ_VHOST = "%RABBITMQ_VHOST%"
|
||||
RABBITMQ_INPUT_QUEUE = "%RABBITMQ_INPUT_QUEUE%"
|
||||
RESULT_QUEUE = "%RESULT_QUEUE%"
|
||||
RABBITMQ_RESULT_ROUTING_KEY = "%RESULT_QUEUE%"
|
||||
35
data5/templates/agent-config/Linux.template
Normal file
35
data5/templates/agent-config/Linux.template
Normal file
@@ -0,0 +1,35 @@
|
||||
[DEFAULT]
|
||||
debug=True
|
||||
verbose=True
|
||||
log_file = /var/log/murano-agnet.log
|
||||
|
||||
storage=/var/murano/plans
|
||||
|
||||
[rabbitmq]
|
||||
|
||||
# Input queue name
|
||||
input_queue = %RABBITMQ_INPUT_QUEUE%
|
||||
|
||||
# Output routing key (usually queue name)
|
||||
result_routing_key = %RESULT_QUEUE%
|
||||
|
||||
# Connection parameters to RabbitMQ service
|
||||
|
||||
# Hostname or IP address where RabbitMQ is located.
|
||||
host = %RABBITMQ_HOST%
|
||||
|
||||
# RabbitMQ port (5672 is a default)
|
||||
port = %RABBITMQ_PORT%
|
||||
|
||||
# Use SSL for RabbitMQ connections (True or False)
|
||||
ssl = %RABBITMQ_SSL%
|
||||
|
||||
# Path to SSL CA certificate or empty to allow self signed server certificate
|
||||
ca_certs =
|
||||
|
||||
# RabbitMQ credentials. Fresh RabbitMQ installation has "guest" account with "guest" password.
|
||||
login = %RABBITMQ_USER%
|
||||
password = %RABBITMQ_PASSWORD%
|
||||
|
||||
# RabbitMQ virtual host (vhost). Fresh RabbitMQ installation has "/" vhost preconfigured.
|
||||
virtual_host = %RABBITMQ_VHOST%
|
||||
12
data5/templates/agent/AskDnsIp.template
Normal file
12
data5/templates/agent/AskDnsIp.template
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"Scripts": [
|
||||
"Get-DnsListeningIpAddress.ps1"
|
||||
],
|
||||
"Commands": [
|
||||
{
|
||||
"Name": "Get-DnsListeningIpAddress",
|
||||
"Arguments": {}
|
||||
}
|
||||
],
|
||||
"RebootOnCompletion": 0
|
||||
}
|
||||
16
data5/templates/agent/CreatePrimaryDC.template
Normal file
16
data5/templates/agent/CreatePrimaryDC.template
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"Scripts": [
|
||||
"ImportCoreFunctions.ps1",
|
||||
"Install-RolePrimaryDomainController.ps1"
|
||||
],
|
||||
"Commands": [
|
||||
{
|
||||
"Name": "Install-RolePrimaryDomainController",
|
||||
"Arguments": {
|
||||
"DomainName": "$domain",
|
||||
"SafeModePassword": "$recoveryPassword"
|
||||
}
|
||||
}
|
||||
],
|
||||
"RebootOnCompletion": 1
|
||||
}
|
||||
18
data5/templates/agent/CreateSecondaryDC.template
Normal file
18
data5/templates/agent/CreateSecondaryDC.template
Normal file
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"Scripts": [
|
||||
"ImportCoreFunctions.ps1",
|
||||
"Install-RoleSecondaryDomainController.ps1"
|
||||
],
|
||||
"Commands": [
|
||||
{
|
||||
"Name": "Install-RoleSecondaryDomainController",
|
||||
"Arguments": {
|
||||
"DomainName": "$domain",
|
||||
"UserName": "Administrator",
|
||||
"Password": "$domainPassword",
|
||||
"SafeModePassword": "$recoveryPassword"
|
||||
}
|
||||
}
|
||||
],
|
||||
"RebootOnCompletion": 1
|
||||
}
|
||||
7
data5/templates/agent/Demo.template
Normal file
7
data5/templates/agent/Demo.template
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"Scripts": [
|
||||
],
|
||||
"Commands": [
|
||||
],
|
||||
"RebootOnCompletion": 0
|
||||
}
|
||||
21
data5/templates/agent/DeployApache.template
Normal file
21
data5/templates/agent/DeployApache.template
Normal file
@@ -0,0 +1,21 @@
|
||||
FormatVersion: 2.0.0
|
||||
Version: 1.0.0
|
||||
Name: Deploy Apache
|
||||
|
||||
Parameters:
|
||||
enablePHP: $enablePHP
|
||||
|
||||
Body: |
|
||||
return apacheDeploy('{0}'.format(args.enablePHP)).stdout
|
||||
|
||||
Scripts:
|
||||
apacheDeploy:
|
||||
Type: Application
|
||||
Version: 1.0.0
|
||||
EntryPoint: Linux/runApacheDeploy.sh
|
||||
Files:
|
||||
- <Linux/installer.sh>
|
||||
- <Linux/common.sh>
|
||||
Options:
|
||||
captureStdout: true
|
||||
captureStderr: true
|
||||
23
data5/templates/agent/DeployTelnet.template
Normal file
23
data5/templates/agent/DeployTelnet.template
Normal file
@@ -0,0 +1,23 @@
|
||||
FormatVersion: 2.0.0
|
||||
Version: 1.0.0
|
||||
Name: Deploy Telnet
|
||||
|
||||
Parameters:
|
||||
appName: $appName
|
||||
|
||||
|
||||
Body: |
|
||||
return telnetDeploy(args.appName).stdout
|
||||
|
||||
Scripts:
|
||||
telnetDeploy:
|
||||
Type: Application
|
||||
Version: 1.0.0
|
||||
EntryPoint: Linux/runTelnetDeploy.sh
|
||||
Files:
|
||||
- <Linux/installer.sh>
|
||||
- <Linux/common.sh>
|
||||
Options:
|
||||
captureStdout: true
|
||||
captureStderr: false
|
||||
|
||||
15
data5/templates/agent/DeployWebApp.template
Normal file
15
data5/templates/agent/DeployWebApp.template
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"Scripts": [
|
||||
"ImportCoreFunctions.ps1",
|
||||
"DeployWebApp.ps1"
|
||||
],
|
||||
"Commands": [
|
||||
{
|
||||
"Name": "Deploy-WebAppFromGit",
|
||||
"Arguments": {
|
||||
"URL": "$repository"
|
||||
}
|
||||
}
|
||||
],
|
||||
"RebootOnCompletion": 0
|
||||
}
|
||||
22
data5/templates/agent/InstallIIS.template
Normal file
22
data5/templates/agent/InstallIIS.template
Normal file
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"Scripts": [
|
||||
"ImportCoreFunctions.ps1",
|
||||
"CopyPrerequisites.ps1",
|
||||
"InstallIIS.ps1"
|
||||
],
|
||||
"Commands": [
|
||||
{
|
||||
"Name": "Copy-Prerequisites",
|
||||
"Arguments": {
|
||||
"Destination": "C:\\Prerequisites"
|
||||
}
|
||||
},
|
||||
{
|
||||
"Name": "Install-WebServer",
|
||||
"Arguments": {
|
||||
"PrerequisitesPath": "C:\\Prerequisites"
|
||||
}
|
||||
}
|
||||
],
|
||||
"RebootOnCompletion": 0
|
||||
}
|
||||
24
data5/templates/agent/InstallMsSqlServer.template
Normal file
24
data5/templates/agent/InstallMsSqlServer.template
Normal file
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"Scripts": [
|
||||
"/ImportCoreFunctions.ps1",
|
||||
"/OptionParser.ps1",
|
||||
"SQLServer/SQLServerOptionParsers.ps1",
|
||||
"SQLServer/SQLServerInstaller.ps1",
|
||||
"SQLServer/Install-SQLServer.ps1",
|
||||
"/Alter-FirewallRulesForSQL.ps1"
|
||||
],
|
||||
"Commands": [
|
||||
{
|
||||
"Name": "Install-SQLServer",
|
||||
"Arguments": {
|
||||
"SAPassword": "$saPassword",
|
||||
"MixedModeAuth": "$mixedModeAuth"
|
||||
}
|
||||
},
|
||||
{
|
||||
"Name": "Enable-SQLExternalAccess",
|
||||
"Arguments": {}
|
||||
}
|
||||
],
|
||||
"RebootOnCompletion": 0
|
||||
}
|
||||
25
data5/templates/agent/JoinDomain.template
Normal file
25
data5/templates/agent/JoinDomain.template
Normal file
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"Scripts": [
|
||||
"ImportCoreFunctions.ps1",
|
||||
"Join-Domain.ps1"
|
||||
],
|
||||
"Commands": [
|
||||
{
|
||||
"Name": "Set-NetworkAdapterConfiguration",
|
||||
"Arguments": {
|
||||
"FirstAvailable": true,
|
||||
"DNSServer": "$dnsIp"
|
||||
}
|
||||
},
|
||||
{
|
||||
"Name": "Join-Domain",
|
||||
"Arguments": {
|
||||
"Username": "$domainUser",
|
||||
"Password": "$domainPassword",
|
||||
"DomainName": "$domain",
|
||||
"OUPath": "$ouPath"
|
||||
}
|
||||
}
|
||||
],
|
||||
"RebootOnCompletion": 1
|
||||
}
|
||||
5
data5/templates/agent/LeaveDomain.template
Normal file
5
data5/templates/agent/LeaveDomain.template
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"Scripts": [],
|
||||
"Commands": [],
|
||||
"RebootOnCompletion": 0,
|
||||
}
|
||||
17
data5/templates/agent/SetPassword.template
Normal file
17
data5/templates/agent/SetPassword.template
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"Scripts": [
|
||||
"ImportCoreFunctions.ps1",
|
||||
"Set-LocalUserPassword.ps1"
|
||||
],
|
||||
"Commands": [
|
||||
{
|
||||
"Name": "Set-LocalUserPassword",
|
||||
"Arguments": {
|
||||
"UserName": "Administrator",
|
||||
"Password": "$adminPassword",
|
||||
"Force": true
|
||||
}
|
||||
}
|
||||
],
|
||||
"RebootOnCompletion": 0
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"Scripts": [
|
||||
"/ImportCoreFunctions.ps1",
|
||||
"SQLServerForAOAG.ps1"
|
||||
],
|
||||
"Commands": [
|
||||
{
|
||||
"Name": "Enable-TrustedHosts",
|
||||
"Arguments": {}
|
||||
},
|
||||
{
|
||||
"Name": "New-SharedFolderForAOAG",
|
||||
"Arguments": {
|
||||
"PrimaryNode": "$primaryNode"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"Scripts": [
|
||||
"/ImportCoreFunctions.ps1",
|
||||
"/Start-PowerShellProcess.ps1",
|
||||
"/Failover-Cluster.ps1"
|
||||
],
|
||||
"Commands": [
|
||||
{
|
||||
"Name": "New-FailoverCluster",
|
||||
"Arguments": {
|
||||
"UserName": "$domainAdminAccountName",
|
||||
"ClusterNodes": "$clusterNodes",
|
||||
"DomainName": "$domainName",
|
||||
"ClusterName": "$clusterName",
|
||||
"UserPassword": "$domainAdminAccountPassword",
|
||||
"StaticAddress": "$clusterIp"
|
||||
}
|
||||
}
|
||||
],
|
||||
"RebootOnCompletion": 0
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"Scripts": [
|
||||
"/ImportCoreFunctions.ps1",
|
||||
"/Update-ServiceConfig.ps1",
|
||||
"SQLServerForAOAG.ps1",
|
||||
"/Failover-Cluster.ps1"
|
||||
],
|
||||
"Commands": [
|
||||
{
|
||||
"Name": "Install-FailoverClusterPrerequisites",
|
||||
"Arguments": {}
|
||||
},
|
||||
{
|
||||
"Name": "Enable-TrustedHosts",
|
||||
"Arguments": {}
|
||||
},
|
||||
{
|
||||
"Name": "Update-ServiceConfig",
|
||||
"Arguments": {
|
||||
"Password": "$domainAdminAccountPassword",
|
||||
"Name": "Murano Agent",
|
||||
"RunAsUser": "$domainAdminAccountName",
|
||||
"DomainName": "$domainName"
|
||||
}
|
||||
}
|
||||
],
|
||||
"RebootOnCompletion": 1
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"Scripts": [
|
||||
"/ImportCoreFunctions.ps1",
|
||||
"/OptionParser.ps1",
|
||||
"/SQLServer/SQLServerOptionParsers.ps1",
|
||||
"/SQLServer/SQLServerInstaller.ps1",
|
||||
"/Export-Function.ps1",
|
||||
"/Start-PowerShellProcess.ps1",
|
||||
"SQLServerForAOAG.ps1"
|
||||
],
|
||||
"Commands": [
|
||||
{
|
||||
"Name": "Initialize-AOAGPrimaryReplica",
|
||||
"Arguments": {
|
||||
"UserName": "$domainAdminAccountName",
|
||||
"NodeList": "$nodeList",
|
||||
"PrimaryNode": "$primaryNode",
|
||||
"DomainName": "$domainName",
|
||||
"UserPassword": "$domainAdminAccountPassword",
|
||||
"GroupName": "$groupName",
|
||||
"ListenerName": "$listenerName",
|
||||
"SyncModeNodeList": "$syncModeNodeList",
|
||||
"ListenerIP": "$listenerIP",
|
||||
"DatabaseList": "$databaseList"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"Scripts": [
|
||||
"/ImportCoreFunctions.ps1",
|
||||
"/OptionParser.ps1",
|
||||
"/SQLServer/SQLServerOptionParsers.ps1",
|
||||
"/SQLServer/SQLServerInstaller.ps1",
|
||||
"/Export-Function.ps1",
|
||||
"/Start-PowerShellProcess.ps1",
|
||||
"SQLServerForAOAG.ps1"
|
||||
],
|
||||
"Commands": [
|
||||
{
|
||||
"Name": "Initialize-AOAGSecondaryReplica",
|
||||
"Arguments": {
|
||||
"UserName": "$domainAdminAccountName",
|
||||
"UserPassword": "$domainAdminAccountPassword",
|
||||
"NodeList": "$nodeList",
|
||||
"PrimaryNode": "$primaryNode",
|
||||
"DomainName": "$domainName"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"Scripts": [
|
||||
"/ImportCoreFunctions.ps1",
|
||||
"/OptionParser.ps1",
|
||||
"/SQLServer/SQLServerOptionParsers.ps1",
|
||||
"/SQLServer/SQLServerInstaller.ps1",
|
||||
"/Export-Function.ps1",
|
||||
"/Start-PowerShellProcess.ps1",
|
||||
"SQLServerForAOAG.ps1"
|
||||
],
|
||||
"Commands": [
|
||||
{
|
||||
"Name": "Initialize-AlwaysOnAvailabilityGroup",
|
||||
"Arguments": {
|
||||
"DomainAdminAccountName": "$domainAdminAccountName",
|
||||
"DomainAdminAccountPassword": "$domainAdminAccountPassword",
|
||||
"NodeList": "$nodeList",
|
||||
"PrimaryNode": "$primaryNode",
|
||||
"DomainName": "$domainName"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
{
|
||||
"Scripts": [
|
||||
"/ImportCoreFunctions.ps1",
|
||||
"/OptionParser.ps1",
|
||||
"/SQLServer/SQLServerOptionParsers.ps1",
|
||||
"/SQLServer/SQLServerInstaller.ps1",
|
||||
"SQLServerForAOAG.ps1"
|
||||
],
|
||||
"Commands": [
|
||||
{
|
||||
"Name": "Disable-Firewall",
|
||||
"Arguments": {}
|
||||
},
|
||||
{
|
||||
"Name": "Install-SQLServerForAOAG",
|
||||
"Arguments": {
|
||||
"SQLServiceUserPassword": "$domainAdminAccountPassword",
|
||||
"SQLServiceUserDomain": "$domainName",
|
||||
"SQLServiceUserName": "$domainAdminAccountName"
|
||||
}
|
||||
},
|
||||
{
|
||||
"Name": "Install-SqlServerPowerShellModule",
|
||||
"Arguments": {}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,538 @@
|
||||
|
||||
trap {
|
||||
&$TrapHandler
|
||||
}
|
||||
|
||||
function Install-SqlServerPowerShellModule {
|
||||
param (
|
||||
[String] $SetupRoot = ''
|
||||
)
|
||||
begin {
|
||||
Show-InvocationInfo $MyInvocation
|
||||
}
|
||||
end {
|
||||
Show-InvocationInfo $MyInvocation -End
|
||||
}
|
||||
process {
|
||||
trap {
|
||||
&$TrapHandler
|
||||
}
|
||||
|
||||
if ((Get-Module SQLPS -ListAvailable) -ne $null) {
|
||||
Write-Log "Module SQLSP already installed."
|
||||
return
|
||||
}
|
||||
|
||||
if ($MuranoFileShare -eq '') {
|
||||
$MuranoFileShare = [String]([Environment]::GetEnvironmentVariable('MuranoFileShare'))
|
||||
if ($MuranoFileShare -eq '') {
|
||||
throw "Unable to find MuranoFileShare path."
|
||||
}
|
||||
}
|
||||
Write-LogDebug "MuranoFileShare = '$MuranoFileShare'"
|
||||
|
||||
if ($SetupRoot -eq '') {
|
||||
$SetupRoot = [IO.Path]::Combine("$MuranoFileShare", 'Prerequisites\SQL Server\Tools')
|
||||
}
|
||||
Write-LogDebug "SetupRoot = '$SetupRoot'"
|
||||
|
||||
$FileList = @(
|
||||
'SQLSysClrTypes.msi',
|
||||
'SharedManagementObjects.msi',
|
||||
'PowerShellTools.msi'
|
||||
)
|
||||
|
||||
foreach ($MsiFile in $FileList) {
|
||||
Write-Log "Trying to install '$MsiFile' ..."
|
||||
$MsiPath = Join-Path $SetupRoot $MsiFile
|
||||
if ([IO.File]::Exists($MsiPath)) {
|
||||
Write-Log "Starting msiexe ..."
|
||||
$Result = Exec -FilePath "msiexec.exe" -ArgumentList @('/i', "`"$MsiPath`"", '/quiet') -PassThru
|
||||
if ($Result.ExitCode -ne 0) {
|
||||
throw "Installation of MSI package '$MsiPath' failed with error code '$($Result.ExitCode)'"
|
||||
}
|
||||
}
|
||||
else {
|
||||
Write-Log "File '$MsiPath' not found."
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
function Install-SqlServerForAOAG {
|
||||
param (
|
||||
# Path to folder where msi files for additional SQL features are located
|
||||
[String] $SetupRoot = '',
|
||||
|
||||
# Path to folder where msi files for additional SQLPS module are located
|
||||
[String] $SqlpsSetupRoot = '',
|
||||
|
||||
[String] $MuranoFileShare = '',
|
||||
|
||||
# (REQUIRED) Domain name
|
||||
[String] $SQLServiceUserDomain = 'fc-acme.local',
|
||||
|
||||
# (REQUIRED) User name for the account which will be used by SQL service
|
||||
[String] $SQLServiceUserName = 'Administrator',
|
||||
|
||||
# (REQUIRED) Password for that user
|
||||
[String] $SQLServiceUserPassword = 'P@ssw0rd',
|
||||
|
||||
[Switch] $UpdateEnabled
|
||||
)
|
||||
begin {
|
||||
Show-InvocationInfo $MyInvocation
|
||||
}
|
||||
end {
|
||||
Show-InvocationInfo $MyInvocation -End
|
||||
}
|
||||
process {
|
||||
trap {
|
||||
&$TrapHandler
|
||||
}
|
||||
|
||||
if ($MuranoFileShare -eq '') {
|
||||
$MuranoFileShare = [String]([Environment]::GetEnvironmentVariable('MuranoFileShare'))
|
||||
if ($MuranoFileShare -eq '') {
|
||||
throw "Unable to find MuranoFileShare path."
|
||||
}
|
||||
}
|
||||
Write-LogDebug "MuranoFileShare = '$MuranoFileShare'"
|
||||
|
||||
if ($SetupRoot -eq '') {
|
||||
$SetupRoot = [IO.Path]::Combine("$MuranoFileShare", 'Prerequisites\SQL Server\2012')
|
||||
}
|
||||
Write-LogDebug "SetupRoot = '$SetupRoot'"
|
||||
|
||||
$ExtraOptions = @{}
|
||||
|
||||
if ($UpdateEnabled) {
|
||||
$ExtraOptions += @{'UpdateEnabled' = $true}
|
||||
}
|
||||
else {
|
||||
$ExtraOptions += @{'UpdateEnabled' = $false}
|
||||
}
|
||||
|
||||
$null = New-SQLServerForAOAG `
|
||||
-SetupRoot $SetupRoot `
|
||||
-SQLSvcUsrDomain $SQLServiceUserDomain `
|
||||
-SQLSvcUsrName $SQLServiceUserName `
|
||||
-SQLSvcUsrPassword $SQLServiceUserPassword `
|
||||
-ExtraOptions $ExtraOptions
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
function Initialize-AlwaysOnAvailabilityGroup {
|
||||
param (
|
||||
[String] $DomainName,
|
||||
[String] $DomainAdminAccountName,
|
||||
[String] $DomainAdminAccountPassword,
|
||||
[String] $SqlServiceAccountName,
|
||||
[String] $PrimaryNode,
|
||||
[String] $ShareName = 'SharedWorkDir'
|
||||
)
|
||||
begin {
|
||||
Show-InvocationInfo $MyInvocation
|
||||
}
|
||||
end {
|
||||
Show-InvocationInfo $MyInvocation -End
|
||||
}
|
||||
process {
|
||||
trap {
|
||||
&$TrapHandler
|
||||
}
|
||||
|
||||
$ShareNetworkPath = '\\' + $PrimaryNode + '\' + $ShareName
|
||||
|
||||
$DomainAdminAccountCreds = New-Credential `
|
||||
-UserName "$DomainName\$DomainAdminAccountName" `
|
||||
-Password "$DomainAdminAccountPassword"
|
||||
|
||||
$FunctionsFile = Export-Function 'Get-NextFreePort', 'Initialize-AlwaysOn'
|
||||
|
||||
$null = Start-PowerShellProcess @"
|
||||
trap {
|
||||
`$_
|
||||
exit 1
|
||||
}
|
||||
|
||||
Import-Module CoreFunctions
|
||||
|
||||
Write-Log "Importing functions file '$FunctionsFile' ..."
|
||||
. "$FunctionsFile"
|
||||
|
||||
Write-Log "Starting 'Initialize-AlwaysOn' ..."
|
||||
`$XmlFile = [IO.Path]::Combine("$ShareNetworkPath", "`$(`$Env:ComputerName).xml")
|
||||
Write-Log "Output XML file is '`$XmlFile'"
|
||||
Initialize-AlwaysOn | Export-CliXml -Path `$XmlFile
|
||||
"@ -Credential $DomainAdminAccountCreds -NoBase64
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function New-SharedFolderForAOAG {
|
||||
param (
|
||||
# (OPTIONAL)
|
||||
[String] $SharePath = [IO.Path]::Combine($Env:SystemDrive + '\', 'SharedWorkDir'),
|
||||
|
||||
# (OPTIONAL)
|
||||
[String] $ShareName = 'SharedWorkDir',
|
||||
|
||||
[String] $PrimaryNode = ' '
|
||||
)
|
||||
begin {
|
||||
Show-InvocationInfo $MyInvocation
|
||||
}
|
||||
end {
|
||||
Show-InvocationInfo $MyInvocation -End
|
||||
}
|
||||
process {
|
||||
trap {
|
||||
&$TrapHandler
|
||||
}
|
||||
|
||||
if ($PrimaryNode.ToLower() -ne ($Env:ComputerName).ToLower()) {
|
||||
Write-Log "This script runs on primary node only."
|
||||
Write-Log "Exiting script."
|
||||
return
|
||||
}
|
||||
|
||||
if ($ShareName -eq '') {
|
||||
$ShareName = [IO.Path]::GetFileNameWithoutExtension($SharePath)
|
||||
}
|
||||
|
||||
Write-LogDebug "SharePath = '$SharePath'"
|
||||
Write-LogDebug "ShareName = '$ShareName'"
|
||||
|
||||
try {
|
||||
Write-LogDebug "Trying to remove share '$ShareName'"
|
||||
$null = Get-SmbShare -Name $ShareName -ErrorAction 'Stop'
|
||||
$null = Remove-SmbShare -Name $ShareName -Force
|
||||
write-Log "Share '$ShareName' removed."
|
||||
}
|
||||
catch {
|
||||
Write-LogWarning "Share '$ShareName' not exists or cannot be deleted."
|
||||
}
|
||||
|
||||
try {
|
||||
Write-LogDebug "Trying to remove folder '$SharePath"
|
||||
$null = Get-Item -Path $SharePath -ErrorAction 'Stop'
|
||||
$null = Remove-Item -Path $SharePath -Recurse -Force
|
||||
Write-Log "Folder '$SharePath' removed."
|
||||
}
|
||||
catch {
|
||||
Write-LogWarning "Folder '$SharePath' not exists or cannot be deleted."
|
||||
}
|
||||
|
||||
$null = New-Item -Path $SharePath -ItemType Container -Force
|
||||
|
||||
$null = New-SmbShare -Path $SharePath `
|
||||
-Name $ShareName `
|
||||
-FullAccess "Everyone" `
|
||||
-Description "Shared folder for AlwaysOn Availability Group setup."
|
||||
|
||||
return '\\' + $Env:ComputerName + '\' + $ShareName
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
function New-DatabaseForAOAG {
|
||||
param (
|
||||
[String] $DatabaseName,
|
||||
[String] $DomainName,
|
||||
[String] $UserName,
|
||||
[String] $UserPassword
|
||||
)
|
||||
|
||||
$Creds = New-Credential -UserName "$DomainName\$UserName" -Password "$UserPassword"
|
||||
|
||||
$FunctionsFile = Export-Function 'Invoke-SQLText', 'ConvertTo-SQLName', 'ConvertTo-SQLString', 'New-SQLDatabase'
|
||||
|
||||
Start-PowerShellProcess @"
|
||||
trap {
|
||||
`$_
|
||||
exit 1
|
||||
}
|
||||
|
||||
Import-Module CoreFunctions
|
||||
|
||||
Write-Log "Importing functions from file '$FunctionsFile' ..."
|
||||
. "$FunctionsFile"
|
||||
|
||||
Write-Log "Starting 'New-SQLDatabase' ..."
|
||||
New-SQLDatabase $DatabaseName
|
||||
"@ -Credential $Creds -NoBase64
|
||||
}
|
||||
|
||||
|
||||
|
||||
function Initialize-AOAGPrimaryReplica {
|
||||
param (
|
||||
# (OPTIONAL) Name of the new Availability Group. If not specified then default name will be used.
|
||||
[String] $GroupName = 'MuranoAG',
|
||||
|
||||
# (REQUIRED) Nodes that will be configured as replica partners.
|
||||
#[Parameter(Mandatory=$true)]
|
||||
[String[]] $NodeList,
|
||||
|
||||
# (REQUIRED) Node name that will be primary for selected Availability Group
|
||||
#[Parameter(Mandatory=$true)]
|
||||
[String] $PrimaryNode,
|
||||
|
||||
# (REQUIRED) Database list that will be added to the Availability Group
|
||||
#[Parameter(Mandatory=$true)]
|
||||
[String[]] $DatabaseList,
|
||||
|
||||
# (REQUIRED) Listener name that will be used by clients to connect to databases in that AG
|
||||
#[Parameter(Mandatory=$true)]
|
||||
[String] $ListenerName = 'MuranoAG_Listener',
|
||||
|
||||
# (REQUIRED) IP address of the listener
|
||||
#[Parameter(Mandatory=$true)]
|
||||
[String] $ListenerIP,
|
||||
|
||||
[String] $ListenerIPMask = '255.255.255.0',
|
||||
|
||||
[String] $ListenerPort = '5023',
|
||||
|
||||
# Sync Mode Node List
|
||||
[String[]] $SyncModeNodeList,
|
||||
|
||||
[String] $SharedWorkDir = 'SharedWorkDir',
|
||||
|
||||
[String] $CliXmlFile = '',
|
||||
|
||||
[String] $DomainName,
|
||||
[String] $UserName,
|
||||
[String] $UserPassword
|
||||
)
|
||||
begin {
|
||||
Show-InvocationInfo $MyInvocation
|
||||
}
|
||||
end {
|
||||
Show-InvocationInfo $MyInvocation -End
|
||||
}
|
||||
process {
|
||||
trap {
|
||||
&$TrapHandler
|
||||
}
|
||||
|
||||
Write-Log "Primary node: '$($PrimaryNode.ToLower())'"
|
||||
Write-Log "Current node: '$(($Env:ComputerName).ToLower())'"
|
||||
|
||||
if ($PrimaryNode.ToLower() -ne $($Env:ComputerName).ToLower()) {
|
||||
Write-Log "This function works on PrimaryNode only."
|
||||
Write-Log "Exiting."
|
||||
return
|
||||
}
|
||||
|
||||
if ($CliXmlFile -eq '') {
|
||||
$ReplicaDefinitionList = @()
|
||||
foreach ($Node in $NodeList) {
|
||||
try {
|
||||
$NodeEndpointPort = Import-CliXml -Path "\\$PrimaryNode\SharedWorkDir\$Node.xml"
|
||||
}
|
||||
catch {
|
||||
Write-Log "Using default endpoint port 5022"
|
||||
$NodeEndpointPort = 5022
|
||||
}
|
||||
|
||||
$ReplicaDefinition = @{
|
||||
"SERVER_INSTANCE" = "$Node";
|
||||
"ENDPOINT_URL" = "TCP://${Node}:${NodeEndpointPort}";
|
||||
"AVAILABILITY_MODE" = "ASYNCHRONOUS_COMMIT";
|
||||
"FAILOVER_MODE"="MANUAL";
|
||||
}
|
||||
|
||||
if ($SyncModeNodeList -contains $Node) {
|
||||
Write-Log "$Node is in SyncModeNodeList"
|
||||
$ReplicaDefinition['AVAILABILITY_MODE'] = "SYNCHRONOUS_COMMIT"
|
||||
$ReplicaDefinition['FAILOVER_MODE'] = "AUTOMATIC"
|
||||
}
|
||||
else {
|
||||
Write-Log "$Node is NOT in SyncModeNodeList"
|
||||
}
|
||||
|
||||
$ReplicaDefinitionList += @($ReplicaDefinition)
|
||||
}
|
||||
|
||||
$Preferences = @{}
|
||||
|
||||
$ListenerDefinition = @{
|
||||
"NAME"=$ListenerName;
|
||||
"PORT" = "$ListenerPort";
|
||||
"STATIC" = "$ListenerIP/$ListenerIPMask"
|
||||
}
|
||||
|
||||
$Parameters = @{
|
||||
'WorkDir' = "\\$PrimaryNode\$SharedWorkDir";
|
||||
'Name' = $GroupName;
|
||||
'DatabaseNames' = $DatabaseList;
|
||||
'ReplicaDefs' = $ReplicaDefinitionList;
|
||||
'Preferences' = $Preferences;
|
||||
'ListenerDef' = $ListenerDefinition;
|
||||
}
|
||||
|
||||
$null = Remove-Item -Path "\\$PrimaryNode\SharedWorkDir\*" -Force
|
||||
|
||||
$CliXmlFile = [IO.Path]::GetTempFileName()
|
||||
|
||||
Write-LogDebug "CliXml file: '$CliXmlFile'"
|
||||
|
||||
$null = Export-CliXml -Path $CliXmlFile -InputObject $Parameters -Depth 10
|
||||
|
||||
$null = Initialize-AOAGPrimaryReplica `
|
||||
-CliXmlFile $CliXmlFile `
|
||||
-DomainName $DomainName `
|
||||
-UserName $UserName `
|
||||
-UserPassword $UserPassword `
|
||||
-PrimaryNode $PrimaryNode
|
||||
|
||||
Write-LogDebug "Inner 'Initialize-AOAGPrimaryReplica' call completed."
|
||||
}
|
||||
else {
|
||||
$Creds = New-Credential -UserName "$DomainName\$UserName" -Password "$UserPassword"
|
||||
|
||||
$FunctionsFile = Export-Function -All
|
||||
|
||||
$null = Start-PowerShellProcess @"
|
||||
trap {
|
||||
`$_
|
||||
exit 1
|
||||
}
|
||||
|
||||
Import-Module CoreFunctions
|
||||
|
||||
Write-Log "Importing functions from '$FunctionsFile' ..."
|
||||
. "$FunctionsFile"
|
||||
|
||||
Write-Log "Importing CliXml parameters file ..."
|
||||
`$Parameters = Import-CliXml -Path $CliXmlFile
|
||||
|
||||
Write-Log "Starting 'New-AlwaysOnAvailabilityGroup' ..."
|
||||
New-AlwaysOnAvailabilityGroup ``
|
||||
-WorkDir `$Parameters['WorkDir'] ``
|
||||
-Name `$Parameters['Name'] ``
|
||||
-DatabaseNames `$Parameters['DatabaseNames'] ``
|
||||
-ReplicaDefs `$Parameters['ReplicaDefs'] ``
|
||||
-Preferences `$Parameters['Preferences'] ``
|
||||
-ListenerDef `$Parameters['ListenerDef']
|
||||
"@ -Credential $Creds -NoBase64
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
function Initialize-AOAGSecondaryReplica {
|
||||
param (
|
||||
# (REQUIRED) Nodes that will be configured as replica partners.
|
||||
[Parameter(Mandatory=$true)]
|
||||
[String[]] $NodeList,
|
||||
|
||||
# (REQUIRED) Node name that will be primary for selected Availability Group
|
||||
[Parameter(Mandatory=$true)]
|
||||
[String] $PrimaryNode,
|
||||
|
||||
[String] $SharedWorkDir = 'SharedWorkDir',
|
||||
|
||||
[String] $DomainName,
|
||||
[String] $UserName,
|
||||
[String] $UserPassword
|
||||
)
|
||||
begin {
|
||||
Show-InvocationInfo $MyInvocation
|
||||
}
|
||||
end {
|
||||
Show-InvocationInfo $MyInvocation -End
|
||||
}
|
||||
process {
|
||||
trap {
|
||||
&$TrapHandler
|
||||
}
|
||||
|
||||
if ($PrimaryNode.ToLower() -eq ($Env:ComputerName).ToLower()) {
|
||||
Write-Log "This function works on any SecondaryNode only."
|
||||
Write-Log "Exiting."
|
||||
return
|
||||
}
|
||||
|
||||
$Creds = New-Credential -UserName "$DomainName\$UserName" -Password "$UserPassword"
|
||||
|
||||
$FunctionsFile = Export-Function -All
|
||||
|
||||
$null = Start-PowerShellProcess @"
|
||||
trap {
|
||||
$_
|
||||
exit 1
|
||||
}
|
||||
|
||||
Import-Module CoreFunctions
|
||||
|
||||
Write-Log "Importing functions from '$FunctionsFile' ..."
|
||||
. "$FunctionsFile"
|
||||
|
||||
Write-Log "Starting 'New-AlwaysOnAvailabilityGroupReplica' ..."
|
||||
New-AlwaysOnAvailabilityGroupReplica -WorkDir "\\$PrimaryNode\$SharedWorkDir"
|
||||
"@ -Credential $Creds -NoBase64
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
function Disable-Firewall {
|
||||
begin {
|
||||
Show-InvocationInfo $MyInvocation
|
||||
}
|
||||
end {
|
||||
Show-InvocationInfo $MyInvocation -End
|
||||
}
|
||||
process {
|
||||
trap {
|
||||
&$TrapHandler
|
||||
}
|
||||
|
||||
netsh advfirewall set allprofiles state off
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
function Enable-Firewall {
|
||||
begin {
|
||||
Show-InvocationInfo $MyInvocation
|
||||
}
|
||||
end {
|
||||
Show-InvocationInfo $MyInvocation -End
|
||||
}
|
||||
process {
|
||||
trap {
|
||||
&$TrapHandler
|
||||
}
|
||||
|
||||
netsh advfirewall set allprofiles state on
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
function Enable-TrustedHosts {
|
||||
begin {
|
||||
Show-InvocationInfo $MyInvocation
|
||||
}
|
||||
end {
|
||||
Show-InvocationInfo $MyInvocation -End
|
||||
}
|
||||
process {
|
||||
trap {
|
||||
&$TrapHandler
|
||||
}
|
||||
|
||||
Set-Item WSMan:\localhost\Client\TrustedHosts -Value '*' -Force
|
||||
}
|
||||
}
|
||||
61
data5/templates/agent/scripts/Alter-FirewallRulesForSQL.ps1
Normal file
61
data5/templates/agent/scripts/Alter-FirewallRulesForSQL.ps1
Normal file
@@ -0,0 +1,61 @@
|
||||
trap {
|
||||
&$TrapHandler
|
||||
}
|
||||
|
||||
|
||||
$FW_Rules = @{
|
||||
"SQL Server Data Connection" = "1433";
|
||||
"SQL Admin Connection" = "1434";
|
||||
"SQL Service Broker" = "4022";
|
||||
"SQL Debugger/RPC"="135";
|
||||
}
|
||||
|
||||
|
||||
$FW_Proto = "TCP"
|
||||
|
||||
|
||||
function Add-NetshFirewallRule {
|
||||
param (
|
||||
[HashTable] $hshRules,
|
||||
[String] $proto
|
||||
)
|
||||
|
||||
|
||||
foreach ($h in $hshRules.GetEnumerator()) {
|
||||
try {
|
||||
$command="advfirewall firewall add rule name=`"$($h.Name)`" dir=in action=allow protocol=$proto localport=$($h.Value)"
|
||||
Start-Process -FilePath netsh -ArgumentList $command -Wait
|
||||
}
|
||||
catch {
|
||||
$except= $_ | Out-String
|
||||
Write-LogError "Add rule $($h.Name) FAILS with $except"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function Remove-NetShFirewallRule {
|
||||
param (
|
||||
[HashTable] $hshRules
|
||||
)
|
||||
|
||||
foreach ($h in $hshRules.GetEnumerator()) {
|
||||
try {
|
||||
$command="advfirewall firewall delete rule name=`"$($h.Name)`""
|
||||
Start-Process -FilePath netsh -ArgumentList $command -Wait
|
||||
}
|
||||
catch {
|
||||
$except= $_ | Out-String
|
||||
Write-LogError "Delete rule $($h.Name) FAILS with $except"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function Enable-SQLExternalAccess {
|
||||
Add-NetshFirewallRule $FW_Rules $FW_Proto
|
||||
}
|
||||
|
||||
|
||||
function Disable-SQLExternalAccess {
|
||||
Remove-NetshFirewallRule $FW_Rules $FW_Proto
|
||||
}
|
||||
50
data5/templates/agent/scripts/CopyPrerequisites.ps1
Normal file
50
data5/templates/agent/scripts/CopyPrerequisites.ps1
Normal file
@@ -0,0 +1,50 @@
|
||||
|
||||
trap {
|
||||
&$TrapHandler
|
||||
}
|
||||
|
||||
|
||||
Function Copy-Prerequisites {
|
||||
param (
|
||||
[String] $Path = '',
|
||||
[String] $Destination = ''
|
||||
)
|
||||
begin {
|
||||
Show-InvocationInfo $MyInvocation
|
||||
}
|
||||
end {
|
||||
Show-InvocationInfo $MyInvocation -End
|
||||
}
|
||||
process {
|
||||
trap {
|
||||
&$TrapHandler
|
||||
}
|
||||
|
||||
Write-Log "--> Copy-Prerequisites"
|
||||
|
||||
if ($Destination -eq '') {
|
||||
throw("Copy-Prerequisites: Destination path not specified!")
|
||||
}
|
||||
|
||||
if ($Path -eq '') {
|
||||
$Path = [Environment]::GetEnvironmentVariable('MuranoFileShare')
|
||||
if ($Path -eq $null) {
|
||||
throw("Copy-Prerequisites: Unable to determine source path for prerequisites.")
|
||||
}
|
||||
}
|
||||
|
||||
Write-Log "Creating new PSDrive ..."
|
||||
New-PSDrive -Name 'P' -PSProvider 'FileSystem' -Root $Path | Out-Null
|
||||
|
||||
Write-Log "Creating destination folder ..."
|
||||
New-Item -Path $Destination -ItemType Container -Force | Out-Null
|
||||
|
||||
Write-Log "Copying items ..."
|
||||
Copy-Item -Path 'P:\Prerequisites\IIS' -Destination $Destination -Recurse -Force | Out-Null
|
||||
|
||||
Write-Log "Removing PSDrive ..."
|
||||
Remove-PSDrive -Name 'P' -PSProvider 'FileSystem' -Force | Out-Null
|
||||
|
||||
Write-Log "<-- Copy-Prerequisites"
|
||||
}
|
||||
}
|
||||
152
data5/templates/agent/scripts/DeployWebApp.ps1
Normal file
152
data5/templates/agent/scripts/DeployWebApp.ps1
Normal file
@@ -0,0 +1,152 @@
|
||||
|
||||
trap {
|
||||
&$TrapHandler
|
||||
}
|
||||
|
||||
|
||||
Function Register-WebApp {
|
||||
<#
|
||||
.LINKS
|
||||
|
||||
http://www.iis.net/learn/manage/powershell/powershell-snap-in-creating-web-sites-web-applications-virtual-directories-and-application-pools
|
||||
#>
|
||||
param (
|
||||
[String] $Source,
|
||||
[String] $Path = "C:\inetpub\wwwroot",
|
||||
[String] $Name = "",
|
||||
[String] $Username = "",
|
||||
[String] $Password = ""
|
||||
)
|
||||
begin {
|
||||
Show-InvocationInfo $MyInvocation
|
||||
}
|
||||
end {
|
||||
Show-InvocationInfo $MyInvocation -End
|
||||
}
|
||||
process {
|
||||
trap {
|
||||
&$TrapHandler
|
||||
}
|
||||
|
||||
Import-Module WebAdministration
|
||||
|
||||
if ($Name -eq "") {
|
||||
$Name = @([IO.Path]::GetDirectoryName($Source) -split '\\')[-1]
|
||||
if ($Name -eq "wwwroot") {
|
||||
throw("Application pool name couldn't be 'wwwroot'.")
|
||||
}
|
||||
}
|
||||
else {
|
||||
$Path = [IO.Path]::Combine($Path, $Name)
|
||||
}
|
||||
|
||||
$null = Copy-Item -Path $Source -Destination $Path -Recurse -Force
|
||||
|
||||
# Create new application pool
|
||||
$AppPool = New-WebAppPool -Name $Name -Force
|
||||
#$AppPool = Get-Item "IIS:\AppPools\$Name"
|
||||
$AppPool.managedRuntimeVersion = 'v4.0'
|
||||
$AppPool.managedPipelineMode = 'Classic'
|
||||
$AppPool.processModel.loadUserProfile = $true
|
||||
$AppPool.processModel.logonType = 'LogonBatch'
|
||||
|
||||
#Set Identity type
|
||||
if ($Username -eq "") {
|
||||
$AppPool.processModel.identityType = 'ApplicationPoolIdentity'
|
||||
}
|
||||
else {
|
||||
$AppPool.processModel.identityType = 'SpecificUser'
|
||||
$AppPool.processModel.userName = $Username
|
||||
$AppPool.processModel.password = $Password
|
||||
$null = $AppPool | Set-Item
|
||||
}
|
||||
|
||||
|
||||
# Create Website
|
||||
$WebSite = New-WebSite -Name $Name -Port 80 -HostHeader $Name -PhysicalPath $Path -Force
|
||||
#$WebSite = Get-Item "IIS:\Sites\$Name"
|
||||
|
||||
# Set the Application Pool
|
||||
$null = Set-ItemProperty "IIS:\Sites\$Name" 'ApplicationPool' $Name
|
||||
|
||||
#Turn on Directory Browsing
|
||||
#Set-WebConfigurationProperty -Filter '/system.webServer/directoryBrowse' -Name 'enabled' -Value $true -PSPath "IIS:\Sites\$Name"
|
||||
|
||||
# Update Authentication
|
||||
#Set-WebConfigurationProperty -Filter '/system.WebServer/security/authentication/AnonymousAuthentication' -Name 'enabled' -Value $true -Location $name
|
||||
#Set-WebConfigurationProperty -Filter '/system.WebServer/security/authentication/windowsAuthentication' -Name 'enabled' -Value $false -Location $Name
|
||||
#Set-WebConfigurationProperty -Filter '/system.WebServer/security/authentication/basicAuthentication' -Name 'enabled' -Value $false -Location $Name
|
||||
|
||||
$null = $WebSite.Start()
|
||||
|
||||
$null = Add-Content -Path "C:\Windows\System32\Drivers\etc\hosts" -Value "127.0.0.1 $Name"
|
||||
|
||||
# Remove standard IIS 'Hello World' application from localhost:80
|
||||
$null = Get-WebBinding 'Default Web Site' | Remove-WebBinding
|
||||
# Add new application on http://localhost:80
|
||||
$null = New-WebBinding -Name "$Name" -IP "*" -Port 80 -Protocol http
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Function Deploy-WebAppFromGit {
|
||||
param (
|
||||
[String] $URL,
|
||||
[String] $TempPath = [IO.Path]::Combine([IO.Path]::GetTempPath(), [IO.Path]::GetRandomFileName()),
|
||||
[String] $OutputPath = [IO.Path]::Combine([IO.Path]::GetTempPath(), [IO.Path]::GetRandomFileName())
|
||||
)
|
||||
begin {
|
||||
Show-InvocationInfo $MyInvocation
|
||||
}
|
||||
end {
|
||||
Show-InvocationInfo $MyInvocation -End
|
||||
}
|
||||
process {
|
||||
trap {
|
||||
&$TrapHandler
|
||||
}
|
||||
|
||||
Write-Log "TempPath = '$TempPath'"
|
||||
Write-Log "OutputPath = '$OutputPath'"
|
||||
|
||||
|
||||
# Fetch web application
|
||||
#----------------------
|
||||
Write-Log "Fetching sources from Git ..."
|
||||
|
||||
$null = New-Item -Path $TempPath -ItemType Container
|
||||
$null = Exec -FilePath 'git.exe' -ArgumentList @('clone', $URL) -WorkingDir $TempPath -RedirectStreams
|
||||
|
||||
$Path = @(Get-ChildItem $TempPath)[0].FullName
|
||||
#----------------------
|
||||
|
||||
|
||||
# Build web application
|
||||
#----------------------
|
||||
Write-Log "Building sources ..."
|
||||
|
||||
$msbuild = "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe"
|
||||
|
||||
$null = New-Item -Path $OutputPath -ItemType Container
|
||||
|
||||
$SlnFiles = @(Get-ChildItem -Path $Path -Filter *.sln -Recurse)
|
||||
|
||||
# Start new processs with additional env variables:
|
||||
#* VisualStudioVersion = "10.0"
|
||||
#* EnableNuGetPackageRestore = "true"
|
||||
$null = Exec -FilePath $msbuild `
|
||||
-ArgumentList @($SlnFiles[0].FullName, "/p:OutputPath=$OutputPath") `
|
||||
-Environment @{'VisualStudioVersion' = '10.0'; 'EnableNuGetPackageRestore' = 'true'} `
|
||||
-RedirectStreams
|
||||
|
||||
$AppFolder = @(Get-ChildItem ([IO.Path]::Combine($OutputPath, '_PublishedWebsites')))[0]
|
||||
#----------------------
|
||||
|
||||
|
||||
# Install web application
|
||||
#------------------------
|
||||
$null = Register-WebApp -Source $AppFolder.FullName -Name $AppFolder.Name
|
||||
#------------------------
|
||||
}
|
||||
}
|
||||
61
data5/templates/agent/scripts/Export-Function.ps1
Normal file
61
data5/templates/agent/scripts/Export-Function.ps1
Normal file
@@ -0,0 +1,61 @@
|
||||
|
||||
trap {
|
||||
&$TrapHandler
|
||||
}
|
||||
|
||||
function Export-Function {
|
||||
param (
|
||||
[String[]] $Name,
|
||||
|
||||
[Parameter(ValueFromPipeline=$true)]
|
||||
[String] $Path = [IO.Path]::GetTempFileName(),
|
||||
|
||||
[Switch] $All
|
||||
)
|
||||
|
||||
if ([IO.Path]::GetExtension($Path) -ne 'ps1') {
|
||||
$null = Rename-Item -Path $Path -NewName "$Path.ps1" -Force
|
||||
$Path = "$Path.ps1"
|
||||
}
|
||||
|
||||
$SystemFunctions = @(
|
||||
'A:', 'B:', 'C:', 'D:', 'E:', 'F:', 'G:', 'H:', 'I:', 'J:',
|
||||
'K:', 'L:', 'M:', 'N:', 'O:', 'P:', 'Q:', 'R:', 'S:', 'T:',
|
||||
'U:', 'V:', 'W:', 'X:', 'Y:', 'Z:',
|
||||
'cd..', 'cd\', 'help', 'mkdir', 'more', 'oss', 'prompt',
|
||||
'Clear-Host', 'Get-Verb', 'Pause', 'TabExpansion2'
|
||||
)
|
||||
|
||||
if ($All) {
|
||||
Get-ChildItem Function: |
|
||||
Where-Object {$_.ModuleName -eq ''} |
|
||||
Where-Object {$SystemFunctions -notcontains $_.Name} |
|
||||
ForEach-Object {
|
||||
Add-Content -Path $Path -Value @"
|
||||
|
||||
|
||||
function $($_.Name) {
|
||||
$($_.ScriptBlock)
|
||||
}
|
||||
|
||||
"@
|
||||
}
|
||||
}
|
||||
else {
|
||||
foreach ($FunctionName in $Name) {
|
||||
$FunctionObject = Get-ChildItem "Function:\$FunctionName"
|
||||
if ($FunctionObject -ne $null) {
|
||||
Add-Content -Path $Path -Value @"
|
||||
|
||||
|
||||
function $FunctionName {
|
||||
$($FunctionObject.ScriptBlock)
|
||||
}
|
||||
|
||||
"@
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $Path
|
||||
}
|
||||
239
data5/templates/agent/scripts/Failover-Cluster.ps1
Normal file
239
data5/templates/agent/scripts/Failover-Cluster.ps1
Normal file
@@ -0,0 +1,239 @@
|
||||
<#
|
||||
.DESCRIPTION
|
||||
|
||||
## Failover Cluster Input Data (from the UI)
|
||||
|
||||
* Domain Membership
|
||||
- [String] / [Select box] $DomainName - Domain name
|
||||
* Domain User Credentials
|
||||
- [String] $UserName - Username
|
||||
- [Password string] $UserPassword - User password
|
||||
* Shared Folder Information
|
||||
- [String] $ShareServer - Server which will host the folder
|
||||
- [String] $ShareName - Share name
|
||||
- [String] $SharePath - Shared folder internal path
|
||||
* Failover Cluster Members
|
||||
- [String] $ClusterName - Cluster name
|
||||
- [String] $ClusterIP - Static IP address that will be assigned to the cluster
|
||||
- [String[]] $ClusterNodes - List of node names
|
||||
|
||||
|
||||
|
||||
## Failover Cluster creation workflow
|
||||
|
||||
* Create AD domain
|
||||
* Join all the VMs to that domain
|
||||
* Prepare nodes
|
||||
- Install Failover Cluster prerequisites on all FC nodes
|
||||
* Create failover cluster
|
||||
- Create new cluster
|
||||
- Add members
|
||||
* Confugure FC quorum
|
||||
- Create new folder that will be shared
|
||||
- Share that folder with appropriate permissions
|
||||
- Configure quorum mode
|
||||
|
||||
|
||||
|
||||
## Helpful SmbShare* Functions
|
||||
|
||||
* New-SmbShare
|
||||
* Grant-SmbShareAccess
|
||||
|
||||
#>
|
||||
|
||||
trap {
|
||||
&$TrapHandler
|
||||
}
|
||||
|
||||
|
||||
|
||||
function Install-FailoverClusterPrerequisites {
|
||||
#Import-Module FailoverClusters
|
||||
|
||||
#Add-WindowsFeature Failover-Clustering, RSAT-Clustering-PowerShell
|
||||
}
|
||||
|
||||
|
||||
|
||||
function New-FailoverClusterSharedFolder {
|
||||
param (
|
||||
[String] $ClusterName,
|
||||
[String] $DomainName,
|
||||
[String] $ShareServer,
|
||||
[String] $SharePath = $($Env:SystemDrive + '\FCShare'),
|
||||
[String] $ShareName = 'FCShare',
|
||||
[String] $UserName,
|
||||
[String] $UserPassword,
|
||||
$Credential = $null
|
||||
)
|
||||
begin {
|
||||
Show-InvocationInfo $MyInvocation
|
||||
}
|
||||
end {
|
||||
Show-InvocationInfo $MyInvocation -End
|
||||
}
|
||||
process {
|
||||
trap {
|
||||
&$TrapHandler
|
||||
}
|
||||
|
||||
Write-Log "--> New-FailoverClusterSharedFolder"
|
||||
|
||||
Write-Log "Creating shared folder for Failover Cluster ..."
|
||||
|
||||
if ($Credential -eq $null) {
|
||||
$Credential = New-Credential -UserName "$DomainName\$UserName" -Password "$UserPassword"
|
||||
}
|
||||
|
||||
if ((Test-Connection -ComputerName $ShareServer -Count 1 -Quiet) -eq $false) {
|
||||
throw("Server '$ShareServer' is unreachable via ICMP.")
|
||||
}
|
||||
|
||||
$Session = New-PSSession -ComputerName $ShareServer -Credential $Credential
|
||||
|
||||
Write-Log "Creating folder on '$ShareServer' ..."
|
||||
Invoke-Command -Session $Session -ScriptBlock {
|
||||
param (
|
||||
[String] $SharePath,
|
||||
[String] $ShareName,
|
||||
[String] $ClusterAccount
|
||||
)
|
||||
|
||||
Remove-SmbShare -Name $ShareName -Force -ErrorAction 'SilentlyContinue'
|
||||
Remove-Item -Path $SharePath -Force -ErrorAction 'SilentlyContinue'
|
||||
|
||||
New-Item -Path $SharePath -ItemType Container -Force
|
||||
|
||||
New-SmbShare -Path $SharePath `
|
||||
-Name $ShareName `
|
||||
-FullAccess "$ClusterAccount", 'Everyone' `
|
||||
-Description "Shared folder for Failover Cluster."
|
||||
|
||||
} -ArgumentList $SharePath, $ShareName, "$DomainName\$ClusterName`$"
|
||||
|
||||
Write-Log "Confguring Failover Cluster to use shared folder as qourum resourse ..."
|
||||
|
||||
$null = Set-ClusterQuorum -NodeAndFileShareMajority "\\$ShareServer\$ShareName"
|
||||
|
||||
Write-Log "<-- New-FailoverClusterSharedFolder"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
function New-FailoverCluster {
|
||||
param (
|
||||
[String] $ClusterName,
|
||||
[String] $StaticAddress,
|
||||
[String[]] $ClusterNodes,
|
||||
[String] $DomainName,
|
||||
[String] $UserName,
|
||||
[String] $UserPassword,
|
||||
$Credential
|
||||
)
|
||||
begin {
|
||||
Show-InvocationInfo $MyInvocation
|
||||
}
|
||||
end {
|
||||
Show-InvocationInfo $MyInvocation -End
|
||||
}
|
||||
process {
|
||||
trap {
|
||||
&$TrapHandler
|
||||
}
|
||||
|
||||
Write-Log "ClusterNodes: $($ClusterNodes -join ', ')"
|
||||
|
||||
if ($Credential -eq $null) {
|
||||
$Credential = New-Credential -UserName "$DomainName\$UserName" -Password "$UserPassword"
|
||||
}
|
||||
|
||||
foreach ($Node in $ClusterNodes) {
|
||||
Write-LogDebug "Installing Failover Cluster modules on '$Node' ..."
|
||||
$null = Invoke-Command `
|
||||
-ComputerName $Node `
|
||||
-Credential $Credential `
|
||||
-ScriptBlock {
|
||||
Add-WindowsFeature Failover-Clustering, RSAT-Clustering-PowerShell
|
||||
}
|
||||
}
|
||||
|
||||
Import-Module FailoverClusters
|
||||
|
||||
if ((Get-Cluster $ClusterName -ErrorAction SilentlyContinue) -eq $null) {
|
||||
Write-Log "Creating new cluster '$ClusterName' ..."
|
||||
<#
|
||||
Start-PowerShellProcess -Command @"
|
||||
Import-Module FailoverClusters
|
||||
New-Cluster -Name '$ClusterName' -StaticAddress '$StaticAddress'
|
||||
"@ -Credential $Credential -NoBase64
|
||||
#>
|
||||
New-Cluster -Name "$ClusterName" -StaticAddress "$StaticAddress"
|
||||
Start-Sleep -Seconds 30
|
||||
}
|
||||
else {
|
||||
Write-Log "Cluster '$ClusterName' already exists."
|
||||
}
|
||||
|
||||
foreach ($Node in $ClusterNodes) {
|
||||
Write-Log "Adding node '$Node' to the cluster '$ClusterName' ..."
|
||||
if ((Get-ClusterNode $Node -ErrorAction SilentlyContinue) -eq $null) {
|
||||
Write-Log "Adding node ..."
|
||||
<#
|
||||
Start-PowerShellProcess -Command @"
|
||||
Import-Module FailoverClusters
|
||||
Add-ClusterNode -Cluster '$ClusterName' -Name '$Node'
|
||||
"@ -Credential $Credential -NoBase64
|
||||
#>
|
||||
Add-ClusterNode -Cluster "$ClusterName" -Name "$Node"
|
||||
}
|
||||
else {
|
||||
Write-Log "Node '$Node' already a part of the cluster '$ClusterName'."
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
<#
|
||||
|
||||
# Example
|
||||
|
||||
$DomainName = 'fc-acme.local'
|
||||
$DomainUser = 'Administrator'
|
||||
$DomainPassword = 'P@ssw0rd'
|
||||
|
||||
$ClusterName = 'fc-test'
|
||||
$ClusterIP = '10.200.0.60'
|
||||
$ClusterNodes = @('fc-node-01','fc-node-02','fc-node-03')
|
||||
|
||||
$ShareServer = 'fc-dc-01'
|
||||
$ShareName = 'FCShare'
|
||||
|
||||
$SharePath = "C:\$ShareName"
|
||||
|
||||
|
||||
|
||||
Import-Module CoreFunctions -Force
|
||||
|
||||
$Creds = New-Credential `
|
||||
-UserName "$DomainName\$DomainUser" `
|
||||
-Password "$DomainPassword"
|
||||
|
||||
New-FailoverCluster `
|
||||
-ClusterName $ClusterName `
|
||||
-StaticAddress $ClusterIP `
|
||||
-ClusterNodes $ClusterNodes `
|
||||
-Credential $Creds
|
||||
|
||||
New-FailoverClusterSharedFolder `
|
||||
-ClusterName $ClusterName `
|
||||
-DomainName $DomainName `
|
||||
-ShareServer $ShareServer `
|
||||
-SharePath "$SharePath" `
|
||||
-ShareName "$ShareName" `
|
||||
-Credential $Creds
|
||||
|
||||
#>
|
||||
@@ -0,0 +1,7 @@
|
||||
|
||||
function Get-DnsListeningIpAddress {
|
||||
Import-Module DnsServer
|
||||
|
||||
(Get-DNSServer -ComputerName localhost).ServerSetting.ListeningIpAddress |
|
||||
Where-Object { $_ -match "\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}" }
|
||||
}
|
||||
68
data5/templates/agent/scripts/ImportCoreFunctions.ps1
Normal file
68
data5/templates/agent/scripts/ImportCoreFunctions.ps1
Normal file
@@ -0,0 +1,68 @@
|
||||
|
||||
Import-Module CoreFunctions -Force
|
||||
Initialize-Logger 'MuranoAgent' 'C:\Murano\PowerShell.log'
|
||||
|
||||
|
||||
function Show-InvocationInfo {
|
||||
param (
|
||||
$Invocation,
|
||||
[Switch] $End
|
||||
)
|
||||
|
||||
if ($End) {
|
||||
Write-LogDebug "</function name='$($Invocation.MyCommand.Name)'>"
|
||||
}
|
||||
else {
|
||||
Write-LogDebug "<function name='$($Invocation.MyCommand.Name)'>"
|
||||
Write-LogDebug "<param>"
|
||||
foreach ($Parameter in $Invocation.MyCommand.Parameters) {
|
||||
foreach ($Key in $Parameter.Keys) {
|
||||
$Type = $Parameter[$Key].ParameterType.FullName
|
||||
foreach ($Value in $Invocation.BoundParameters[$Key]) {
|
||||
Write-LogDebug "[$Type] $Key = '$Value'"
|
||||
}
|
||||
}
|
||||
}
|
||||
Write-LogDebug "</param>"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$TrapHandler = {
|
||||
Write-LogError "<exception>"
|
||||
Write-LogError $_ -EntireObject
|
||||
Write-LogError "</exception>"
|
||||
break
|
||||
}
|
||||
|
||||
|
||||
trap {
|
||||
&$TrapHandler
|
||||
}
|
||||
|
||||
$ErrorActionPreference = 'Stop'
|
||||
|
||||
|
||||
<#
|
||||
# Usage example for Show-InvocationInfo
|
||||
|
||||
function MyFunction {
|
||||
param (
|
||||
[String] $Value1,
|
||||
[String] $Value2,
|
||||
[Int] $Int1
|
||||
)
|
||||
begin {
|
||||
Show-InvocationInfo $MyInvocation
|
||||
}
|
||||
end {
|
||||
Show-InvocationInfo $MyInvocation -End
|
||||
}
|
||||
process {
|
||||
trap {
|
||||
&$TrapHandler
|
||||
}
|
||||
# Main code here
|
||||
}
|
||||
}
|
||||
#>
|
||||
@@ -0,0 +1,43 @@
|
||||
|
||||
trap {
|
||||
&$TrapHandler
|
||||
}
|
||||
|
||||
|
||||
Function Install-RolePrimaryDomainController {
|
||||
param (
|
||||
[String] $DomainName,
|
||||
[String] $SafeModePassword
|
||||
)
|
||||
begin {
|
||||
Show-InvocationInfo $MyInvocation
|
||||
}
|
||||
end {
|
||||
Show-InvocationInfo $MyInvocation -End
|
||||
}
|
||||
process {
|
||||
trap {
|
||||
&$TrapHandler
|
||||
}
|
||||
|
||||
Add-WindowsFeatureWrapper `
|
||||
-Name "DNS","AD-Domain-Services","RSAT-DFS-Mgmt-Con" `
|
||||
-IncludeManagementTools `
|
||||
-NotifyRestart
|
||||
|
||||
Write-Log "Creating first domain controller ..."
|
||||
|
||||
$SMAP = ConvertTo-SecureString -String $SafeModePassword -AsPlainText -Force
|
||||
|
||||
$null = Install-ADDSForest `
|
||||
-DomainName $DomainName `
|
||||
-SafeModeAdministratorPassword $SMAP `
|
||||
-DomainMode Default `
|
||||
-ForestMode Default `
|
||||
-NoRebootOnCompletion `
|
||||
-Force
|
||||
|
||||
Write-Log "Waiting 60 seconds for reboot ..."
|
||||
Start-Sleep -Seconds 60
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
|
||||
trap {
|
||||
&$TrapHandler
|
||||
}
|
||||
|
||||
|
||||
Function Install-RoleSecondaryDomainController
|
||||
{
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Install additional (secondary) domain controller.
|
||||
|
||||
#>
|
||||
param
|
||||
(
|
||||
[String]
|
||||
# Domain name to join to.
|
||||
$DomainName,
|
||||
|
||||
[String]
|
||||
# Domain user who is allowed to join computer to domain.
|
||||
$UserName,
|
||||
|
||||
[String]
|
||||
# User's password.
|
||||
$Password,
|
||||
|
||||
[String]
|
||||
# Domain controller recovery mode password.
|
||||
$SafeModePassword
|
||||
)
|
||||
begin {
|
||||
Show-InvocationInfo $MyInvocation
|
||||
}
|
||||
end {
|
||||
Show-InvocationInfo $MyInvocation -End
|
||||
}
|
||||
process {
|
||||
trap {
|
||||
&$TrapHandler
|
||||
}
|
||||
|
||||
$Credential = New-Credential -UserName "$DomainName\$UserName" -Password $Password
|
||||
|
||||
# Add required windows features
|
||||
Add-WindowsFeatureWrapper `
|
||||
-Name "DNS","AD-Domain-Services","RSAT-DFS-Mgmt-Con" `
|
||||
-IncludeManagementTools `
|
||||
-NotifyRestart
|
||||
|
||||
|
||||
Write-Log "Adding secondary domain controller ..."
|
||||
|
||||
$SMAP = ConvertTo-SecureString -String $SafeModePassword -AsPlainText -Force
|
||||
|
||||
Install-ADDSDomainController `
|
||||
-DomainName $DomainName `
|
||||
-SafeModeAdministratorPassword $SMAP `
|
||||
-Credential $Credential `
|
||||
-NoRebootOnCompletion `
|
||||
-Force `
|
||||
-ErrorAction Stop | Out-Null
|
||||
|
||||
Write-Log "Waiting for restart ..."
|
||||
# Stop-Execution -ExitCode 3010 -ExitString "Computer must be restarted to finish domain controller promotion."
|
||||
# Write-Log "Restarting computer ..."
|
||||
# Restart-Computer -Force
|
||||
}
|
||||
}
|
||||
72
data5/templates/agent/scripts/InstallIIS.ps1
Normal file
72
data5/templates/agent/scripts/InstallIIS.ps1
Normal file
@@ -0,0 +1,72 @@
|
||||
|
||||
trap {
|
||||
&$TrapHandler
|
||||
}
|
||||
|
||||
|
||||
Function Install-WebServer {
|
||||
param (
|
||||
[String] $PrerequisitesPath
|
||||
)
|
||||
begin {
|
||||
Show-InvocationInfo $MyInvocation
|
||||
}
|
||||
end {
|
||||
Show-InvocationInfo $MyInvocation -End
|
||||
}
|
||||
process {
|
||||
trap {
|
||||
&$TrapHandler
|
||||
}
|
||||
|
||||
Write-Log "--> Install-WebServer"
|
||||
|
||||
$FeatureList = @(
|
||||
'Web-Server',
|
||||
'Web-Net-Ext45',
|
||||
'Web-ASP',
|
||||
'Web-Asp-Net45',
|
||||
'Web-ISAPI-Ext',
|
||||
'Web-ISAPI-Filter',
|
||||
'Web-Includes'
|
||||
)
|
||||
|
||||
$PrerequisitesList = @(
|
||||
'AspNetMvc4Setup.exe',
|
||||
'WebApplications.exe'
|
||||
)
|
||||
|
||||
$PrerequisitesPath = [IO.Path]::Combine($PrerequisitesPath, 'IIS')
|
||||
|
||||
Write-Log "Validating prerequisites based on the list ..."
|
||||
foreach ($FileName in $PrerequisitesList) {
|
||||
$FilePath = [IO.Path]::Combine($PrerequisitesPath, $FileName)
|
||||
if (-not (Test-Path -Path $FilePath -PathType Leaf)) {
|
||||
throw("Prerequisite file not found: '$FilePath'")
|
||||
}
|
||||
}
|
||||
|
||||
Import-Module ServerManager
|
||||
|
||||
Write-Log "Installing Web Server ..."
|
||||
Install-WindowsFeature $FeatureList -IncludeManagementTools
|
||||
|
||||
Write-Log "Installing AspNetMvp4 ..."
|
||||
$Exec = Exec -FilePath $([IO.Path]::Combine($PrerequisitesPath, 'AspNetMvc4Setup.exe')) -ArgumentList '/q' -PassThru
|
||||
if ($Exec.ExitCode -ne 0) {
|
||||
throw("Installation of 'AspNetMvc4Setup.exe' failed. Process exit code '$($Exec.ExitCode)'")
|
||||
}
|
||||
|
||||
# Extract WebApplications folder with *.target files to
|
||||
# C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0
|
||||
Write-Log "Installing WebApplication targets ..."
|
||||
$WebApplicationsTargetsRoot = 'C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0'
|
||||
$null = New-Item -Path $WebApplicationsTargetsRoot -ItemType Container
|
||||
$Exec = Exec -FilePath $([IO.Path]::Combine($PrerequisitesPath, 'WebApplications.exe')) -ArgumentList @("-o`"$WebApplicationsTargetsRoot`"", '-y') -PassThru
|
||||
if ($Exec.ExitCode -ne 0) {
|
||||
throw("Installation of 'WebApplications.exe' failed. Process exit code '$($Exec.ExitCode)'")
|
||||
}
|
||||
|
||||
Write-Log "<-- Install-WebServer"
|
||||
}
|
||||
}
|
||||
67
data5/templates/agent/scripts/Join-Domain.ps1
Normal file
67
data5/templates/agent/scripts/Join-Domain.ps1
Normal file
@@ -0,0 +1,67 @@
|
||||
|
||||
trap {
|
||||
&$TrapHandler
|
||||
}
|
||||
|
||||
|
||||
Function Join-Domain {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Executes "Join domain" action.
|
||||
|
||||
Requires 'CoreFunctions' module.
|
||||
#>
|
||||
param (
|
||||
[String] $DomainName = '',
|
||||
[String] $UserName = '',
|
||||
[String] $Password = '',
|
||||
[String] $OUPath = '',
|
||||
[Switch] $AllowRestart
|
||||
)
|
||||
begin {
|
||||
Show-InvocationInfo $MyInvocation
|
||||
}
|
||||
end {
|
||||
Show-InvocationInfo $MyInvocation -End
|
||||
}
|
||||
process {
|
||||
trap {
|
||||
&$TrapHandler
|
||||
}
|
||||
|
||||
if ($UserName -eq '') {
|
||||
$UserName = 'Administrator'
|
||||
}
|
||||
|
||||
$Credential = New-Credential -UserName "$DomainName\$UserName" -Password $Password
|
||||
|
||||
|
||||
if (Test-ComputerName -DomainName $DomainName -ErrorAction 'SilentlyContinue') {
|
||||
Write-LogWarning "Computer already joined to domain '$DomainName'"
|
||||
}
|
||||
else {
|
||||
Write-Log "Joining computer to domain '$DomainName' ..."
|
||||
|
||||
if ($OUPath -eq '') {
|
||||
Add-Computer -DomainName $DomainName -Credential $Credential -Force
|
||||
}
|
||||
else {
|
||||
Add-Computer -DomainName $DomainName -Credential $Credential -OUPath $OUPath -Force
|
||||
}
|
||||
|
||||
$null = Exec 'ipconfig' @('/registerdns') -RedirectStreams
|
||||
|
||||
Write-Log "Waiting 30 seconds to restart ..."
|
||||
Start-Sleep -Seconds 30
|
||||
<#
|
||||
if ($AllowRestart) {
|
||||
Write-Log "Restarting computer ..."
|
||||
Restart-Computer -Force
|
||||
}
|
||||
else {
|
||||
Write-Log "Please restart the computer now."
|
||||
}
|
||||
#>
|
||||
}
|
||||
}
|
||||
}
|
||||
204
data5/templates/agent/scripts/Linux/common.sh
Normal file
204
data5/templates/agent/scripts/Linux/common.sh
Normal file
@@ -0,0 +1,204 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
DEBUGLVL=3
|
||||
LOGFILE=/tmp/muranodeployment.log
|
||||
PIPAPPS="pip python-pip pip-python"
|
||||
PIPCMD=""
|
||||
if [ "$DEBUGLVL" -eq 4 ]; then
|
||||
set -x
|
||||
fi
|
||||
function log {
|
||||
if [ "$DEBUGLVL" -gt 0 ]; then
|
||||
chars=$(echo "@$" | wc -c)
|
||||
case $DEBUGLVL in
|
||||
1 )
|
||||
echo -e "LOG:>$@"
|
||||
;;
|
||||
2)
|
||||
echo -e "$(date +"%m-%d-%Y %H:%M") LOG:>$@" | tee --append $LOGFILE
|
||||
;;
|
||||
3)
|
||||
echo -e "$(date +"%m-%d-%Y %H:%M") LOG:>$@" >> $LOGFILE
|
||||
;;
|
||||
4)
|
||||
echo -e "$(date +"%m-%d-%Y %H:%M") LOG:>$@" | tee --append $LOGFILE
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
}
|
||||
function lowercase(){
|
||||
echo "$1" | sed "y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/"
|
||||
}
|
||||
function find_pip()
|
||||
{
|
||||
for cmd in $PIPAPPS
|
||||
do
|
||||
_cmd=$(which $cmd 2>/dev/null)
|
||||
if [ $? -eq 0 ];then
|
||||
break
|
||||
fi
|
||||
done
|
||||
if [ -z $_cmd ];then
|
||||
echo "Can't find \"pip\" in system, please install it first, exiting!"
|
||||
exit 1
|
||||
else
|
||||
PIPCMD=$_cmd
|
||||
fi
|
||||
}
|
||||
OPTIND=1 # Reset if getopts used previously
|
||||
function collect_args(){
|
||||
_n=$1
|
||||
shift
|
||||
ARGS=''
|
||||
while true
|
||||
do
|
||||
if [[ "$_n" == -* ]] || [ -z "$_n" ]; then
|
||||
OPTIND=$((OPTIND - 1))
|
||||
break
|
||||
fi
|
||||
#echo "_n=$_n ; $OPTIND"
|
||||
if [ -z "$ARGS" ]; then
|
||||
ARGS=$OPTARG
|
||||
else
|
||||
ARGS="$ARGS $_n"
|
||||
fi
|
||||
eval _n=\$$OPTIND
|
||||
OPTIND=$((OPTIND + 1))
|
||||
#sleep 1
|
||||
done
|
||||
echo $ARGS
|
||||
unset _n
|
||||
unset ARGS
|
||||
}
|
||||
function get_os(){
|
||||
KERNEL=$(uname -r)
|
||||
MACH=$(uname -m)
|
||||
OS=$(uname)
|
||||
if [ "${OS}" = "Linux" ] ; then
|
||||
if [ -f /etc/redhat-release ] ; then
|
||||
DistroBasedOn='RedHat'
|
||||
Packager='yum'
|
||||
DIST=$(cat /etc/redhat-release |sed s/\ release.*//)
|
||||
PSUEDONAME=$(cat /etc/redhat-release | sed s/.*\(// | sed s/\)//)
|
||||
REV=$(cat /etc/redhat-release | sed s/.*release\ // | sed s/\ .*//)
|
||||
elif [ -f /etc/SuSE-release ] ; then
|
||||
DistroBasedOn='SuSe'
|
||||
Packager='zypper'
|
||||
PSUEDONAME=$(cat /etc/SuSE-release | tr "\n" ' '| sed s/VERSION.*//)
|
||||
REV=$(cat /etc/SuSE-release | tr "\n" ' ' | sed s/.*=\ //)
|
||||
elif [ -f /etc/mandrake-release ] ; then
|
||||
DistroBasedOn='Mandrake'
|
||||
Packager='urpmi urpme'
|
||||
PSUEDONAME=$(cat /etc/mandrake-release | sed s/.*\(// | sed s/\)//)
|
||||
REV=$(cat /etc/mandrake-release | sed s/.*release\ // | sed s/\ .*//)
|
||||
elif [ -f /etc/debian_version ] ; then
|
||||
DistroBasedOn='Debian'
|
||||
Packager='apt-get'
|
||||
DIST=$(cat /etc/lsb-release | grep '^DISTRIB_ID' | awk -F= '{ print $2 }')
|
||||
PSUEDONAME=$(cat /etc/lsb-release | grep '^DISTRIB_CODENAME' | awk -F= '{ print $2 }')
|
||||
REV=$(cat /etc/lsb-release | grep '^DISTRIB_RELEASE' | awk -F= '{ print $2 }')
|
||||
fi
|
||||
if [ -f /etc/UnitedLinux-release ] ; then
|
||||
DIST="${DIST}[$(cat /etc/UnitedLinux-release | tr "\n" ' ' | sed s/VERSION.*//)]"
|
||||
fi
|
||||
OS=$(lowercase $OS)
|
||||
DistroBasedOn=$(lowercase $DistroBasedOn)
|
||||
readonly OS
|
||||
readonly DIST
|
||||
readonly DistroBasedOn
|
||||
readonly PSUEDONAME
|
||||
readonly REV
|
||||
readonly KERNEL
|
||||
readonly MACH
|
||||
#readonly Packager
|
||||
else
|
||||
OS=unknown
|
||||
readonly OS
|
||||
log "OS:$OS"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
function add_fw_rule(){
|
||||
_rule_string=$@
|
||||
_tmp_fw_port=$(echo $_rule_string | grep -o -e "dport [0-9]*\s")
|
||||
_tmp_fw_proto=$(echo $_rule_string | grep -o -e "-p \w*\s")
|
||||
_fw_port=$(echo $_tmp_fw_port | awk '{print $2}')
|
||||
_fw_proto=$(echo $_tmp_fw_proto |awk '{print $2}')
|
||||
_fw_reload=""
|
||||
#find iptables and add rule
|
||||
case $DIST in
|
||||
"Fedora")
|
||||
_fw_cmd=$(which firewall-cmd)
|
||||
_fw_port=$(echo $_rule_string | grep -o -e "dport [0-9]*\s" | awk '{print $2}')
|
||||
_fw_proto=$(echo $_rule_string | grep -o -e "-p \w*\s" | awk '{print $2}')
|
||||
_fw_rule="--permanent --add-port=$_fw_port/$_fw_proto"
|
||||
_fw_enable_rules="$_fw_cmd --reload"
|
||||
;;
|
||||
*)
|
||||
_fw_cmd=$(which iptables)
|
||||
_fw_rule=$_rule_string
|
||||
_fw_enable_rules="service $_fw_cmd save"
|
||||
;;
|
||||
esac
|
||||
iptcmdsave=$(which iptables-save)
|
||||
if [[ "$_fw_cmd" != '' ]] && [[ "$iptcmdsave" != '' ]]; then
|
||||
eval "$iptcmdsave | grep -e \"$_tmp_fw_port\" | grep -e \"$_tmp_fw_proto\"" > /dev/null 2>&1
|
||||
if [ $? -ne 0 ]; then
|
||||
eval $_fw_cmd $_fw_rule
|
||||
if [ $? -ne 0 ]; then
|
||||
log "Can't set firewall rules, exiting..."
|
||||
exit 1
|
||||
else
|
||||
if [ -n "$_fw_enable_rules" ]; then
|
||||
log "Running \"$_fw_enable_rules\""
|
||||
$_fw_enable_rules > /dev/null
|
||||
fi
|
||||
log "$_fw_cmd rule with $_fw_rule set."
|
||||
fi
|
||||
else
|
||||
log "$_fw_cmd rule exists."
|
||||
fi
|
||||
else
|
||||
log "There are no fw found..."
|
||||
fi
|
||||
}
|
||||
function enable_init(){
|
||||
_initctrl=""
|
||||
_init_suffix=""
|
||||
_service=$1
|
||||
case $DistroBasedOn in
|
||||
"debian")
|
||||
_initctrl="update-rc.d"
|
||||
_init_suffix="defaults"
|
||||
;;
|
||||
*)
|
||||
_initctrl="chkconfig"
|
||||
_init_suffix="on"
|
||||
;;
|
||||
esac
|
||||
$_initctrl $_service $_init_suffix
|
||||
if [ $? -ne 0 ]; then
|
||||
log "$_initctrl $_service $_init_suffix - fails!"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
function restart_service(){
|
||||
_service=$1
|
||||
service $_service restart > /dev/null 2>&1
|
||||
if [ $? -ne 0 ]; then
|
||||
log "Can't start $_service service!"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
function package_renamer(){
|
||||
_pkg=$1
|
||||
case $DistroBasedOn in
|
||||
"debian")
|
||||
_pkg=$(echo $_pkg | sed 's/-devel$/-dev/')
|
||||
;;
|
||||
*)
|
||||
_pkg=$(echo $_pkg | sed 's/-dev$/-devel/')
|
||||
;;
|
||||
esac
|
||||
echo $_pkg
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user