29-sep: [servicios] Migración watchers al VPS - Telegram Watcher y Shutdown Listener migrados al VPS - Recordatorios Msgbox eliminado - Scripts de instalación y documentación completa
This commit is contained in:
@@ -13,9 +13,18 @@
|
|||||||
- **2026-09-20-fix-bot-telegram-control-pc-confirmacion-watchdog** [scripts] Fix bot Telegram control PC: confirmacion + watchdog (aplicado en: sobremesa)
|
- **2026-09-20-fix-bot-telegram-control-pc-confirmacion-watchdog** [scripts] Fix bot Telegram control PC: confirmacion + watchdog (aplicado en: sobremesa)
|
||||||
- **2026-09-20-shutdown-listener-instalado-como-tarea-programada** [watchers] Shutdown listener instalado como tarea programada (aplicado en: sobremesa)
|
- **2026-09-20-shutdown-listener-instalado-como-tarea-programada** [watchers] Shutdown listener instalado como tarea programada (aplicado en: sobremesa)
|
||||||
- **2026-09-20-timeout-home-assistant-aumentado-5s-15s-para-proxy-shutdown** [servicios] Timeout Home Assistant aumentado 5s→15s para proxy shutdown (aplicado en: sobremesa)
|
- **2026-09-20-timeout-home-assistant-aumentado-5s-15s-para-proxy-shutdown** [servicios] Timeout Home Assistant aumentado 5s→15s para proxy shutdown (aplicado en: sobremesa)
|
||||||
|
- **2026-09-29-migraci-n-de-watchers-al-vps** [servicios] Migración de watchers al VPS (aplicado en: sobremesa)
|
||||||
|
|
||||||
## Historial
|
## Historial
|
||||||
|
|
||||||
|
### 2026-09-29 · Migración de watchers al VPS
|
||||||
|
- **id**: `2026-09-29-migraci-n-de-watchers-al-vps`
|
||||||
|
- **Equipo**: sobremesa
|
||||||
|
- **Categoria**: servicios
|
||||||
|
- **Transferible**: si
|
||||||
|
- **Aplicado en**: sobremesa
|
||||||
|
- **Detalle**: Telegram Watcher y Shutdown Listener migrados al VPS. Recordatorios Msgbox eliminado. Ver INFRAESTRUCTURA/vps/MIGRACION_SERVICIOS_VPS.md para instrucciones.
|
||||||
|
|
||||||
### 2026-09-20 · OmniRoute arranque fiable (tarea programada + vigilante)
|
### 2026-09-20 · OmniRoute arranque fiable (tarea programada + vigilante)
|
||||||
- **id**: `2026-09-20-omniroute-arranque-fiable-tarea-programada-vigilante`
|
- **id**: `2026-09-20-omniroute-arranque-fiable-tarea-programada-vigilante`
|
||||||
- **Equipo**: sobremesa
|
- **Equipo**: sobremesa
|
||||||
|
|||||||
@@ -168,6 +168,18 @@
|
|||||||
"sobremesa"
|
"sobremesa"
|
||||||
],
|
],
|
||||||
"detalle": "Documentado problema usuario temporal Juan M en pantalla login. No es usuario real, es perfil corrupto de Windows. Solución: ejecutar scripts\\fix_autologon.ps1 como Admin y reiniciar. Autologon correctamente configurado pero perfil persiste en caché."
|
"detalle": "Documentado problema usuario temporal Juan M en pantalla login. No es usuario real, es perfil corrupto de Windows. Solución: ejecutar scripts\\fix_autologon.ps1 como Admin y reiniciar. Autologon correctamente configurado pero perfil persiste en caché."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "2026-09-29-migraci-n-de-watchers-al-vps",
|
||||||
|
"fecha": "2026-09-29",
|
||||||
|
"equipo": "sobremesa",
|
||||||
|
"categoria": "servicios",
|
||||||
|
"titulo": "Migración de watchers al VPS",
|
||||||
|
"transferible": true,
|
||||||
|
"aplicado_en": [
|
||||||
|
"sobremesa"
|
||||||
|
],
|
||||||
|
"detalle": "Telegram Watcher y Shutdown Listener migrados al VPS. Recordatorios Msgbox eliminado. Ver INFRAESTRUCTURA/vps/MIGRACION_SERVICIOS_VPS.md para instrucciones."
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
228
vps/MIGRACION_SERVICIOS_VPS.md
Normal file
228
vps/MIGRACION_SERVICIOS_VPS.md
Normal file
@@ -0,0 +1,228 @@
|
|||||||
|
# Migración de Servicios al VPS
|
||||||
|
|
||||||
|
**Fecha:** 29 Sep 2026
|
||||||
|
**Servicios migrados:**
|
||||||
|
- Telegram Watcher
|
||||||
|
- Shutdown Listener
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## ✅ Estado Actual
|
||||||
|
|
||||||
|
### En el PC Local (sobremesa)
|
||||||
|
- ❌ **Recordatorios Msgbox** → ELIMINADO (no se quiere más)
|
||||||
|
- ❌ **Telegram Watcher** → MIGRADO AL VPS
|
||||||
|
- ❌ **Shutdown Listener** → MIGRADO AL VPS
|
||||||
|
- ✅ **OmniRoute Watchdog** → MANTIENE LOCAL (necesario para OpenCode)
|
||||||
|
|
||||||
|
### En el VPS (185.187.169.109)
|
||||||
|
- ✅ **Telegram Watcher** → Servicio systemd
|
||||||
|
- ✅ **Shutdown Listener** → Servicio systemd
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📋 Instalación en el VPS
|
||||||
|
|
||||||
|
### 1. Conectarse al VPS
|
||||||
|
|
||||||
|
```bash
|
||||||
|
ssh -i C:\Users\juanm\Documents\GitHub\contabo root@185.187.169.109
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2. Ejecutar script de configuración
|
||||||
|
|
||||||
|
```bash
|
||||||
|
/root/configurar_servicios.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
Te pedirá:
|
||||||
|
- **TELEGRAM_API_ID**: API ID de Telegram (obtener de https://my.telegram.org)
|
||||||
|
- **TELEGRAM_API_HASH**: API Hash de Telegram
|
||||||
|
- **TELEGRAM_BOT_TOKEN**: Token del bot de Telegram (obtener de @BotFather)
|
||||||
|
- **SHUTDOWN_TOKEN**: Token de seguridad (presiona Enter para usar el actual)
|
||||||
|
|
||||||
|
### 3. Verificar que los servicios están corriendo
|
||||||
|
|
||||||
|
```bash
|
||||||
|
systemctl status telegram-watcher
|
||||||
|
systemctl status shutdown-listener
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📊 Monitorización
|
||||||
|
|
||||||
|
### Ver logs en tiempo real
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Telegram Watcher
|
||||||
|
journalctl -u telegram-watcher -f
|
||||||
|
|
||||||
|
# Shutdown Listener
|
||||||
|
journalctl -u shutdown-listener -f
|
||||||
|
```
|
||||||
|
|
||||||
|
### Ver mensajes de Telegram
|
||||||
|
|
||||||
|
```bash
|
||||||
|
tail -f /var/log/telegram_watcher/mensajes.log
|
||||||
|
```
|
||||||
|
|
||||||
|
### Reiniciar servicios
|
||||||
|
|
||||||
|
```bash
|
||||||
|
systemctl restart telegram-watcher
|
||||||
|
systemctl restart shutdown-listener
|
||||||
|
```
|
||||||
|
|
||||||
|
### Ver estado
|
||||||
|
|
||||||
|
```bash
|
||||||
|
systemctl status telegram-watcher
|
||||||
|
systemctl status shutdown-listener
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🔧 Configuración del Shutdown Listener
|
||||||
|
|
||||||
|
### Requisitos previos
|
||||||
|
|
||||||
|
Para que el Shutdown Listener del VPS pueda apagar el PC:
|
||||||
|
|
||||||
|
1. **SSH habilitado en el PC Windows**
|
||||||
|
- Instalar OpenSSH Server (Configuración → Aplicaciones → Características opcionales → OpenSSH Server)
|
||||||
|
- Iniciar servicio: `Start-Service sshd`
|
||||||
|
- Habilitar al inicio: `Set-Service -Name sshd -StartupType 'Automatic'`
|
||||||
|
|
||||||
|
2. **Configurar clave SSH del VPS en el PC**
|
||||||
|
|
||||||
|
En el VPS:
|
||||||
|
```bash
|
||||||
|
# Generar clave si no existe
|
||||||
|
ssh-keygen -t rsa -b 4096 -f /root/.ssh/id_rsa -N ""
|
||||||
|
|
||||||
|
# Copiar clave pública
|
||||||
|
cat /root/.ssh/id_rsa.pub
|
||||||
|
```
|
||||||
|
|
||||||
|
En el PC Windows:
|
||||||
|
```powershell
|
||||||
|
# Crear directorio SSH si no existe
|
||||||
|
mkdir C:\Users\juanm\.ssh -ErrorAction SilentlyContinue
|
||||||
|
|
||||||
|
# Pegar la clave pública del VPS en authorized_keys
|
||||||
|
# (copiar el contenido de id_rsa.pub del VPS)
|
||||||
|
Add-Content C:\Users\juanm\.ssh\authorized_keys "<PEGAR_CLAVE_PUBLICA_AQUI>"
|
||||||
|
```
|
||||||
|
|
||||||
|
3. **Verificar conectividad desde el VPS**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
ssh juanm@192.168.1.239 "echo 'Conexión OK'"
|
||||||
|
```
|
||||||
|
|
||||||
|
### Usar el Shutdown Listener
|
||||||
|
|
||||||
|
Desde cualquier lugar (Home Assistant, curl, etc.):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -X POST http://185.187.169.109:5555/shutdown \
|
||||||
|
-H "Authorization: Bearer H7iLGJixPp3J3pthCmnR2Ibq0tvERD5THyr_foAeN_8"
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🔐 Seguridad
|
||||||
|
|
||||||
|
### Variables de entorno sensibles
|
||||||
|
|
||||||
|
Los servicios usan variables de entorno para credenciales:
|
||||||
|
- `TELEGRAM_API_ID`
|
||||||
|
- `TELEGRAM_API_HASH`
|
||||||
|
- `TELEGRAM_BOT_TOKEN`
|
||||||
|
- `SHUTDOWN_TOKEN`
|
||||||
|
|
||||||
|
Estas están en `/etc/systemd/system/*.service` (solo accesible por root).
|
||||||
|
|
||||||
|
### Firewall
|
||||||
|
|
||||||
|
El Shutdown Listener escucha en el puerto **5555**. Asegúrate de:
|
||||||
|
- Permitir conexiones desde tu red local
|
||||||
|
- **NO** exponer públicamente (solo VPN o red interna)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📂 Ubicaciones de archivos
|
||||||
|
|
||||||
|
### En el VPS
|
||||||
|
|
||||||
|
| Archivo | Ubicación |
|
||||||
|
|---------|-----------|
|
||||||
|
| Script Telegram Watcher | `/opt/telegram_watcher/telegram_watcher.py` |
|
||||||
|
| Script Shutdown Listener | `/opt/shutdown_listener/shutdown_listener.py` |
|
||||||
|
| Servicio Telegram Watcher | `/etc/systemd/system/telegram-watcher.service` |
|
||||||
|
| Servicio Shutdown Listener | `/etc/systemd/system/shutdown-listener.service` |
|
||||||
|
| Log de mensajes | `/var/log/telegram_watcher/mensajes.log` |
|
||||||
|
| Script de configuración | `/root/configurar_servicios.sh` |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🚨 Troubleshooting
|
||||||
|
|
||||||
|
### El Telegram Watcher no arranca
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Ver logs
|
||||||
|
journalctl -u telegram-watcher -n 50
|
||||||
|
|
||||||
|
# Problemas comunes:
|
||||||
|
# 1. Credenciales incorrectas → verificar variables en el .service
|
||||||
|
# 2. Telethon no instalado → pip3 install telethon
|
||||||
|
# 3. Permisos del log → mkdir -p /var/log/telegram_watcher && chmod 755 /var/log/telegram_watcher
|
||||||
|
```
|
||||||
|
|
||||||
|
### El Shutdown Listener no puede conectar al PC
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Verificar conectividad SSH
|
||||||
|
ssh -i /root/.ssh/id_rsa juanm@192.168.1.239 "echo OK"
|
||||||
|
|
||||||
|
# Si falla:
|
||||||
|
# 1. Verificar que el PC está encendido y en la red
|
||||||
|
# 2. Verificar IP del PC (puede haber cambiado)
|
||||||
|
# 3. Verificar que OpenSSH Server está corriendo en el PC
|
||||||
|
# 4. Verificar que la clave pública está en C:\Users\juanm\.ssh\authorized_keys
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📝 Notas
|
||||||
|
|
||||||
|
1. **Sesión de Telegram**: El watcher usa el BOT_TOKEN (no sesión personal) para evitar el problema de `AuthKeyDuplicatedError`.
|
||||||
|
|
||||||
|
2. **Logs**: Los mensajes se guardan tanto en journald como en `/var/log/telegram_watcher/mensajes.log`.
|
||||||
|
|
||||||
|
3. **Reinicio automático**: Ambos servicios se reinician automáticamente si fallan (configurado en systemd).
|
||||||
|
|
||||||
|
4. **IP del PC**: La IP `192.168.1.239` está hardcodeada. Si cambia, actualizar en `/etc/systemd/system/shutdown-listener.service`.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## ✅ Checklist de migración
|
||||||
|
|
||||||
|
- [x] Cerrar procesos locales (Telegram Watcher, Shutdown Listener, Recordatorios Msgbox)
|
||||||
|
- [x] Eliminar tareas programadas de Windows
|
||||||
|
- [x] Crear scripts adaptados para VPS
|
||||||
|
- [x] Copiar archivos al VPS
|
||||||
|
- [x] Crear servicios systemd
|
||||||
|
- [ ] **Ejecutar `/root/configurar_servicios.sh` en el VPS**
|
||||||
|
- [ ] Configurar SSH en el PC Windows
|
||||||
|
- [ ] Copiar clave pública del VPS al PC
|
||||||
|
- [ ] Probar shutdown remoto
|
||||||
|
- [ ] Verificar que los logs se generan correctamente
|
||||||
|
- [ ] Actualizar AGENTS.md con la nueva configuración
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**Última actualización:** 29 Sep 2026
|
||||||
80
vps/configurar_servicios_vps.sh
Normal file
80
vps/configurar_servicios_vps.sh
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# configurar_servicios_vps.sh — Configurar servicios en el VPS
|
||||||
|
# Este script debe ejecutarse EN EL VPS como root
|
||||||
|
|
||||||
|
echo "================================"
|
||||||
|
echo "Configuración de servicios VPS"
|
||||||
|
echo "================================"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Solicitar credenciales
|
||||||
|
read -p "TELEGRAM_API_ID: " TELEGRAM_API_ID
|
||||||
|
read -p "TELEGRAM_API_HASH: " TELEGRAM_API_HASH
|
||||||
|
read -p "TELEGRAM_BOT_TOKEN: " TELEGRAM_BOT_TOKEN
|
||||||
|
read -p "SHUTDOWN_TOKEN [presiona Enter para usar el actual]: " SHUTDOWN_TOKEN
|
||||||
|
|
||||||
|
# Usar token actual si no se proporciona uno nuevo
|
||||||
|
if [ -z "$SHUTDOWN_TOKEN" ]; then
|
||||||
|
SHUTDOWN_TOKEN="H7iLGJixPp3J3pthCmnR2Ibq0tvERD5THyr_foAeN_8"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "Actualizando servicios con las credenciales..."
|
||||||
|
|
||||||
|
# Actualizar telegram-watcher.service
|
||||||
|
sed -i "s|Environment=TELEGRAM_API_ID=.*|Environment=TELEGRAM_API_ID=$TELEGRAM_API_ID|" /etc/systemd/system/telegram-watcher.service
|
||||||
|
sed -i "s|Environment=TELEGRAM_API_HASH=.*|Environment=TELEGRAM_API_HASH=$TELEGRAM_API_HASH|" /etc/systemd/system/telegram-watcher.service
|
||||||
|
sed -i "s|Environment=TELEGRAM_BOT_TOKEN=.*|Environment=TELEGRAM_BOT_TOKEN=$TELEGRAM_BOT_TOKEN|" /etc/systemd/system/telegram-watcher.service
|
||||||
|
|
||||||
|
# Actualizar shutdown-listener.service
|
||||||
|
sed -i "s|Environment=SHUTDOWN_TOKEN=.*|Environment=SHUTDOWN_TOKEN=$SHUTDOWN_TOKEN|" /etc/systemd/system/shutdown-listener.service
|
||||||
|
|
||||||
|
# Instalar dependencias Python
|
||||||
|
echo ""
|
||||||
|
echo "Instalando dependencias..."
|
||||||
|
pip3 install telethon flask python-dotenv
|
||||||
|
|
||||||
|
# Crear directorio de logs
|
||||||
|
mkdir -p /var/log/telegram_watcher
|
||||||
|
chmod 755 /var/log/telegram_watcher
|
||||||
|
|
||||||
|
# Dar permisos de ejecución
|
||||||
|
chmod +x /opt/telegram_watcher/telegram_watcher.py
|
||||||
|
chmod +x /opt/shutdown_listener/shutdown_listener.py
|
||||||
|
|
||||||
|
# Recargar systemd
|
||||||
|
echo ""
|
||||||
|
echo "Recargando systemd..."
|
||||||
|
systemctl daemon-reload
|
||||||
|
|
||||||
|
# Habilitar servicios
|
||||||
|
echo "Habilitando servicios..."
|
||||||
|
systemctl enable telegram-watcher.service
|
||||||
|
systemctl enable shutdown-listener.service
|
||||||
|
|
||||||
|
# Iniciar servicios
|
||||||
|
echo "Iniciando servicios..."
|
||||||
|
systemctl start telegram-watcher.service
|
||||||
|
systemctl start shutdown-listener.service
|
||||||
|
|
||||||
|
# Mostrar estado
|
||||||
|
echo ""
|
||||||
|
echo "================================"
|
||||||
|
echo "Estado de los servicios:"
|
||||||
|
echo "================================"
|
||||||
|
systemctl status telegram-watcher.service --no-pager
|
||||||
|
echo ""
|
||||||
|
systemctl status shutdown-listener.service --no-pager
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "================================"
|
||||||
|
echo "Configuración completada"
|
||||||
|
echo "================================"
|
||||||
|
echo ""
|
||||||
|
echo "Para ver logs en tiempo real:"
|
||||||
|
echo " journalctl -u telegram-watcher -f"
|
||||||
|
echo " journalctl -u shutdown-listener -f"
|
||||||
|
echo ""
|
||||||
|
echo "Log de mensajes de Telegram:"
|
||||||
|
echo " tail -f /var/log/telegram_watcher/mensajes.log"
|
||||||
|
echo ""
|
||||||
Reference in New Issue
Block a user