This repository has been archived on 2026-01-03. You can view files and clone it, but cannot push or open issues or pull requests.
Files
lions-user-manager/scripts/kill-java-processes.ps1

156 lines
5.6 KiB
PowerShell
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env pwsh
<#
.SYNOPSIS
Script pour tuer les processus Java liés au projet Lions User Manager
.DESCRIPTION
Ce script identifie et tue tous les processus Java qui pourraient verrouiller
les fichiers du projet, permettant ainsi d'exécuter mvn clean sans erreur.
.PARAMETER Force
Force l'arrêt des processus sans confirmation
.EXAMPLE
.\kill-java-processes.ps1
.EXAMPLE
.\kill-java-processes.ps1 -Force
#>
param(
[Parameter(Mandatory=$false)]
[switch]$Force
)
$ErrorActionPreference = "Stop"
# Couleurs
function Write-Success { Write-Host "$args" -ForegroundColor Green }
function Write-Info { Write-Host " $args" -ForegroundColor Cyan }
function Write-Warning { Write-Host "⚠️ $args" -ForegroundColor Yellow }
function Write-Error { Write-Host "$args" -ForegroundColor Red }
function Write-Step { Write-Host "`n🚀 $args" -ForegroundColor Magenta }
Write-Host @"
🔪 ARRÊT DES PROCESSUS JAVA - LIONS USER MANAGER 🔪
"@ -ForegroundColor Cyan
# 1. Lister tous les processus Java
Write-Step "1. Recherche des processus Java..."
$javaProcesses = Get-Process | Where-Object {
$_.ProcessName -like "*java*" -or $_.ProcessName -like "*javaw*"
} | Where-Object {
# Exclure les processus Cursor/IDE
$_.Path -notlike "*\.cursor\*" -and
$_.Path -notlike "*\.vscode\*" -and
$_.Path -notlike "*IntelliJ*" -and
$_.Path -notlike "*eclipse*"
}
if ($javaProcesses.Count -eq 0) {
Write-Success "Aucun processus Java trouvé à arrêter"
exit 0
}
Write-Info "Processus Java trouvés: $($javaProcesses.Count)"
$javaProcesses | ForEach-Object {
Write-Host " - PID: $($_.Id) | Process: $($_.ProcessName) | Path: $($_.Path)" -ForegroundColor Gray
}
# 2. Vérifier les ports utilisés
Write-Step "2. Vérification des ports utilisés..."
$ports = @(8080, 8081, 8180)
foreach ($port in $ports) {
$connections = netstat -ano | Select-String ":$port\s" | ForEach-Object {
if ($_ -match '\s+(\d+)$') {
$matches[1]
}
}
if ($connections) {
Write-Info "Port $port utilisé par les PIDs: $($connections -join ', ')"
}
}
# 3. Demander confirmation (sauf si -Force)
if (-not $Force) {
Write-Warning "`n⚠️ Ces processus seront arrêtés de force."
$confirm = Read-Host "Continuer ? (O/N)"
if ($confirm -ne "O" -and $confirm -ne "o" -and $confirm -ne "Y" -and $confirm -ne "y") {
Write-Info "Opération annulée"
exit 0
}
}
# 4. Arrêter les processus
Write-Step "3. Arrêt des processus Java..."
$killed = 0
$errors = 0
foreach ($process in $javaProcesses) {
try {
Write-Info "Arrêt du processus $($process.Id) ($($process.ProcessName))..."
Stop-Process -Id $process.Id -Force -ErrorAction Stop
$killed++
Write-Success "Processus $($process.Id) arrêté"
} catch {
$errors++
Write-Error "Erreur lors de l'arrêt du processus $($process.Id): $_"
}
}
# 5. Attendre un peu pour que les fichiers soient libérés
if ($killed -gt 0) {
Write-Info "Attente de 2 secondes pour libérer les fichiers..."
Start-Sleep -Seconds 2
}
# 6. Vérifier qu'il ne reste plus de processus (sauf Cursor/IDE)
Write-Step "4. Vérification finale..."
$remaining = Get-Process | Where-Object {
($_.ProcessName -like "*java*" -or $_.ProcessName -like "*javaw*") -and
$_.Path -notlike "*\.cursor\*" -and
$_.Path -notlike "*\.vscode\*" -and
$_.Path -notlike "*IntelliJ*" -and
$_.Path -notlike "*eclipse*"
}
if ($remaining.Count -eq 0) {
Write-Success "Tous les processus Java du projet ont été arrêtés"
} else {
Write-Warning "Il reste $($remaining.Count) processus Java:"
$remaining | ForEach-Object {
Write-Host " - PID: $($_.Id) | Process: $($_.ProcessName)" -ForegroundColor Yellow
}
}
# 7. Résumé
Write-Host @"
PROCESSUS JAVA ARRÊTÉS
"@ -ForegroundColor Green
Write-Host "📊 RÉSUMÉ:" -ForegroundColor Yellow
Write-Host " Processus arrêtés: $killed" -ForegroundColor White
if ($errors -gt 0) {
Write-Host " Erreurs: $errors" -ForegroundColor Red
}
Write-Host ""
Write-Host "💡 Vous pouvez maintenant exécuter 'mvn clean' sans erreur" -ForegroundColor Cyan
Write-Host ""