88 lines
2.3 KiB
PowerShell
88 lines
2.3 KiB
PowerShell
#Requires -RunAsAdministrator
|
|
<#
|
|
.SYNOPSIS
|
|
BTGO Telegram Bot - Service Restart Script
|
|
.DESCRIPTION
|
|
Restart rapid al serviciului
|
|
#>
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
$ServiceName = "BTGOTelegramBot"
|
|
|
|
function Write-ColorOutput {
|
|
param([string]$Message, [string]$Prefix = "")
|
|
$color = switch ($Prefix) {
|
|
"[OK]" { "Green" }
|
|
"[INFO]" { "Cyan" }
|
|
"[EROARE]" { "Red" }
|
|
default { "White" }
|
|
}
|
|
if ($Prefix) {
|
|
Write-Host "$Prefix " -ForegroundColor $color -NoNewline
|
|
Write-Host $Message
|
|
} else {
|
|
Write-Host $Message
|
|
}
|
|
}
|
|
|
|
function Write-Separator {
|
|
Write-Host ""
|
|
Write-Host ("=" * 80) -ForegroundColor Cyan
|
|
Write-Host "RESTART SERVICIU: $ServiceName" -ForegroundColor Yellow
|
|
Write-Host ("=" * 80) -ForegroundColor Cyan
|
|
Write-Host ""
|
|
}
|
|
|
|
Write-Separator
|
|
|
|
# Verifică dacă serviciul există
|
|
$service = Get-Service -Name $ServiceName -ErrorAction SilentlyContinue
|
|
|
|
if (-not $service) {
|
|
Write-ColorOutput "Serviciul $ServiceName nu este instalat!" -Prefix "[EROARE]"
|
|
Read-Host "`nApasa Enter pentru a inchide"
|
|
exit 1
|
|
}
|
|
|
|
# Oprește serviciul
|
|
Write-ColorOutput "Oprire serviciu..." -Prefix "[INFO]"
|
|
try {
|
|
Stop-Service -Name $ServiceName -Force
|
|
Write-ColorOutput "Serviciu oprit" -Prefix "[OK]"
|
|
} catch {
|
|
Write-ColorOutput "Oprirea a esuat. Incercam oprire fortata..." -Prefix "[AVERTIZARE]"
|
|
sc.exe stop $ServiceName | Out-Null
|
|
}
|
|
|
|
Start-Sleep -Seconds 2
|
|
|
|
# Pornește serviciul
|
|
Write-ColorOutput "Pornire serviciu..." -Prefix "[INFO]"
|
|
try {
|
|
Start-Service -Name $ServiceName
|
|
Write-ColorOutput "Serviciu pornit" -Prefix "[OK]"
|
|
} catch {
|
|
Write-ColorOutput "Pornirea serviciului a esuat!" -Prefix "[EROARE]"
|
|
Write-Host "Verificati logurile pentru detalii"
|
|
Read-Host "`nApasa Enter pentru a inchide"
|
|
exit 1
|
|
}
|
|
|
|
Start-Sleep -Seconds 2
|
|
|
|
# Verifică status
|
|
$service = Get-Service -Name $ServiceName
|
|
|
|
if ($service.Status -eq "Running") {
|
|
Write-Host ""
|
|
Write-ColorOutput "[SUCCES] Serviciu restartat cu succes!" -ForegroundColor Green
|
|
Write-Host ""
|
|
Get-Service -Name $ServiceName | Format-Table -AutoSize
|
|
} else {
|
|
Write-Host ""
|
|
Write-ColorOutput "Serviciul nu ruleaza dupa restart!" -Prefix "[EROARE]"
|
|
Get-Service -Name $ServiceName | Format-Table -AutoSize
|
|
}
|
|
|
|
Read-Host "`nApasa Enter pentru a inchide"
|