feat(deploy): adauga script update.ps1 pentru git pull + restart rapid

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-16 16:07:49 +02:00
parent 2e8e5832e0
commit 2954bd5780

View File

@@ -0,0 +1,76 @@
#Requires -RunAsAdministrator
<#
.SYNOPSIS
BTGO Telegram Bot - Update & Restart
.DESCRIPTION
git pull + restart serviciu
#>
$ErrorActionPreference = "Stop"
$ServiceName = "BTGOTelegramBot"
$ScriptDir = Split-Path -Parent $PSCommandPath
$ProjectDir = Resolve-Path (Join-Path $ScriptDir "..\..\..") | Select-Object -ExpandProperty Path
function Write-ColorOutput {
param([string]$Message, [string]$Prefix = "")
$color = switch ($Prefix) {
"[OK]" { "Green" }
"[INFO]" { "Cyan" }
"[EROARE]" { "Red" }
"[WARN]" { "Yellow" }
default { "White" }
}
if ($Prefix) {
Write-Host "$Prefix " -ForegroundColor $color -NoNewline
Write-Host $Message
} else {
Write-Host $Message
}
}
Write-Host ""
Write-Host ("=" * 60) -ForegroundColor Cyan
Write-Host "BTGO - UPDATE & RESTART" -ForegroundColor Yellow
Write-Host ("=" * 60) -ForegroundColor Cyan
Write-Host ""
# [1] git pull
Write-ColorOutput "Rulare git pull..." -Prefix "[INFO]"
Set-Location $ProjectDir
git pull
if ($LASTEXITCODE -ne 0) {
Write-ColorOutput "git pull a esuat!" -Prefix "[EROARE]"
Read-Host "`nApasa Enter pentru a inchide"
exit 1
}
Write-ColorOutput "Cod actualizat" -Prefix "[OK]"
Write-Host ""
# [2] Restart serviciu
Write-ColorOutput "Restart serviciu $ServiceName..." -Prefix "[INFO]"
$service = Get-Service -Name $ServiceName -ErrorAction SilentlyContinue
if (-not $service) {
Write-ColorOutput "Serviciul nu este instalat. Ruleaza deploy.ps1 intai." -Prefix "[EROARE]"
Read-Host "`nApasa Enter pentru a inchide"
exit 1
}
Stop-Service -Name $ServiceName -Force -ErrorAction SilentlyContinue
Start-Sleep -Seconds 2
Start-Service -Name $ServiceName
Start-Sleep -Seconds 2
$service = Get-Service -Name $ServiceName
if ($service.Status -eq "Running") {
Write-ColorOutput "Serviciu pornit cu succes" -Prefix "[OK]"
Write-Host ""
Write-Host "Logs live:" -ForegroundColor Yellow
Write-Host " Get-Content '$ProjectDir\logs\telegram_bot_stdout.log' -Wait"
} else {
Write-ColorOutput "Serviciul nu ruleaza!" -Prefix "[EROARE]"
Get-Service -Name $ServiceName | Format-Table -AutoSize
}
Write-Host ""
Read-Host "Apasa Enter pentru a inchide"