Files
descarga_xml_sunat/docs/DEPLOYMENT.md
T

87 lines
2.2 KiB
Markdown
Raw Normal View History

2026-07-17 12:21:31 -05:00
# Despliegue
## systemd (Linux)
### Requisitos adicionales
- **Mozilla Firefox** instalado (para `get_token_headless.py`)
2026-07-17 12:21:31 -05:00
- **rsync** y **cifs-utils** (para montar SMB y sincronizar)
### Servicio
```ini
[Unit]
Description=SUNAT CPE Downloader Daemon
After=network.target
[Service]
Type=simple
User=tu_usuario
WorkingDirectory=/ruta/a/descarga_xml_sunat
ExecStart=/usr/bin/python3 main.py
Restart=always
RestartSec=30
[Install]
WantedBy=multi-user.target
```
```bash
# Guarda el bloque [Unit]/[Service]/[Install] de arriba en un archivo, ej. sunat-cpe.service
2026-07-17 12:21:31 -05:00
sudo cp sunat-cpe.service /etc/systemd/system/
sudo systemctl enable sunat-cpe
sudo systemctl start sunat-cpe
```
## NSSM (Windows)
### Requisitos
- **Mozilla Firefox** instalado (cualquier versión) — necesario para `get_token_headless.py`
2026-07-17 12:21:31 -05:00
- Python 3.12+ con dependencias instaladas
- **Unidad de red mapeable** (SMB) para sincronizar descargas
### Instalación como servicio
```cmd
:: Instalar servicio
nssm install SUNAT-CPE "C:\Python312\python.exe" "C:\ruta\descarga_xml_sunat\main.py"
:: Configurar directorio de trabajo
nssm set SUNAT-CPE AppDirectory "C:\ruta\descarga_xml_sunat"
:: Configurar reinicio automático
nssm set SUNAT-CPE AppExit Default Exit
nssm set SUNAT-CPE AppThrottle 30000
:: Iniciar servicio
nssm set SUNAT-CPE Start SERVICE_AUTO_START
nssm start SUNAT-CPE
```
### Logs
NSSM redirige stdout/stderr a `C:\ruta\descarga_xml_sunat\logs\` por defecto (el logger del daemon también escribe allí).
### Renovación de token
Como servicio, el daemon usa `get_token_headless()` (headless, Firefox real) para renovar el token automáticamente sin intervención. Si Firefox no está instalado, el daemon lo detecta y usa `get_token.py headless=False` como respaldo (requiere escritorio). Para renovar manualmente:
2026-07-17 12:21:31 -05:00
```cmd
C:\ruta\descarga_xml_sunat\sunat-venv\Scripts\python get_token.py
2026-07-17 12:21:31 -05:00
```
### Actualización
```cmd
nssm stop SUNAT-CPE
:: actualizar archivos
nssm start SUNAT-CPE
```
## Docker (opcional)
```dockerfile
FROM python:3.12-slim
RUN pip install -r requirements.txt && playwright install firefox
2026-07-17 12:21:31 -05:00
WORKDIR /app
COPY . .
CMD ["python", "main.py"]
```
Asegúrate de que `requirements.txt` incluya: `playwright`, `python-dotenv`, `requests`, `hdbcli`.