diff --git a/casaos.yaml b/casaos.yaml index 1699907..fedc864 100644 --- a/casaos.yaml +++ b/casaos.yaml @@ -7,7 +7,12 @@ services: deploy: resources: limits: - memory: 15922M + memory: 512M + reservations: + devices: [] + dns: + - 8.8.8.8 + - 1.1.1.1 environment: - ADMIN_PASSWORD=MiPo6425@@ - ADMIN_USERNAME=nickpons666 @@ -23,93 +28,18 @@ services: - TELEGRAM_TOKEN=8469229183:AAEVIV5e7rjDXKNgFTX0dnCW6JWB88X4p2I - WEB_HOST=0.0.0.0 - WEB_PORT=8000 + - PYTHONDONTWRITEBYTECODE=1 + - PYTHONOPTIMIZE=1 + - TZ=America/Mexico_City + - REDIS_HOST=10.10.4.17 + - REDIS_PORT=6379 + - REDIS_PASSWORD=translation_redis_secret + - REDIS_DB=0 hostname: bots-translation - image: registry-pons.duckdns.org/bots-translation:v1 - dns: - - 8.8.8.8 - - 1.1.1.1 + image: registry-pons.duckdns.org/bots-translation:latest labels: icon: https://www.ruthlessreviews.com/wp-content/uploads/2025/12/last-war-image.jpg ports: - target: 8000 published: "8091" - protocol: tcp - restart: unless-stopped - volumes: - - type: bind - source: /DATA/AppData/bots-translation/data - target: /app/data - - type: bind - source: /DATA/AppData/bots-translation/data/logs - target: /app/data/logs - x-casaos: - envs: - - container: DISCORD_TOKEN - description: - en_us: Token del bot de Discord - - container: TELEGRAM_TOKEN - description: - en_us: Token del bot de Telegram - - container: LIBRETRANSLATE_URL - description: - en_us: URL de LibreTranslate - - container: ADMIN_USERNAME - description: - en_us: Usuario admin del panel - - container: ADMIN_PASSWORD - description: - en_us: Contraseña admin del panel - - container: DB_TYPE - description: - en_us: Tipo de base de datos (sqlite/mysql) - - container: DB_HOST - description: - en_us: Host de MySQL - - container: DB_PORT - description: - en_us: Puerto de MySQL - - container: DB_USER - description: - en_us: Usuario de MySQL - - container: DB_PASSWORD - description: - en_us: Contraseña de MySQL - - container: DB_NAME - description: - en_us: Nombre de la base de datos MySQL - - container: DATABASE_PATH - description: - en_us: Ruta de la base de datos SQLite (si DB_TYPE=sqlite) - ports: - - container: "8000" - description: - en_us: Puerto del panel web - volumes: - - container: /app/data - description: - en_us: Datos de los bots y base de datos - devices: [] - cap_add: [] - network_mode: bridge - privileged: false -x-casaos: - architectures: - - amd64 - author: nickpons666 - category: Utility - description: - en_us: Bots de traducción para Discord y Telegram con panel web - developer: nickpons666 - hostname: "" - icon: https://www.ruthlessreviews.com/wp-content/uploads/2025/12/last-war-image.jpg - index: / - is_uncontrolled: false - main: bots-translation - port_map: "8091" - scheme: http - store_app_id: bots-translation - tagline: - en_us: Bots de Traducción - title: - custom: "" - en_us: Bots de Traducción + protocol: tcp \ No newline at end of file diff --git a/iniciar_todo.py b/iniciar_todo.py index 9e3bd45..000fa96 100755 --- a/iniciar_todo.py +++ b/iniciar_todo.py @@ -37,13 +37,29 @@ def start_process(cmd, name, delay_before=0): log(f"✅ Iniciando {name}...") log_path = f"{LOG_DIR}/{name.lower().replace(' ', '_')}.log" - with open(log_path, "a") as f: - p = subprocess.Popen( - cmd, - stdout=f, - stderr=subprocess.STDOUT, - preexec_fn=os.setsid - ) + log_fd = open(log_path, "a") + + # stdout va al archivo Y a la consola del contenedor (Docker logs) + p = subprocess.Popen( + cmd, + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT, + preexec_fn=os.setsid + ) + + # Hilo que redirige la salida del proceso al archivo + consola + import threading + def tee_output(proc, fd, label): + for line in iter(proc.stdout.readline, b''): + decoded = line.decode("utf-8", errors="replace") + fd.write(decoded) + fd.flush() + print(f"[{label}] {decoded}", end="", flush=True) + fd.close() + + t = threading.Thread(target=tee_output, args=(p, log_fd, name), daemon=True) + t.start() + processes.append((p, name)) return p diff --git a/utils/logger.py b/utils/logger.py index 6fd7c22..b0e59fb 100644 --- a/utils/logger.py +++ b/utils/logger.py @@ -6,8 +6,10 @@ import logging import os from logging.handlers import TimedRotatingFileHandler -# Directorio base para almacenar los logs -LOG_DIR = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "logs") +# Directorio base para almacenar los logs (respeta el volumen de Docker /app/data) +_DEFAULT_LOG_DIR = "/app/data/logs" +_LOCAL_LOG_DIR = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "logs") +LOG_DIR = _DEFAULT_LOG_DIR if os.path.exists("/app/data") else _LOCAL_LOG_DIR os.makedirs(LOG_DIR, exist_ok=True) def _create_logger(name: str, filename: str, level=logging.INFO) -> logging.Logger: