Created
March 29, 2016 14:53
-
-
Save DamianStanger/ea12bc8b156f143d3941 to your computer and use it in GitHub Desktop.
Powershell that can create multiple go agents running on a single machine all pointing at different gocd servers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#https://docs.go.cd/current/installation/install/agent/windows.html | |
$goSetupExe = "go-agent-16.2.1-3027-setup.exe" | |
cd / | |
New-Item C:\go -ItemType Directory -ErrorAction SilentlyContinue | |
cd c:\go | |
if(Test-Path "c:\go\$goSetupExe"){ | |
write-host -ForegroundColor green "c:\go\$goSetupExe exists" | |
} | |
else{ | |
Write-Host "downloading https://download.go.cd/binaries/16.2.1-3027/win/$goSetupExe" | |
$client = new-object System.Net.WebClient | |
$client.DownloadFile("https://download.go.cd/binaries/16.2.1-3027/win/$goSetupExe", "C:\go\$goSetupExe") | |
Write-Host "downloaded" | |
} | |
copy-Item "c:\go\$goSetupExe" "c:\go\go-agent-setup.exe" -ErrorAction Continue | |
if(get-service "go agent" -ErrorAction SilentlyContinue){ | |
Write-Host -ForegroundColor green "Default goagent already Installed at C:\go\agent1" | |
} | |
else{ | |
Write-Host "Installing defaultAgent at C:\go\agent1" | |
.\go-agent-setup.exe /S /SERVERIP=go-serviceboundary1.mydomain.com /D=C:\go\agent1 | |
Write-Host "Agent install started at C:\go\agent1" | |
Write-Host "Rerun this script once the agent is installed and running." -ForegroundColor Red | |
exit | |
} | |
stop-service "go agent" | |
#https://docs.go.cd/current/advanced_usage/admin_install_multiple_agents.html | |
(Get-Content C:\go\agent1\config\wrapper-agent.conf).replace('%GO_SERVER%', 'go-serviceboundary1.mydomain.com') | Set-Content C:\go\agent1\config\wrapper-agent.conf | |
(Get-Content C:\go\agent1\config\wrapper-agent.conf).replace('%GO_AGENT_DIR%', 'c:\go\agent1') | Set-Content C:\go\agent1\config\wrapper-agent.conf | |
function createAgent($agentNumber, $boundedContext){ | |
Write-Host "Creating Agent$agentNumber for go-$boundedContext.mydomain.com" | |
if(Test-Path "c:\go\agent$agentNumber"){ | |
write-host -ForegroundColor green "c:\go\agent$agentNumber Exists" | |
} | |
else{ | |
Write-Host "Creating directory and re-writing config at C:\go\agent$agentNumber" | |
new-item "C:\go\agent$agentNumber" -ItemType Directory | |
Copy-Item "C:\go\agent1\*" -Destination "C:\go\agent$agentNumber" -Recurse | |
Remove-Item "C:\go\agent$agentNumber\config\guid.txt" | |
Remove-Item "C:\go\agent$agentNumber\*.log" | |
(Get-Content "C:\go\agent$agentNumber\config\wrapper-agent.conf").replace('go-serviceboundary1.mydomain.com', "go-$boundedContext.mydomain.com") | Set-Content "C:\go\agent$agentNumber\config\wrapper-agent.conf" | |
(Get-Content "C:\go\agent$agentNumber\config\wrapper-agent.conf").replace('c:\go\agent1', "c:\go\agent$agentNumber") | Set-Content "C:\go\agent$agentNumber\config\wrapper-agent.conf" | |
} | |
if(get-service "Go Agent$agentNumber" -ErrorAction SilentlyContinue){ | |
write-host -ForegroundColor green "service 'Go Agent$agentNumber' Exists" | |
} | |
else{ | |
Write-Host "Creating service 'Go Agent$agentNumber'" | |
New-Service -Name "Go Agent$agentNumber" -DisplayName "Go Agent$agentNumber (go-$boundedContext.mydomain.com)" -Description "Go Agent$agentNumber (go-$boundedContext.mydomain.com)" -StartupType Automatic -BinaryPathName "`"C:\go\agent$agentNumber\cruisewrapper.exe`" -s `"c:\go\agent$agentNumber\config\wrapper-agent.conf`"" | |
#(Get-WmiObject Win32_Service -filter "name='Go Agent4'").delete() | |
} | |
} | |
createAgent 4 "serviceboundary2" | |
createAgent 5 "serviceboundary3" | |
createAgent 6 "serviceboundary4" | |
Start-Service "Go Agent" | |
Start-Service "Go Agent2" | |
Start-Service "Go Agent3" | |
Start-Service "Go Agent4" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment