#Requires -Version 5.1 <# .SYNOPSIS Start, stop, restart DupFinder, or open it in the browser. .PARAMETER Action start | stop | restart | open (default: open) .EXAMPLE .\dupfinder-start-stop.ps1 -Action open .\dupfinder-start-stop.ps1 -Action stop #> param( [ValidateSet("start","stop","restart","open")] [string]$Action = "open" ) $ConfigFile = "C:\ProgramData\DupFinder\dupfinder.conf" if (-not (Test-Path $ConfigFile)) { Write-Error "DupFinder is not installed. Run install.ps1 first." exit 1 } # Read config $conf = @{} Get-Content $ConfigFile | ForEach-Object { if ($_ -match '^(.+?)=(.+)$') { $conf[$Matches[1]] = $Matches[2] } } $ComposeDir = $conf["COMPOSE_DIR"] $AppPort = $conf["APP_PORT"] $ComposeYml = "$ComposeDir\docker-compose.yml" $OverrideYml = "$ComposeDir\docker-compose.override.yml" $Url = "http://localhost:$AppPort" function Invoke-Compose([string]$cmd) { & docker compose -f $ComposeYml -f $OverrideYml $cmd.Split(" ") } switch ($Action) { "start" { Write-Host "Starting DupFinder..." Invoke-Compose "up -d --pull never" } "stop" { Write-Host "Stopping DupFinder..." Invoke-Compose "stop" } "restart" { Write-Host "Restarting DupFinder..." Invoke-Compose "restart" } "open" { # Ensure container is running $running = docker ps --filter "name=dup-finder" --format "{{.Names}}" 2>$null if (-not $running) { Write-Host "Starting DupFinder..." Invoke-Compose "up -d --pull never" } # Poll until responsive (up to 15s) $tries = 0 while ($tries -lt 15) { try { $r = Invoke-WebRequest -Uri $Url -UseBasicParsing -TimeoutSec 1 -ErrorAction Stop break } catch { } Start-Sleep 1 $tries++ } Start-Process $Url } }