Initial Codex Telegram admin bot

This commit is contained in:
2026-07-09 14:02:14 +02:00
commit 997ff20703
13 changed files with 953 additions and 0 deletions

View File

@@ -0,0 +1,16 @@
[Unit]
Description=Codex Server Admin Telegram Bot
After=network-online.target
Wants=network-online.target
[Service]
Type=simple
User=root
WorkingDirectory=/opt/codex-tg-bot
EnvironmentFile=/etc/codex-tg-bot/.env
ExecStart=/opt/codex-tg-bot/venv/bin/python -m bot.main
Restart=on-failure
RestartSec=5
[Install]
WantedBy=multi-user.target

54
deploy/install.sh Normal file
View File

@@ -0,0 +1,54 @@
#!/usr/bin/env bash
# Installs the Codex Server Admin Telegram Bot as a systemd service.
# Run as root on the target Linux server, from the project root:
# sudo bash deploy/install.sh
set -euo pipefail
INSTALL_DIR=/opt/codex-tg-bot
CONFIG_DIR=/etc/codex-tg-bot
SERVICE_NAME=codex-tg-bot
PROJECT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
if [[ $EUID -ne 0 ]]; then
echo "ERROR: run as root (sudo bash deploy/install.sh)" >&2
exit 1
fi
echo "==> Checking prerequisites"
if ! command -v python3 >/dev/null; then
echo "ERROR: python3 not found. Install it, for example: apt install python3 python3-venv" >&2
exit 1
fi
echo "==> Copying project to $INSTALL_DIR"
mkdir -p "$INSTALL_DIR"
cp -r "$PROJECT_DIR/bot" "$PROJECT_DIR/requirements.txt" "$INSTALL_DIR/"
echo "==> Creating virtualenv and installing dependencies"
if [[ ! -d "$INSTALL_DIR/venv" ]]; then
python3 -m venv "$INSTALL_DIR/venv"
fi
"$INSTALL_DIR/venv/bin/pip" install --upgrade pip -q
"$INSTALL_DIR/venv/bin/pip" install -r "$INSTALL_DIR/requirements.txt" -q
echo "==> Setting up config in $CONFIG_DIR"
mkdir -p "$CONFIG_DIR"
if [[ ! -f "$CONFIG_DIR/.env" ]]; then
cp "$PROJECT_DIR/.env.example" "$CONFIG_DIR/.env"
chmod 600 "$CONFIG_DIR/.env"
echo ""
echo "!! Created $CONFIG_DIR/.env from template."
echo "!! Fill in TELEGRAM_API_ID, TELEGRAM_API_HASH, TELEGRAM_BOT_TOKEN, ADMIN_IDS,"
echo "!! then run: systemctl restart $SERVICE_NAME"
echo ""
fi
echo "==> Installing systemd service"
cp "$PROJECT_DIR/deploy/$SERVICE_NAME.service" "/etc/systemd/system/$SERVICE_NAME.service"
systemctl daemon-reload
systemctl enable --now "$SERVICE_NAME"
echo "==> Done"
systemctl --no-pager status "$SERVICE_NAME" || true
echo ""
echo "Logs: journalctl -u $SERVICE_NAME -f"