Skip to content

Commit 9315a0b

Browse files
Added scripts for Mongo
1 parent 7d8b2aa commit 9315a0b

2 files changed

Lines changed: 89 additions & 1 deletion

File tree

scripts/AzurePlatformSetup/SmallEnvironment/Create-SmallEnvironment.ps1

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,5 +110,12 @@ $diskConfig = New-AzDiskConfig -Location $region -CreateOption Empty -DiskSizeGB
110110
$newDataDisk = New-AzDisk -ResourceGroupName $resourceGroupName -DiskName $dataDiskName -Disk $diskConfig
111111
Add-AzVMDataDisk -VM $vm -Name $dataDiskName -CreateOption Attach -ManagedDiskId $newDataDisk.Id -Lun 1
112112
Update-AzVM -VM $vm -ResourceGroupName $vm.ResourceGroupName
113-
Invoke-AzVMRunCommand -VM $vm -CommandId 'RunPowerShellScript' -ScriptString "Get-disk | where-Object Number -eq '1' | Initialize-Disk -PartitionStyle GPT -PassThru | New-Partition -UseMaximumSize -DriveLetter E | Format-Volume -FileSystem NTFX -NewFileSystemLabel 'QuantumDMS-Data'"
113+
Invoke-AzVMRunCommand -VM $vm -CommandId 'RunPowerShellScript' -ScriptString "Get-disk | where-Object Number -eq '1' | Initialize-Disk -PartitionStyle GPT -PassThru | New-Partition -UseMaximumSize -DriveLetter E | Format-Volume -FileSystem NTFS -NewFileSystemLabel 'QuantumDMS-Data'"
114114

115+
$command1 = "iwr -Uri `"https://raw.githubusercontent.com/OneBitSoftware/DevOps/refs/heads/main/scripts/Base/Install-PowerShellCore.ps1`" -OutFile `"E:\Install\Install-PowerShellCore.ps1`""
116+
$command2 = "powershell `"E:\Install\Install-PowerShellCore.ps1`" -ScriptDownloadFolder `"E:\Install`" -PowerShellCoreVersion 7.4.5"
117+
$psCommand = "mkdir E:\Install;e:;cd e:\install;powershell -c '$command1';$command2;"
118+
$commandResult = Invoke-AzVMRunCommand -VM $vm -CommandId 'RunPowerShellScript' -ScriptString $psCommand
119+
120+
$ps7Command1 = "C:\Program Files\PowerShell\7\pwsh.exe"
121+
$ps7CommandResult = Invoke-AzVMRunCommand -VM $vm -CommandId 'RunPowerShellScript' -ScriptString $ps7Command1
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
2+
3+
# MongoDB variables - Download the Community edition
4+
$MongoDbPath = "E:\MongoDB"
5+
6+
$MongoMajorVersion = "7.0" # Used in path
7+
$MongoMinorVersion = "14"
8+
$MongoDbVersion = "$MongoMajorVersion.$MongoMinorVersion"
9+
$UnzippedFolderName = "mongodb-win32-x86_64-windows-$MongoDbVersion"
10+
$MongoMsiFilename = "mongodb-windows-x86_64-$MongoDbVersion-signed.msi"
11+
$MongoDownloadURL = "https://fastdl.mongodb.org/windows/$MongoMsiFilename"
12+
$MongoDbConnectionString = "mongodb://localhost:27017/${CatalogDatabaseName}"
13+
$MongoShellFilename = "mongosh-2.3.2-x64.msi"
14+
$MongoShellDownloadURL = "https://downloads.mongodb.com/compass/$MongoShellFilename"
15+
16+
17+
############################################################ MongoDB Start
18+
#Check if mongo is already installed
19+
if ((Test-Path -path $MongoDbPath) -eq $True)
20+
{
21+
write-host "MongoDB is already installed. Terminating."
22+
Exit 1;
23+
}
24+
25+
#Create mongo system directories
26+
mkdir $MongoDbPath
27+
28+
#Download MongoDB Server installation file
29+
$mongoDbMsiFile = "$MongoDbPath\$MongoMsiFilename"
30+
Write-Host "Downloading $MongoDownloadURL"
31+
Invoke-WebRequest -Uri $MongoDownloadURL -Method Get -OutFile $mongoDbMsiFile
32+
Write-Host "Downloading mongo complete."
33+
34+
#Download MongoDB Shell installation file
35+
$mongoDbShellMsiFile = "$MongoDbPath\$MongoShellFilename"
36+
Write-Host "Downloading $MongoShellDownloadURL"
37+
Invoke-WebRequest -Uri $MongoShellDownloadURL -Method Get -OutFile $mongoDbShellMsiFile
38+
Write-Host "Downloading mongo complete."
39+
40+
41+
######## New - Use the MSI to install MongoDB Server
42+
msiexec.exe /l*v mdbinstall.log /qb /i $mongoDbMsiFile INSTALLLOCATION="$MongoDbPath\Server\5.0\" ADDLOCAL="ServerService"
43+
44+
# Loop and wait for the service to start
45+
$limit = (Get-Date).AddMinutes(5)
46+
while ($null -eq (Get-Service mongodb) -and (Get-Date) -le $limit) {
47+
Write-Host "Waiting 5 seconds for the mongodb service to start..."
48+
Start-Sleep -Seconds 5
49+
}
50+
if ((Get-Service mongodb).Status -ne "Running") {
51+
Write-Host "MongoDB is not running as a service. Terminating." -ForegroundColor Red
52+
Exit 1;
53+
}
54+
55+
# New - Use the MSI to install MongoDB Shell
56+
msiexec.exe /l*v mdbshellinstall.log /quiet /i $mongoDbShellMsiFile INSTALLFOLDER="$MongoDbPath\Tools\" MSIINSTALLPERUSER=0
57+
58+
Remove-Item $mongoDbMsiFile -recurse -force
59+
Remove-Item $mongoDbShellMsiFile -recurse -force
60+
61+
# Update mongo config with replica set settings
62+
$mongoDbInstallLocation = "$MongoDbPath\Server\$MongoMajorVersion"
63+
$mongoDbBinLocation = "$mongoDbInstallLocation\bin\"
64+
$mongoDbConfigPath = "$mongoDbBinLocation\mongod.cfg"
65+
66+
#Prepare config data
67+
$MongoConfigContent = @"
68+
# Quantum DMS additions to this flie
69+
replication:
70+
replSetName: rs0
71+
"@
72+
73+
Add-Content -Path $mongoDbConfigPath -Value $MongoConfigContent
74+
Write-Host "Saved $mongoDbConfigPath"
75+
76+
Get-Service mongodb | Restart-Service
77+
78+
#Initiate replica set
79+
$mongoExe = "$MongoDbPath\Tools\" + "mongosh.exe"
80+
& $mongoExe --quiet --port 27017 --eval "rs.initiate()"
81+
############################################################ MongoDB END

0 commit comments

Comments
 (0)