initializare
This commit is contained in:
87
deployment/windows/scripts/restart_service.ps1
Normal file
87
deployment/windows/scripts/restart_service.ps1
Normal file
@@ -0,0 +1,87 @@
|
||||
#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"
|
||||
Reference in New Issue
Block a user