Add uv support, systemd service, and deployment tooling
- pyproject.toml: uv-native project definition (replaces requirements.txt for uv users) - requirements.txt: kept for pip compatibility - deploy/jigaido-bot.service: systemd service file (copy to /etc/systemd/system/) - deploy/setup.sh: automated deployment script - README.md: updated with uv instructions, tmux, and systemd setup
This commit is contained in:
@@ -6,24 +6,85 @@ A Telegram bot for managing and tracking bounties in groups and DMs.
|
||||
|
||||
```bash
|
||||
cd apps/telegram-bot
|
||||
|
||||
# Install uv (if not already installed)
|
||||
curl -LsSf https://astral.sh/uv/install.sh | sh
|
||||
|
||||
# Copy and edit environment
|
||||
cp .env.example .env
|
||||
# Edit .env and add your bot token
|
||||
pip install -r requirements.txt
|
||||
# Add your bot token to .env: JIGAIDO_BOT_TOKEN="your:token"
|
||||
|
||||
# Install dependencies and run
|
||||
uv sync # creates .venv/, installs deps
|
||||
uv run python bot.py # runs the bot
|
||||
```
|
||||
|
||||
## Run
|
||||
## Running in Background
|
||||
|
||||
### Option 1: tmux (quick, survives SSH disconnect)
|
||||
|
||||
```bash
|
||||
python bot.py
|
||||
tmux new -s jigaido
|
||||
uv run python bot.py
|
||||
# Press Ctrl+B, then D to detach (bot keeps running)
|
||||
|
||||
// Later:
|
||||
tmux attach -t jigaido
|
||||
```
|
||||
|
||||
### Option 2: systemd (production, auto-restart, boot on startup)
|
||||
|
||||
```bash
|
||||
# Edit the service file paths first
|
||||
nano deploy/jigaido-bot.service
|
||||
# Change /home/shoko/repositories/jigaido to your actual path
|
||||
|
||||
# Install
|
||||
sudo cp deploy/jigaido-bot.service /etc/systemd/system/
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl enable jigaido-bot
|
||||
sudo systemctl start jigaido-bot
|
||||
|
||||
# Useful commands:
|
||||
sudo systemctl status jigaido-bot
|
||||
sudo systemctl restart jigaido-bot
|
||||
sudo systemctl stop jigaido-bot
|
||||
journalctl -u jigaido-bot -f # tail logs
|
||||
```
|
||||
|
||||
Or use the automated setup script:
|
||||
```bash
|
||||
export JIGAIDO_BOT_TOKEN="your:token"
|
||||
bash deploy/setup.sh
|
||||
```
|
||||
|
||||
## Reminders
|
||||
|
||||
Schedule a daily cron job:
|
||||
Schedule a daily cron job for due date notifications:
|
||||
|
||||
```bash
|
||||
# crontab -e
|
||||
0 9 * * * cd /path/to/jigaido/apps/telegram-bot && JIGAIDO_BOT_TOKEN="..." python cron.py
|
||||
# crontab -e — run at 9am daily
|
||||
0 9 * * * cd /path/to/jigaido/apps/telegram-bot && JIGAIDO_BOT_TOKEN="your:token" uv run python cron.py
|
||||
```
|
||||
|
||||
## Project Structure
|
||||
|
||||
```
|
||||
apps/telegram-bot/
|
||||
├── bot.py # Bot entrypoint
|
||||
├── commands.py # Command handlers
|
||||
├── cron.py # Daily reminder job
|
||||
├── db.py # SQLite database wrapper
|
||||
├── schema.sql # Database schema
|
||||
├── pyproject.toml # uv project definition
|
||||
├── .env.example # Environment template
|
||||
├── deploy/
|
||||
│ ├── jigaido-bot.service # systemd service
|
||||
│ └── setup.sh # Automated setup script
|
||||
└── tests/
|
||||
├── conftest.py # Test fixtures
|
||||
├── test_db.py # Database tests
|
||||
└── test_commands.py # Command/parsing tests
|
||||
```
|
||||
|
||||
## Commands
|
||||
|
||||
30
apps/telegram-bot/deploy/jigaido-bot.service
Normal file
30
apps/telegram-bot/deploy/jigaido-bot.service
Normal file
@@ -0,0 +1,30 @@
|
||||
[Unit]
|
||||
Description=JIGAIDO Telegram Bot
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
# Run as the user who owns the repo. Change USER and GROUP as needed.
|
||||
User=shoko
|
||||
Group=shoko
|
||||
|
||||
# Path to this app directory
|
||||
WorkingDirectory=/home/shoko/repositories/jigaido/apps/telegram-bot
|
||||
|
||||
# Load environment from .env in the WorkingDirectory
|
||||
EnvironmentFile=/home/shoko/repositories/jigaido/apps/telegram-bot/.env
|
||||
|
||||
# Start jigaido using uv. Change the path to uv if needed (e.g. /home/user/.local/bin/uv).
|
||||
# If uv is not in PATH, use the full path: ExecStart=/home/shoko/.local/bin/uv run python bot.py
|
||||
ExecStart=/usr/local/bin/uv run python bot.py
|
||||
|
||||
# Restart on crash, wait 5s before restarting
|
||||
Restart=always
|
||||
RestartSec=5
|
||||
|
||||
# Logging
|
||||
StandardOutput=append:/home/shoko/repositories/jigaido/apps/telegram-bot/bot.log
|
||||
StandardError=append:/home/shoko/repositories/jigaido/apps/telegram-bot/bot.log
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
56
apps/telegram-bot/deploy/setup.sh
Normal file
56
apps/telegram-bot/deploy/setup.sh
Normal file
@@ -0,0 +1,56 @@
|
||||
#!/bin/bash
|
||||
# JIGAIDO Telegram Bot — Deployment setup script
|
||||
# Run once on a fresh server to set everything up.
|
||||
|
||||
set -e
|
||||
|
||||
BOT_DIR="/home/shoko/repositories/jigaido/apps/telegram-bot"
|
||||
SERVICE_NAME="jigaido-bot"
|
||||
SERVICE_FILE="$BOT_DIR/deploy/$SERVICE_NAME.service"
|
||||
SYSTEMD_DIR="/etc/systemd/system"
|
||||
|
||||
echo "=== JIGAIDO Bot Setup ==="
|
||||
|
||||
# 1. Check for uv
|
||||
if ! command -v uv &> /dev/null; then
|
||||
echo "Installing uv..."
|
||||
curl -LsSf https://astral.sh/uv/install.sh | sh
|
||||
export PATH="$HOME/.local/bin:$PATH"
|
||||
fi
|
||||
|
||||
# 2. Check for bot token
|
||||
if [ -z "$JIGAIDO_BOT_TOKEN" ]; then
|
||||
echo "ERROR: JIGAIDO_BOT_TOKEN is not set."
|
||||
echo "Get a token from @BotFather on Telegram, then run:"
|
||||
echo " export JIGAIDO_BOT_TOKEN='your:token'"
|
||||
echo " $0"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 3. Create .env from example if it doesn't exist
|
||||
if [ ! -f "$BOT_DIR/.env" ]; then
|
||||
cp "$BOT_DIR/.env.example" "$BOT_DIR/.env"
|
||||
echo "Created .env — edit it and add your JIGAIDO_BOT_TOKEN"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 4. Install dependencies (uv creates venv automatically)
|
||||
cd "$BOT_DIR"
|
||||
uv sync
|
||||
|
||||
# 5. Install systemd service
|
||||
echo "Installing systemd service..."
|
||||
sudo cp "$SERVICE_FILE" "$SYSTEMD_DIR/"
|
||||
sudo sed -i "s|/home/shoko/repositories/jigaido|$BOT_DIR|g" "$SYSTEMD_DIR/$SERVICE_NAME.service"
|
||||
|
||||
# 6. Reload systemd, enable and start
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl enable "$SERVICE_NAME"
|
||||
sudo systemctl start "$SERVICE_NAME"
|
||||
|
||||
echo ""
|
||||
echo "=== Done ==="
|
||||
echo "Bot is running. Check status with: sudo systemctl status $SERVICE_NAME"
|
||||
echo "View logs with: journalctl -u $SERVICE_NAME -f"
|
||||
echo "Stop with: sudo systemctl stop $SERVICE_NAME"
|
||||
echo "Restart with: sudo systemctl restart $SERVICE_NAME"
|
||||
22
apps/telegram-bot/pyproject.toml
Normal file
22
apps/telegram-bot/pyproject.toml
Normal file
@@ -0,0 +1,22 @@
|
||||
[project]
|
||||
name = "jigaido-telegram-bot"
|
||||
version = "0.1.0"
|
||||
description = "Telegram bounty tracker for JIGAIDO"
|
||||
requires-python = ">=3.10"
|
||||
dependencies = [
|
||||
"python-telegram-bot>=21.6",
|
||||
"dateparser>=1.2.0",
|
||||
]
|
||||
|
||||
[project.optional-dependencies]
|
||||
dev = [
|
||||
"pytest>=8.3.5",
|
||||
"pytest-asyncio>=0.25.2",
|
||||
]
|
||||
|
||||
[tool.pytest.ini_options]
|
||||
testpaths = ["tests"]
|
||||
python_files = ["test_*.py"]
|
||||
python_classes = ["Test*"]
|
||||
python_functions = ["test_*"]
|
||||
asyncio_mode = "auto"
|
||||
@@ -1,2 +1,4 @@
|
||||
python-telegram-bot==21.6
|
||||
dateparser==1.2.0
|
||||
# For pip users (pip install -r requirements.txt)
|
||||
# For uv users: uv sync (reads pyproject.toml)
|
||||
python-telegram-bot>=21.6
|
||||
dateparser>=1.2.0
|
||||
|
||||
Reference in New Issue
Block a user