Simplify Vault start on Windows
Some checks failed
Some checks failed
This commit is contained in:
@@ -1,92 +1,31 @@
|
||||
# Create directories
|
||||
New-Item -ItemType Directory -Path ".\vault-data" -Force -ErrorAction SilentlyContinue
|
||||
New-Item -ItemType Directory -Path ".\vault-logs" -Force -ErrorAction SilentlyContinue
|
||||
|
||||
# Start Vault server
|
||||
$vaultArgs = @(
|
||||
"server",
|
||||
"-dev",
|
||||
"-dev-tls",
|
||||
"-dev-root-token-id=root",
|
||||
"-dev-listen-address=127.0.0.1:8200",
|
||||
"-log-level=debug",
|
||||
"-log-file=.\vault-logs\vault.log"
|
||||
)
|
||||
|
||||
Write-Output "✅ Starting Vault server..."
|
||||
$vaultJob = Start-Job -Name "VaultServer" -ScriptBlock {
|
||||
param($Args)
|
||||
& ".\vault.exe" $Args
|
||||
} -ArgumentList $vaultArgs
|
||||
Write-Host "Starting Vault dev server..."
|
||||
$vaultProc = Start-Process vault `
|
||||
-ArgumentList "server -dev -dev-tls" `
|
||||
-RedirectStandardOutput "vault.out.log" `
|
||||
-RedirectStandardError "vault.err.log" `
|
||||
-WindowStyle Hidden `
|
||||
-PassThru
|
||||
$vaultPid = $vaultProc.Id
|
||||
Write-Host "Vault started with PID $vaultPid"
|
||||
Set-Content -Path vault.pid -Value $vaultPid
|
||||
|
||||
# Wait a moment for the job to start
|
||||
Start-Sleep -Seconds 2
|
||||
|
||||
# Get the actual process ID from the job
|
||||
$vaultProcess = Get-Process -Name "vault" -ErrorAction SilentlyContinue | Select-Object -First 1
|
||||
if ($vaultProcess) {
|
||||
$vaultProcess.Id | Out-File -FilePath "vault-pid.txt"
|
||||
Write-Output "✅ Vault process started with PID: $($vaultProcess.Id)"
|
||||
} else {
|
||||
Write-Output "❌ Could not find Vault process"
|
||||
|
||||
# Show logs
|
||||
Write-Output "=== LOG (last 20 lines) ==="
|
||||
Get-Content ".\vault-logs\vault.log" -ErrorAction SilentlyContinue | Select-Object -Last 20
|
||||
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Wait for Vault to become ready using port check
|
||||
$timeout = 30
|
||||
$counter = 0
|
||||
$isReady = $false
|
||||
$vaultPort = 8200
|
||||
|
||||
Write-Output "🕐 Waiting for Vault to start on port $vaultPort..."
|
||||
while ($counter -lt $timeout) {
|
||||
# Check if process is still running
|
||||
if (-not (Get-Process -Id $vaultPid -ErrorAction SilentlyContinue)) {
|
||||
Write-Output "❌ Vault process died unexpectedly!"
|
||||
break
|
||||
}
|
||||
|
||||
# Check if port is listening
|
||||
# Wait until Vault is ready
|
||||
$maxRetries = 15
|
||||
$ok = $false
|
||||
for ($i=0; $i -lt $maxRetries; $i++) {
|
||||
try {
|
||||
$tcpClient = New-Object System.Net.Sockets.TcpClient
|
||||
$asyncResult = $tcpClient.BeginConnect("127.0.0.1", $vaultPort, $null, $null)
|
||||
$wait = $asyncResult.AsyncWaitHandle.WaitOne(1000, $false)
|
||||
if ($wait) {
|
||||
$tcpClient.EndConnect($asyncResult)
|
||||
$tcpClient.Close()
|
||||
$isReady = $true
|
||||
Write-Output "✅ Vault server is listening on port $vaultPort!"
|
||||
break
|
||||
}
|
||||
$tcpClient.Close()
|
||||
Invoke-RestMethod -UseBasicParsing -SkipCertificateCheck https://127.0.0.1:8200/v1/sys/health | Out-Null
|
||||
$ok = $true
|
||||
break
|
||||
} catch {
|
||||
# Port not ready yet
|
||||
Start-Sleep -Seconds 2
|
||||
}
|
||||
|
||||
Write-Output "🕐 Waiting for Vault to start... ($counter/$timeout)"
|
||||
Start-Sleep -Seconds 1
|
||||
$counter++
|
||||
}
|
||||
|
||||
if (-not $isReady) {
|
||||
Write-Output "❌ Vault server failed to start within $timeout seconds"
|
||||
|
||||
# Show process status
|
||||
Write-Output "=== PROCESS STATUS ==="
|
||||
Get-Process -Id $vaultPid -ErrorAction SilentlyContinue | Format-List *
|
||||
|
||||
# Show logs
|
||||
Write-Output "=== LOG (last 20 lines) ==="
|
||||
Get-Content ".\vault-logs\vault.log" -ErrorAction SilentlyContinue | Select-Object -Last 20
|
||||
|
||||
# Cleanup
|
||||
Stop-Process -Id $vaultPid -Force -ErrorAction SilentlyContinue
|
||||
exit 1
|
||||
if (-not $ok) {
|
||||
Write-Error "Vault did not become ready in time"
|
||||
Exit 1
|
||||
}
|
||||
|
||||
Write-Output "✅ Vault server started successfully!"
|
||||
Write-Host "Vault is up and running."
|
Reference in New Issue
Block a user