---
title: MardisBot
description: Telegram bot for Mardis group
host: tg_bots-vm
status: active
last_reviewed: 2026-09-12
owner: gmikcon
confidence: 100
review_interval: 90
source_of_truth: live_system
---

# MardisBot

Telegram bot for the Mardis group.

> **STATUS 2026-09-12: ACTIVE** on VM `tg_bots` (192.168.1.254, libvirt VM on
> hypervisor bserv 192.168.1.130). Verified live via SSH: process running
> since 2026-08-13, systemd service active.
>
> **Naming warning:** there are TWO similarly named hosts. The bot lives on
> the **VM `tg_bots` (192.168.1.254, hostname `tgbots`)** — NOT on the
> external VPS `tgbots` (192.168.1.178, hostname `vmk`), which hosts only the
> marginator web stack. Earlier documentation wrongly placed the bot on the
> VPS; after the VPS was rebuilt ~2026-08-27 the bot was believed missing,
> but it had actually been (re)deployed to the VM.

## Live deployment (verified 2026-09-12)
- **Host**: VM `tg_bots`, 192.168.1.254 (libvirt on bserv, disk
  /mnt/main/vm_main/tg_bots, bridge br0, MAC 52:54:00:94:4b:e0)
- **User**: `ubuntu` (password in gnexus-creds secret "tgbots")
- **Project Path**: `/home/ubuntu/bots/MardisBot`
- **Main Script**: `bot.py` (venv: `/home/ubuntu/bots/MardisBot/venv`,
  Python 3.10)
- **Config**: `.env` in project dir (bot token, not documented here)
- **Dependencies**: python-telegram-bot[job-queue] 22.7, python-dotenv
  (requirements.txt)

## Poll schedule (changed 2026-09-12)
- Weekly training poll ("Хто буде на тренуванні?") is sent
  **Wednesday and Friday at 19:00 Europe/Kyiv**.
- Implementation: `app.job_queue.run_daily(..., days=(3, 5),
  name="weekly_poll_wednesday_friday")` in `bot.py` (~line 174).
  PTB 22.7 day convention: **0 = Sunday … 6 = Saturday** (verified against
  the installed library source and its `_CRON_MAPPING`).
- Time is configured via `.env`: `POLL_HOUR=19`, `POLL_MINUTE=0`
  (defaults in code are 10:00 if unset).
- Before 2026-09-12 the poll ran Thursday+Saturday at 08:00 (env-driven).
- There is **no catch-up logic**: a poll is never sent on bot start/restart;
  missed slots are skipped silently.
- Startup `print` lines in `bot.py` state the configured time and days.

## systemd service
- **Service Name**: `mardisbot.service` — active (running), enabled
- **Unit File**: `/etc/systemd/system/mardisbot.service`
- **Unit change 2026-09-12**: added `Environment=PYTHONUNBUFFERED=1`
  (stdout was block-buffered under systemd, hiding startup logs in
  journalctl until process exit). Unit backup:
  `/home/ubuntu/backups/mardisbot.service.bak_20260912`.
- **Memory**: ~40 MB

### Service management
```bash
sudo systemctl status mardisbot.service
sudo journalctl -u mardisbot.service -f
sudo systemctl restart mardisbot.service
```

## Backups (2026-09-12)
- Full code+config backup before the schedule change:
  `/home/ubuntu/backups/MardisBot_backup_20260912_155039.tar.gz`
  (bot.py, .env, requirements.txt; venv excluded). Rollback: extract
  bot.py/.env from the archive, `sudo systemctl restart mardisbot.service`.

## Remote ops (added 2026-09-10, extended 2026-09-10)
The bot owner can manage this service remotely via the companion ops bot
**MardisOpsBot** (`@MardisOps_bot`) — see
`10-systems/bots/mardisopsbot.md`. Commands: `/status`, `/restart`,
`/logs [N]`, `/backup` (download current MardisBot code as ZIP), and
ZIP-upload update (send a .zip with bot.py to update the code on the VM —
auto-backup before apply, auto-rollback if the service fails after
restart; `.env` and `venv` are never touched). Access: first 3 Telegram
users who press /start (user_ids persisted in `admins.json` on the VM).
No SSH or inbound network access is required or granted.

## Health notes (2026-09-12)
- Occasional `telegram.error.NetworkError: Bad Gateway` in journal
  (transient Telegram API/network blips; network_retry_loop recovers
  automatically). No error handlers registered in bot.py — cosmetic only.
