Skip to content

Instantly share code, notes, and snippets.

@srazzaque
Last active December 22, 2015 14:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save srazzaque/6488371 to your computer and use it in GitHub Desktop.
Save srazzaque/6488371 to your computer and use it in GitHub Desktop.
Replica set starter for Windows 7 (PowerShell)
# Mongo replica set starter for use in Windows 7 (Powershell 3.x)
Write-Host "Mongo Replica Set Starter"
Write-Host "WARNING: Will delete rs1/2/3 directories and 1/2/3.log files in the current directory."
$replSet = "m101"
$curDir = (Get-Location).Path + "\"
function Start-MongoRS ($logPath, $dataDir, $portNo) {
$lp = $curDir + $logPath
$dd = $curDir + $dataDir
Write-Host "Starting up mongo replica on $portNo (and clearing logfile beforehand)"
if (Test-Path $lp) {
Remove-Item $lp
}
$x = Start-Job { mongod --replSet $using:replSet --logpath $using:lp --dbpath $using:dd --port $using:portNo --smallfiles }
}
function Create-MongoDataDir ($dirName) {
$dir = $curDir + $dirName
if (Test-Path $dir) {
$x = rmdir -Force -Recurse $dir
}
$x = mkdir $dir
}
@("rs1", "rs2", "rs3") | % { Create-MongoDataDir $_ }
Start-MongoRS "1.log" "rs1" 27017
Start-MongoRS "2.log" "rs2" 27018
Start-MongoRS "3.log" "rs3" 27019
Write-Host "All started - use Get-Process to find 'mongod' instances running, you should see 3."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment