docs: SSH debugging guide pentru prod Windows — ce merge, ce nu merge

Adaugat in sectiunea 'Depanare SSH' din README:
- Comanda corecta ssh cu -i ~/.ssh/id_ed25519
- Deploy pachet Oracle via sqlplus @fisier.pck
- Restart FastAPI cand nssm e indisponibil (kill python + start.ps1)
- Tabel explicit cu ce NU merge (nssm/sc/WMI/pipe/curl -m/here-doc)
  si alternativele corecte
- Metoda scriere SQL ad-hoc: fisier local -> scp -> @fisier.sql

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Claude Agent
2026-04-28 10:45:19 +00:00
parent e42b1f63b7
commit 874ba4ca4e

View File

@@ -412,10 +412,10 @@ Loguri aplicatie: `logs/sync_comenzi_*.log`
```bash ```bash
# Conectare SSH (PowerShell remote, cheie publica) # Conectare SSH (PowerShell remote, cheie publica)
ssh -p 22122 gomag@79.119.86.134 ssh -i ~/.ssh/id_ed25519 -p 22122 -o StrictHostKeyChecking=no gomag@79.119.86.134
# Verificare .env # Verificare .env
cmd /c type C:\gomag-vending\api\.env powershell -Command "Get-Content C:\gomag-vending\api\.env | Select-String 'ORACLE_'"
# Test conexiune Oracle # Test conexiune Oracle
C:\gomag-vending\venv\Scripts\python.exe -c "import oracledb, os; os.environ['TNS_ADMIN']='C:/roa/instantclient_11_2_0_2'; conn=oracledb.connect(user='VENDING', password='ROMFASTSOFT', dsn='ROA'); print('Connected!'); conn.close()" C:\gomag-vending\venv\Scripts\python.exe -c "import oracledb, os; os.environ['TNS_ADMIN']='C:/roa/instantclient_11_2_0_2'; conn=oracledb.connect(user='VENDING', password='ROMFASTSOFT', dsn='ROA'); print('Connected!'); conn.close()"
@@ -423,20 +423,80 @@ C:\gomag-vending\venv\Scripts\python.exe -c "import oracledb, os; os.environ['TN
# Verificare tnsnames.ora # Verificare tnsnames.ora
cmd /c type C:\roa\instantclient_11_2_0_2\tnsnames.ora cmd /c type C:\roa\instantclient_11_2_0_2\tnsnames.ora
# Verificare procese Python # Verificare procese Python (ID-uri pentru kill/restart)
Get-Process *python* | Select-Object Id,ProcessName,Path powershell -Command "Get-Process python -ErrorAction SilentlyContinue | Format-Table Id, CPU -AutoSize"
# Verificare loguri recente # Verificare loguri recente
Get-ChildItem C:\gomag-vending\logs\*.log | Sort-Object LastWriteTime -Descending | Select-Object -First 3 Get-ChildItem C:\gomag-vending\logs\*.log | Sort-Object LastWriteTime -Descending | Select-Object -First 3
# Test sync manual (verifica ca Oracle pool porneste) # Test app (prin nginx reverse proxy)
curl http://localhost:5003/health powershell -Command "Invoke-WebRequest -Uri 'http://localhost/gomag/' -UseBasicParsing | Select-Object StatusCode"
curl -X POST http://localhost:5003/api/sync/start
# Refresh facturi manual # Retry comanda din linie de comanda
curl -X POST http://localhost:5003/api/dashboard/refresh-invoices powershell -Command "Invoke-WebRequest -Uri 'http://localhost/gomag/api/orders/NRCOMANDA/retry' -Method POST -UseBasicParsing | Select-Object -ExpandProperty Content"
``` ```
#### Deploy pachet Oracle PL/SQL via SSH
```bash
# Metoda corecta: sqlplus cu fisier .pck (contine ambele: PACKAGE + PACKAGE BODY)
ssh -i ~/.ssh/id_ed25519 -p 22122 gomag@79.119.86.134 \
"powershell -Command \"echo exit | sqlplus -S VENDING/PAROLA@ROA '@C:\\gomag-vending\\api\\database-scripts\\05_pack_import_parteneri.pck'\""
# Output asteptat: "Package created." + "Package body created."
```
#### Restart serviciu FastAPI via SSH
Userul `gomag` nu are acces la `nssm` sau `sc` (necesita Administrator).
Metoda disponibila — kill python + relanseaza start.ps1:
```bash
# 1. Gaseste PID-urile Python
ssh -i ~/.ssh/id_ed25519 -p 22122 gomag@79.119.86.134 \
"powershell -Command \"Get-Process python -ErrorAction SilentlyContinue | Format-Table Id, CPU -AutoSize\""
# 2. Kill + restart (inlocuieste PID1,PID2 cu valorile reale)
ssh -i ~/.ssh/id_ed25519 -p 22122 gomag@79.119.86.134 \
"powershell -Command \"Stop-Process -Id PID1,PID2 -Force -ErrorAction SilentlyContinue; Start-Sleep 2; cd C:\\gomag-vending; Start-Process powershell -ArgumentList '-NoExit','-File','start.ps1' -WindowStyle Hidden\""
# 3. Verifica ca a pornit (asteapta ~5s)
ssh -i ~/.ssh/id_ed25519 -p 22122 gomag@79.119.86.134 \
"powershell -Command \"Invoke-WebRequest -Uri 'http://localhost/gomag/' -UseBasicParsing | Select-Object StatusCode\""
```
#### Ce NU merge via SSH (userul gomag fara Administrator)
| Comanda | Eroare | Alternativa |
|---------|--------|-------------|
| `nssm restart GoMagVending` | `Error opening service manager!` | Kill python + Start-Process start.ps1 (vezi mai sus) |
| `sc query` / `sc stop` | `Access is denied` | Nu exista alternativa — necesita acces direct la server |
| `Get-WmiObject Win32_Process` | `Access denied` | `Get-Process` simplu fara CommandLine |
| Pipe `\|` in -Command cu ghilimele nested | `An empty pipe element is not allowed` | Scrie SQL in fisier temporar, copiaza cu scp, ruleaza `@fisier.sql` |
| `&&` (bash syntax) in PowerShell | `The term '&&' is not recognized` | Foloseste `;` (continua indiferent) sau `-Command "cmd1; cmd2"` |
| `-m` flag la `curl` in PowerShell | `Ambiguous parameter name` | Foloseste `Invoke-WebRequest` in loc de curl |
| Here-doc `<< 'EOF'` in PowerShell | `Missing file specification` | Scrie fisierul local, copiaza cu scp |
#### Rulare SQL ad-hoc prin SSH (fara interactiv)
PowerShell nu suporta pipe catre sqlplus cu ghilimele complexe. Metoda corecta:
```bash
# 1. Scrie SQL local
cat > /tmp/query.sql << 'EOF'
SELECT coloana FROM tabel WHERE conditie;
exit
EOF
# 2. Copiaza pe prod
scp -i ~/.ssh/id_ed25519 -P 22122 /tmp/query.sql "gomag@79.119.86.134:C:/gomag-vending/query.sql"
# 3. Ruleaza
ssh -i ~/.ssh/id_ed25519 -p 22122 gomag@79.119.86.134 \
"powershell -Command \"sqlplus -S VENDING/PAROLA@ROA '@C:\\gomag-vending\\query.sql'\""
```
**Nu folosi** `echo 'SQL;' | sqlplus` — PowerShell trateaza `|` diferit si poate esua cu "empty pipe element".
### Probleme frecvente ### Probleme frecvente
| Eroare | Cauza | Solutie | | Eroare | Cauza | Solutie |