feat(base): finalizada Fase 1 scaffolding v0.1.0-alpha
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
# Nginx configuration for OnEverControl reverse proxy and static assets
|
||||
server {
|
||||
listen 80;
|
||||
server_name _;
|
||||
|
||||
# Compresión Gzip para clientes móviles y tablets de 4GB RAM
|
||||
gzip on;
|
||||
gzip_vary on;
|
||||
gzip_min_length 1024;
|
||||
gzip_proxied expired no-cache no-store private auth;
|
||||
gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/xml application/json;
|
||||
gzip_disable "MSIE [1-6]\.";
|
||||
|
||||
# Estáticos de la aplicación React SPA
|
||||
location / {
|
||||
root /usr/share/nginx/html;
|
||||
index index.html index.htm;
|
||||
try_files $uri $uri/ /index.html;
|
||||
}
|
||||
|
||||
# API Proxy hacia FastAPI
|
||||
location /api/ {
|
||||
proxy_pass http://backend:8000;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
}
|
||||
|
||||
# Endpoint de salud y Swagger
|
||||
location ~ ^/(health|docs|openapi.json) {
|
||||
proxy_pass http://backend:8000;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
}
|
||||
|
||||
# WebSockets en vivo para garitas
|
||||
location /ws/ {
|
||||
proxy_pass http://backend:8000;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection "upgrade";
|
||||
proxy_set_header Host $host;
|
||||
proxy_read_timeout 86400s;
|
||||
proxy_send_timeout 86400s;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
[Unit]
|
||||
Description=OnEverControl Web API (FastAPI)
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
User=root
|
||||
WorkingDirectory=/opt/onevercontrol/backend
|
||||
EnvironmentFile=/opt/onevercontrol/.env
|
||||
ExecStart=/opt/onevercontrol/backend/venv/bin/uvicorn app.main:app --host 0.0.0.0 --port 8000
|
||||
Restart=always
|
||||
RestartSec=5
|
||||
KillMode=process
|
||||
StandardOutput=journal
|
||||
StandardError=journal
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
@@ -0,0 +1,40 @@
|
||||
#!/usr/bin/env bash
|
||||
# ==============================================================================
|
||||
# Script de aprovisionamiento para Contenedores LXC (Debian / Ubuntu / Proxmox)
|
||||
# ==============================================================================
|
||||
set -e
|
||||
|
||||
echo "=== [1/4] Actualizando repositorios e instalando paquetes del sistema ==="
|
||||
apt-get update
|
||||
apt-get install -y --no-install-recommends \
|
||||
python3 \
|
||||
python3-venv \
|
||||
python3-pip \
|
||||
freetds-dev \
|
||||
freetds-bin \
|
||||
build-essential \
|
||||
nginx \
|
||||
curl \
|
||||
git
|
||||
|
||||
APP_DIR="/opt/onevercontrol"
|
||||
echo "=== [2/4] Preparando directorio de aplicacion en $APP_DIR ==="
|
||||
mkdir -p "$APP_DIR"
|
||||
|
||||
echo "=== [3/4] Creando entorno virtual Python e instalando dependencias ==="
|
||||
python3 -m venv "$APP_DIR/backend/venv"
|
||||
"$APP_DIR/backend/venv/bin/pip" install --upgrade pip
|
||||
if [ -f "$APP_DIR/backend/requirements.txt" ]; then
|
||||
"$APP_DIR/backend/venv/bin/pip" install -r "$APP_DIR/backend/requirements.txt"
|
||||
fi
|
||||
|
||||
echo "=== [4/4] Instalando servicio systemd ==="
|
||||
cp "$(dirname "$0")/onevercontrol.service" /etc/systemd/system/
|
||||
systemctl daemon-reload
|
||||
systemctl enable onevercontrol.service
|
||||
|
||||
echo "====================================================================="
|
||||
echo " Aprovisionamiento de LXC completado con exito."
|
||||
echo " Para iniciar: systemctl start onevercontrol"
|
||||
echo " Para ver logs: journalctl -u onevercontrol -f"
|
||||
echo "====================================================================="
|
||||
@@ -0,0 +1,89 @@
|
||||
#!/usr/bin/env python3
|
||||
# ==============================================================================
|
||||
# Script de Diagnóstico de Conexión a SQL Server (videoman)
|
||||
# Compatible con Windows 10/11, LXC (FreeTDS) y Docker
|
||||
# ==============================================================================
|
||||
import sys
|
||||
import platform
|
||||
from pathlib import Path
|
||||
|
||||
# Agregar directorio backend al path para importar configuración
|
||||
BACKEND_DIR = Path(__file__).resolve().parent.parent / "backend"
|
||||
if str(BACKEND_DIR) not in sys.path:
|
||||
sys.path.insert(0, str(BACKEND_DIR))
|
||||
|
||||
try:
|
||||
from app.core.config import settings
|
||||
from app.__version__ import __version__
|
||||
except ImportError as e:
|
||||
print(f"[ERROR] No se pudo importar la configuracion de backend: {e}")
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def test_sql_connection():
|
||||
print("=" * 70)
|
||||
print(f" Diagnostico de Conexion SQL Server - OnEverControl v{__version__}")
|
||||
print("=" * 70)
|
||||
print(f"Sistema Operativo : {platform.system()} {platform.release()} ({platform.machine()})")
|
||||
print(f"Python : {platform.python_version()}")
|
||||
print(f"Servidor Destino : {settings.DB_SERVER}:{settings.DB_PORT}")
|
||||
print(f"Base de Datos : {settings.DB_NAME}")
|
||||
print(f"Usuario : {settings.DB_USER}")
|
||||
print(f"Charset : {settings.DB_CHARSET}")
|
||||
print("-" * 70)
|
||||
|
||||
try:
|
||||
import pymssql
|
||||
except ImportError:
|
||||
print("[ERROR] pymssql no esta instalado en este entorno.")
|
||||
print("Instalelo con: pip install pymssql")
|
||||
return False
|
||||
|
||||
print(f"[INFO] Intentando conectar a '{settings.DB_SERVER}'...")
|
||||
|
||||
try:
|
||||
conn = pymssql.connect(
|
||||
server=settings.DB_SERVER,
|
||||
port=settings.DB_PORT,
|
||||
user=settings.DB_USER,
|
||||
password=settings.DB_PASSWORD,
|
||||
database=settings.DB_NAME,
|
||||
charset=settings.DB_CHARSET,
|
||||
login_timeout=settings.DB_TIMEOUT,
|
||||
timeout=settings.DB_TIMEOUT,
|
||||
)
|
||||
cursor = conn.cursor()
|
||||
cursor.execute("SELECT @@VERSION, DB_NAME(), GETDATE();")
|
||||
row = cursor.fetchone()
|
||||
|
||||
print("[OK] CONEXION EXITOSA!")
|
||||
print("-" * 70)
|
||||
print(f"Base de Datos Activa: {row[1]}")
|
||||
print(f"Fecha/Hora Servidor : {row[2]}")
|
||||
print(f"Version SQL Server : {row[0].splitlines()[0]}")
|
||||
print("=" * 70)
|
||||
|
||||
cursor.close()
|
||||
conn.close()
|
||||
return True
|
||||
|
||||
except pymssql.OperationalError as err:
|
||||
print("[ERROR] Fallo operacional al conectar con SQL Server:")
|
||||
print(f" -> {err}")
|
||||
print("-" * 70)
|
||||
print("POSIBLES CAUSAS Y SOLUCIONES:")
|
||||
print(" 1. Verifique que el servicio SQL Server este en ejecucion.")
|
||||
print(" 2. En SQL Server Configuration Manager, confirme que TCP/IP este HABILITADO.")
|
||||
print(" 3. Verifique que el firewall de Windows permita el puerto 1433 TCP.")
|
||||
print(" 4. Si usa nombre de instancia (ej: localhost\\SQLEXPRESS), verifique que SQL Browser este activo.")
|
||||
print(" 5. Revise que las credenciales en .env sean correctas.")
|
||||
print("=" * 70)
|
||||
return False
|
||||
except Exception as ex:
|
||||
print(f"[ERROR] Error inesperado: {ex}")
|
||||
return False
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
success = test_sql_connection()
|
||||
sys.exit(0 if success else 1)
|
||||
@@ -0,0 +1,49 @@
|
||||
@echo off
|
||||
setlocal
|
||||
echo =====================================================================
|
||||
echo OnEverControl - Instalador de Servicio de Windows (NSSM)
|
||||
echo =====================================================================
|
||||
|
||||
net session >nul 2>&1
|
||||
if %errorLevel% neq 0 (
|
||||
echo [ERROR] Este script requiere privilegios de Administrador.
|
||||
echo Por favor ejecute como Administrador.
|
||||
pause
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
set SERVICE_NAME=OnEverControl
|
||||
set APP_DIR=%~dp0..\..\backend
|
||||
set PYTHON_EXE=%APP_DIR%\venv\Scripts\python.exe
|
||||
set UVICORN_EXE=%APP_DIR%\venv\Scripts\uvicorn.exe
|
||||
|
||||
if not exist "%UVICORN_EXE%" (
|
||||
echo [ERROR] No se encontro el entorno virtual en: %APP_DIR%\venv
|
||||
echo Cree el venv ejecutando en backend: python -m venv venv ^&^& pip install -r requirements.txt
|
||||
pause
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
where nssm >nul 2>&1
|
||||
if %errorLevel% neq 0 (
|
||||
echo [AVISO] NSSM no fue encontrado en PATH. Descarguelo de https://nssm.cc/ y coloquelo en PATH o en esta carpeta.
|
||||
pause
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
echo [INFO] Instalando servicio %SERVICE_NAME%...
|
||||
nssm install %SERVICE_NAME% "%UVICORN_EXE%" "app.main:app --host 0.0.0.0 --port 8000"
|
||||
nssm set %SERVICE_NAME% AppDirectory "%APP_DIR%"
|
||||
nssm set %SERVICE_NAME% Description "Servidor Web OnEverControl Puesto de Control"
|
||||
nssm set %SERVICE_NAME% Start SERVICE_AUTO_START
|
||||
nssm set %SERVICE_NAME% AppStdout "%APP_DIR%\logs\service.log"
|
||||
nssm set %SERVICE_NAME% AppStderr "%APP_DIR%\logs\service_error.log"
|
||||
|
||||
echo [INFO] Iniciando servicio...
|
||||
nssm start %SERVICE_NAME%
|
||||
|
||||
echo =====================================================================
|
||||
echo Servicio instalado con exito. Estado actual:
|
||||
echo =====================================================================
|
||||
nssm status %SERVICE_NAME%
|
||||
pause
|
||||
@@ -0,0 +1,20 @@
|
||||
@echo off
|
||||
setlocal
|
||||
echo =====================================================================
|
||||
echo Iniciando OnEverControl en modo nativo Windows
|
||||
echo =====================================================================
|
||||
|
||||
cd /d "%~dp0..\..\backend"
|
||||
|
||||
if not exist "venv\Scripts\activate.bat" (
|
||||
echo [INFO] Creando entorno virtual Python...
|
||||
python -m venv venv
|
||||
call venv\Scripts\activate.bat
|
||||
pip install -r requirements.txt
|
||||
) else (
|
||||
call venv\Scripts\activate.bat
|
||||
)
|
||||
|
||||
echo [INFO] Levantando servidor Uvicorn en http://0.0.0.0:8000 ...
|
||||
uvicorn app.main:app --host 0.0.0.0 --port 8000 --reload
|
||||
pause
|
||||
Reference in New Issue
Block a user