86 lines
2.1 KiB
Markdown
86 lines
2.1 KiB
Markdown
# Despliegue
|
|||
|
|
|
||
|
|
## systemd (Linux)
|
||
|
|
|
||
|
|
### Requisitos adicionales
|
||
|
|
- **Google Chrome** instalado (para `get_token_headless.py`)
|
||
|
|
- **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
|
||
|
|
sudo cp sunat-cpe.service /etc/systemd/system/
|
||
|
|
sudo systemctl enable sunat-cpe
|
||
|
|
sudo systemctl start sunat-cpe
|
||
|
|
```
|
||
|
|
|
||
|
|
## NSSM (Windows)
|
||
|
|
|
||
|
|
### Requisitos
|
||
|
|
- **Google Chrome** instalado (cualquier versión) — necesario para `get_token_headless.py`
|
||
|
|
- 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, Chrome real) para renovar el token automáticamente sin intervención. Si Chrome no está instalado, el daemon lo detecta y usa `get_token.py headless=False` como respaldo (requiere escritorio). Para renovar manualmente:
|
||
|
|
|
||
|
|
```cmd
|
||
|
|
C:\ruta\descarga_xml_sunat\sunat-env\Scripts\python get_token.py
|
||
|
|
```
|
||
|
|
|
||
|
|
### 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 chromium
|
||
|
|
WORKDIR /app
|
||
|
|
COPY . .
|
||
|
|
CMD ["python", "main.py"]
|
||
|
|
```
|
||
|
|
|
||
|
|
Asegúrate de que `requirements.txt` incluya: `playwright`, `python-dotenv`, `requests`, `hdbcli`, `matplotlib`.
|