82 lines
2.5 KiB
PowerShell
82 lines
2.5 KiB
PowerShell
<#
|
|
.SYNOPSIS
|
|
BTGO Telegram Bot - Update & Restart
|
|
.DESCRIPTION
|
|
git pull + restart serviciu
|
|
#>
|
|
|
|
# Auto-elevare daca nu e Administrator
|
|
if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
|
|
Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs
|
|
exit
|
|
}
|
|
|
|
$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"
|