Skip to content

Latest commit

 

History

History
210 lines (147 loc) · 4.66 KB

readme.md

File metadata and controls

210 lines (147 loc) · 4.66 KB

ServerManagerBot

ServerManagerBot is a Telegram bot designed for managing Hetzner servers. With this bot, administrators can effortlessly control server operations such as listing servers, powering them on or off, rebooting, and resetting passwords—all through Telegram.

Table of Contents

Features

  • Manage Hetzner servers directly via Telegram.
  • Power servers on/off, reboot, and delete them.
  • Support for Docker on multiple platforms (Linux/amd64, Linux/arm64).
  • Robust error handling for both Hetzner API and bot operations.

Requirements

  • Python 3.11
  • Hetzner API Token
  • Telegram Bot Token
  • Docker and Docker Compose

Getting Started

1. Setting Up the Server

Step 1.1: Update the Server

Ensure your server is up to date by running:

sudo apt update && sudo apt upgrade -y

Step 1.2: Install Docker

If Docker isn't already installed, set it up with:

curl -fsSL https://get.docker.com | sh

2. Clone the Repository

Clone the ServerManagerBot repository and navigate to the project directory:

git clone https://github.com/erfjab/ServerManagerBot.git
cd ServerManagerBot

3. Configure the Bot

Step 3.1: Copy the Example Configuration

Copy the example configuration file to create a new configuration file:

cp data/.info.json.example data/.info.json

Step 3.2: Edit the Configuration

Open the data/.info.json file and insert your Telegram Bot Token and Hetzner API keys:

nano data/.info.json

Replace the placeholders with your information:

{
  "TELEGRAM_BOT_TOKEN": "your-telegram-bot-token",
  "TELEGRAM_BOT_ADMINS": {
    "admin_chat_id": "hetzner_api_token"
  }
}
  • TELEGRAM_BOT_TOKEN: Get this from Telegram BotFather.
  • TELEGRAM_BOT_ADMINS: Map your Telegram chat IDs to their Hetzner API tokens. Your chat_id is your Telegram user ID.

Tip

Click here for instructions on generating a Hetzner API token.

4. Docker Setup

Step 4.1: Docker Compose Configuration

Ensure your docker-compose.yml is set up like this:

services:
  ServerManagerBot:
    image: erfjab/ServerManagerBot:latest
    restart: always
    volumes:
      - ./data/:/code/data/

Step 4.2: Build and Run the Bot with Docker

  1. Pull the latest Docker image:

    docker compose pull
  2. Start the bot:

    docker compose up -d
  3. Verify the bot is running:

    docker compose ps

This command lists the running containers.

Updating the Bot

To update the bot to the latest version:

  1. Pull the latest Docker image:

    docker compose pull
  2. Restart the bot:

    docker compose up -d

Managing the Bot with Docker

Restart the bot:

docker compose restart

Stop the bot:

docker compose down

View logs:

To check real-time logs of the bot:

docker compose logs -f

Bot Usage

  • Start a chat with the bot on Telegram.
  • Use the /start command to view a list of your Hetzner servers.
  • Execute actions such as powering on/off, rebooting, and resetting passwords.

Error Handling

The bot includes comprehensive error handling for:

  • Hetzner API issues.
  • Connection problems.
  • Invalid user inputs.

All errors are logged and can be monitored using Docker logs.

What's Next?

  • Show Servers List
  • Display Full Server Info
  • Power On Servers
  • Power Off Servers
  • Perform Reset (Power Cycle)
  • Reset Root Password
  • Delete Servers
  • Rebuild (all images)
  • Reboot Servers
  • Provide Exclusive Access for Each Admin
  • Create New Servers
  • Set Server Limits for Admins
  • Implement Dedicated Proxies for Access
  • Change Server IP
  • Manage Server IP Types (Add/Delete)

Contact

Feel free to ⭐ the project to show your support!

Stargazers over time