Hetzner Migration Plan (WIP)
Relevant source files
The following files were used as context for generating this wiki page:
The Hetzner Migration Plan (Work In Progress) outlines the strategy for transitioning the GentelmeN-CorE (GeNCorE) bot infrastructure from its current Railway-based deployment to a self-hosted or dedicated environment on Hetzner. This move is designed to handle the bot's complex requirements, including persistent database connections, background price monitoring threads, and integration with multiple external APIs like Groq, KuCoin, and Hugging Face.
Currently, the system relies on Railway's RAILPACK builder and V2 runtime, utilizing a single replica with an ON_FAILURE restart policy. The migration aims to maintain the bot's core functionality—AI-driven chat, cryptocurrency alerting, and image generation—while potentially improving reliability and reducing deployment constraints observed in the current environment.
Sources: railway.json:1-15, core/bot.py:65-71
Current Infrastructure Overview
The existing architecture is built on a Python-based Telegram bot framework (pyTelegramBotAPI) that integrates various services. It employs a PostgreSQL database for persisting user preferences and price alerts.
System Components
The following diagram illustrates the current interactions between the bot core and external services:
The bot initializes by loading environment variables for API keys and database connection strings, then starts a dedicated price_monitor thread to track market movements.
Sources: core/bot.py:10-40, core/commands.py:1-20, requirements.txt:1-6
Database Schema and Persistence
The migration must account for the migration of the PostgreSQL database. The current schema consists of two primary tables managed via psycopg2.
| Table | Description | Key Fields |
|---|---|---|
users | Stores user-specific settings and identity. | user_id (PK), language, model_name |
alerts | Stores active cryptocurrency price notifications. | id (PK), user_id, symbol, target_price, direction |
Sources: core/database.py:15-37
Database Initialization Logic
The bot performs an "init-on-startup" check to ensure tables exist:
CREATE TABLE IF NOT EXISTS users (
user_id BIGINT PRIMARY KEY,
username TEXT,
language TEXT DEFAULT 'EN',
model_name TEXT DEFAULT 'llama-3.3-70b-versatile',
joined_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
Sources: core/database.py:19-27
Background Processes and Threading
A critical component of the migration is the price_monitor function, which runs as a daemon thread. This monitor polls KuCoin every 60 seconds for all symbols present in the alerts table.
When migrating to Hetzner, the environment must support persistent background threading and stable outbound network connections for frequent API polling.
Sources: core/bot.py:42-80
Environment Configuration
The following environment variables are mandatory for the system to function and must be securely transferred during the migration:
| Variable | Usage | Source |
|---|---|---|
TELEGRAM_TOKEN | Bot authentication with Telegram | core/bot.py:14 |
GROQ_KEY | Access to Llama and Qwen models | core/bot.py:15 |
DATABASE_URL | PostgreSQL connection string | core/bot.py:16 |
ADMIN_ID | Restricted command access (e.g., balance) | core/commands.py:12 |
KUCOIN_API_KEY | Exchange integration credentials | core/bot.py:27 |
Migration Challenges and Considerations
- Process Management: The current
railway.jsonhandles restarts. On Hetzner, a process manager likesystemdorDockerwill be required to handle thebot.infinity_pollingloop and potential crashes. - Startup Delay: The code currently includes a
time.sleep(15)to wait for "old Railway processes" to close. This may need adjustment or removal for a dedicated Hetzner VPS environment. - Database Migration: Since the database is defined via
DATABASE_URL, a managed database or a local PostgreSQL instance on the Hetzner server must be provisioned.
Sources: core/bot.py:73-86, railway.json:6-14
Conclusion
The Hetzner Migration Plan (WIP) focuses on transitioning the GeNCorE bot from a managed PaaS to a more flexible hosting environment. By documenting the current dependencies on background threading, specific PostgreSQL schemas, and various AI/Finance APIs, the project ensures that the migration will preserve the high-availability requirements of the price monitoring system and the interactive AI capabilities.