initializare
This commit is contained in:
133
deployment/windows/scripts/uninstall_service.ps1
Normal file
133
deployment/windows/scripts/uninstall_service.ps1
Normal file
@@ -0,0 +1,133 @@
|
||||
#Requires -RunAsAdministrator
|
||||
<#
|
||||
.SYNOPSIS
|
||||
BTGO Telegram Bot - Service Uninstall Script
|
||||
.DESCRIPTION
|
||||
Dezinstaleaza serviciul Windows BTGO Telegram Bot
|
||||
.NOTES
|
||||
Rulare: Right-click → "Run with PowerShell" (ca Administrator)
|
||||
#>
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
# ============================================================================
|
||||
# CONFIGURATION
|
||||
# ============================================================================
|
||||
|
||||
$ServiceName = "BTGOTelegramBot"
|
||||
$ScriptDir = Split-Path -Parent $PSCommandPath
|
||||
$ProjectDir = Resolve-Path (Join-Path $ScriptDir "..\..\..") | Select-Object -ExpandProperty Path
|
||||
$NssmPath = Join-Path $ProjectDir "deployment\windows\tools\nssm.exe"
|
||||
|
||||
function Write-ColorOutput {
|
||||
param([string]$Message, [string]$Prefix = "")
|
||||
$color = switch ($Prefix) {
|
||||
"[OK]" { "Green" }
|
||||
"[INFO]" { "Cyan" }
|
||||
"[EROARE]" { "Red" }
|
||||
"[AVERTIZARE]" { "Yellow" }
|
||||
default { "White" }
|
||||
}
|
||||
if ($Prefix) {
|
||||
Write-Host "$Prefix " -ForegroundColor $color -NoNewline
|
||||
Write-Host $Message
|
||||
} else {
|
||||
Write-Host $Message
|
||||
}
|
||||
}
|
||||
|
||||
function Write-Separator {
|
||||
param([string]$Title = "")
|
||||
Write-Host ""
|
||||
Write-Host ("=" * 80) -ForegroundColor Cyan
|
||||
if ($Title) {
|
||||
Write-Host $Title -ForegroundColor Yellow
|
||||
Write-Host ("=" * 80) -ForegroundColor Cyan
|
||||
}
|
||||
}
|
||||
|
||||
# ============================================================================
|
||||
# VERIFICARE SERVICIU
|
||||
# ============================================================================
|
||||
|
||||
Write-Separator "DEZINSTALARE SERVICIU: $ServiceName"
|
||||
Write-Host ""
|
||||
|
||||
$service = Get-Service -Name $ServiceName -ErrorAction SilentlyContinue
|
||||
|
||||
if (-not $service) {
|
||||
Write-ColorOutput "Serviciul $ServiceName nu este instalat." -Prefix "[INFO]"
|
||||
Write-Host "Nimic de dezinstalat."
|
||||
Read-Host "`nApasa Enter pentru a inchide"
|
||||
exit 0
|
||||
}
|
||||
|
||||
# ============================================================================
|
||||
# OPRIRE SERVICIU
|
||||
# ============================================================================
|
||||
|
||||
Write-ColorOutput "Verificare status serviciu..." -Prefix "[INFO]"
|
||||
|
||||
if ($service.Status -eq "Running") {
|
||||
Write-ColorOutput "Serviciul ruleaza. Oprire..." -Prefix "[INFO]"
|
||||
try {
|
||||
Stop-Service -Name $ServiceName -Force
|
||||
Write-ColorOutput "Serviciu oprit cu succes" -Prefix "[OK]"
|
||||
Start-Sleep -Seconds 2
|
||||
} catch {
|
||||
Write-ColorOutput "Oprirea serviciului a esuat!" -Prefix "[AVERTIZARE]"
|
||||
Write-ColorOutput "Incercam oprire fortata..." -Prefix "[INFO]"
|
||||
sc.exe stop $ServiceName | Out-Null
|
||||
Start-Sleep -Seconds 5
|
||||
}
|
||||
} else {
|
||||
Write-ColorOutput "Serviciul este deja oprit" -Prefix "[INFO]"
|
||||
}
|
||||
|
||||
# ============================================================================
|
||||
# DEZINSTALARE SERVICIU
|
||||
# ============================================================================
|
||||
|
||||
Write-ColorOutput "Dezinstalare serviciu..." -Prefix "[INFO]"
|
||||
|
||||
try {
|
||||
if (Test-Path $NssmPath) {
|
||||
# Folosește NSSM pentru dezinstalare
|
||||
& $NssmPath remove $ServiceName confirm
|
||||
if ($LASTEXITCODE -ne 0) { throw }
|
||||
} else {
|
||||
# Fallback la sc delete
|
||||
Write-ColorOutput "NSSM nu a fost gasit, folosim sc delete" -Prefix "[INFO]"
|
||||
sc.exe delete $ServiceName | Out-Null
|
||||
if ($LASTEXITCODE -ne 0) { throw }
|
||||
}
|
||||
} catch {
|
||||
Write-ColorOutput "Dezinstalarea serviciului a esuat!" -Prefix "[EROARE]"
|
||||
Read-Host "`nApasa Enter pentru a inchide"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# ============================================================================
|
||||
# VERIFICARE FINALA
|
||||
# ============================================================================
|
||||
|
||||
Start-Sleep -Seconds 2
|
||||
|
||||
$serviceCheck = Get-Service -Name $ServiceName -ErrorAction SilentlyContinue
|
||||
|
||||
if (-not $serviceCheck) {
|
||||
Write-Separator "[SUCCES] SERVICIU DEZINSTALAT CU SUCCES!"
|
||||
Write-Host ""
|
||||
Write-Host "Serviciul $ServiceName a fost eliminat din sistem." -ForegroundColor Green
|
||||
Write-Host ""
|
||||
Write-Host "Pentru a reinstala serviciul, rulati:" -ForegroundColor Yellow
|
||||
Write-Host " .\install_service.ps1"
|
||||
Write-Host ""
|
||||
Write-Separator
|
||||
} else {
|
||||
Write-ColorOutput "Serviciul pare sa mai existe in sistem!" -Prefix "[AVERTIZARE]"
|
||||
Write-Host "Poate fi nevoie de un restart al sistemului."
|
||||
Get-Service -Name $ServiceName | Format-List
|
||||
}
|
||||
|
||||
Read-Host "`nApasa Enter pentru a inchide"
|
||||
Reference in New Issue
Block a user