{"id":15197144,"url":"https://github.com/madebyadem/linux-server-telegram-bot","last_synced_at":"2026-01-04T10:09:35.827Z","repository":{"id":250218295,"uuid":"833827797","full_name":"MadeByAdem/Linux-server-Telegram-bot","owner":"MadeByAdem","description":"A Telegram bot that monitors and controls a Linux server. It will send notifications to the administrator and actively tries to restore services and containers.","archived":false,"fork":false,"pushed_at":"2024-09-12T06:49:13.000Z","size":496,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-02T21:43:19.264Z","etag":null,"topics":["bash","linux","python","raspberrypi","telegram"],"latest_commit_sha":null,"homepage":"https://madebyadem.dev","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MadeByAdem.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-07-25T20:51:23.000Z","updated_at":"2024-12-16T07:45:51.000Z","dependencies_parsed_at":"2024-07-25T23:43:41.360Z","dependency_job_id":"a773291d-b358-4c95-a1f9-364656b63144","html_url":"https://github.com/MadeByAdem/Linux-server-Telegram-bot","commit_stats":null,"previous_names":["madebyadem/linux-server-telegram-bot"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MadeByAdem%2FLinux-server-Telegram-bot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MadeByAdem%2FLinux-server-Telegram-bot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MadeByAdem%2FLinux-server-Telegram-bot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MadeByAdem%2FLinux-server-Telegram-bot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MadeByAdem","download_url":"https://codeload.github.com/MadeByAdem/Linux-server-Telegram-bot/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241577072,"owners_count":19984940,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bash","linux","python","raspberrypi","telegram"],"created_at":"2024-09-28T00:43:12.637Z","updated_at":"2026-01-04T10:09:35.818Z","avatar_url":"https://github.com/MadeByAdem.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Linux server Telegram bot\nThis is a bot that lets you control your Linux server using a Telegram bot. I've tested it on Ubuntu 22.04, 22.10 and Raspberry Pi 5, but I'm pretty sure that it will work on any Linux server. The main use case is monitoring critical processes like Docker containers and services you have running on a server. But you can also manually perform some actions on your Linux server. The bot has a menu to choose what you want to do.\n\nIt consists of two services: a monitoring service which will check several parameters, and a bot which allows you to control your Linux server.\n\nIt's ideal if you have a single server running, with certain custom services and/or containerized applications and you want to be able to control them on the fly, and having them monitored in an easy way.\n\n## Features\n\n### Monitoring (runs every 5 minutes)\n- Check CPU usage\n- Check memory usage\n- Check disk usage\n- Check temperature\n- Check Docker containers\n- Check services\n- Ping some servers or websites\n- Tries to restart services and docker containers if they fail\n- Sends notifications when something happens\n\n### Bot\n- Wake up a Wake on LAN device if in the same network (requires a device supporting Wake on LAN, and etherwake)\n- Manually check services\n- Start, stop or restart services\n- Manually check Docker containers\n- Start, stop or restart Docker containers\n- Check certain logs\n- Send custom commands to server\n- Check system information (stress test option requires stress-ng on the server)\n- Reboot the server\n\n\u003ccenter\u003e\u003cimg src=\"./example.jpg\" alt=\"Example Linux Telegram Bot\" width=\"300px\"\u003e\u003c/center\u003e\n\n## Table of Contents\n1. [Linux server Telegram bot](#linux-server-telegram-bot)\n2. [Features](#features)\n   - [Monitoring (runs every 5 minutes)](#monitoring-runs-every-5-minutes)\n   - [Bot](#bot)\n3. [Setup](#setup)\n   - [Prerequisites](#prerequisites)\n   - [Installation](#installation)\n     - [Clone the repository](#clone-the-repository)\n     - [Create virtual environment for monitoring](#create-virtual-environment-for-monitoring)\n     - [Create virtual environment for bot](#create-virtual-environment-for-bot)\n     - [Setup environment variables](#setup-environment-variables)\n     - [Setting up the Systemd service](#setting-up-the-systemd-service)\n     - [Modify text files](#modify-text-files)\n     - [Start services](#start-services)\n4. [Usage](#usage)\n   - [Monitoring](#monitoring)\n   - [Bot](#bot-1)\n5. [Contributing](#contributing)\n6. [License](#license)\n\n\n## Setup\n\n### Prerequisites\n- A Linux server (Raspberry Pi, Ubuntu, etc)\n- A Telegram bot token. You can get one by creating a bot through the [BotFather](https://core.telegram.org/bots#botfather).\n- Python3 installed on the server.\n- The function to check servers/websites uses netcat, so you need to install netcat on the server.\n- If you want to make use of the Wake On Lan feature, you need to install etherwake.\n- If you want to use the stress test feature, you need to install stress-ng.\n\n*Important:* The bot needs admin privileges to use certain features.\n\n**Install etherwake and stress-ng**\n\n```bash\nsudo apt update\nsudo apt install etherwake stress-ng netcat-traditional\n```\n\n### Installation\n\n1. **Clone the repository**\n    ```bash\n    git clone https://github.com/MadeByAdem/Linux-server-Telegram-bot\n    cd Linux-server-Telegram-bot\n    ```\n\n2. **Create virtual environment for monitoring**\n    ```bash\n    cd linux_bot\n    python -m venv venv\n    source venv/bin/activate  # On Windows, use `venv\\Scripts\\activate`\n    ```\n\n    Install the required packages for the linux_bot:\n\n    ```bash\n    pip install -r requirements.txt\n    ```\n\n    Deactivate the virtual environment:\n\n    ```bash\n    deactivate\n    ```\n\n3. **Create virtual environment for bot**\n    ```bash\n    cd linux_monitoring\n    python -m venv venv\n    source venv/bin/activate  # On Windows, use `venv\\Scripts\\activate`\n    ```\n\n    Install the required packages for the linux_bot:\n\n    ```bash\n    pip install -r requirements.txt\n    ```\n\n    Deactivate the virtual environment:\n\n    ```bash\n    deactivate\n    ```\n\n4. **Setup environment variables**\n    Copy the `.env.example` file to `.env` and change the variables with your variables. \n    ```bash\n    cp .env.example .env\n    ```   \n    You can obtain your Telegram chatID by chatting with the Telegram bot @RawDataBot on https://t.me/raw_data_bot. Modify the *main.py* if you add more than one user. Just copy paste the CHAT_ID_PERSON1 variable and add more CHAT_ID_PERSON2, CHAT_ID_PERSON3, etc. Add these users to the ALLOWED_USERS list in the main.py of linux_bot and linux_monitoring.\n\n    You can obtain your Telegram bot token by creating a bot on https://t.me/BotFather\n\n5. **Setting up the Systemd service**\n    Modify the service files:\n\n    Update the `linux_bot.service` file with your actual paths:\n    ```ini\n    [Unit]\n    Description=Linux Bot\n    After=network.target\n\n    [Service]\n    ExecStart=/your/path/to/linux_bot/venv/bin/python /your/path/to/linux_bot/main.py\n    WorkingDirectory=/your/path/to/linux_bot\n    User=root\n    Restart=always\n\n    [Install]\n    WantedBy=multi-user.target\n    ```\n\n    Update the `linux_monitoring.service` file with your actual paths:\n    ```ini\n    [Unit]\n    Description=Linux Monitoring\n    After=network.target\n\n    [Service]\n    ExecStart=/your/path/to/linux_monitoring/venv/bin/python /your/path/to/linux_monitoring/main.py\n    WorkingDirectory=/your/path/to/linux_monitoring\n    User=root\n    Restart=always\n\n    [Install]\n    WantedBy=multi-user.target\n    ```\n\n    Copy the service files to the `/etc/systemd/system/` folder:\n\n    ```bash\n    cp linux_bot.service /etc/systemd/system/\n    cp linux_monitoring.service /etc/systemd/system/\n    ```\n\n6. **Modify text files**\n    The linux_bot directory has three text files:\n    - `bot_logfiles.txt` \\\n        Copy and paste all the paths to the logs on separate lines if you want to have access to them through the bot.\n    - `bot_servers.txt`\n        Set all the servers you want to ping on separate lines if you want to be able to ping them through the bot. (Format: name=ipaddress:port) You can also put websites here, but don't use http or https. Use port 80 or 443. eg.: Some URL=some-website.dev:443 \n    - `bot_services.txt`\n        List all the services you want to check by their names on separate lines if you want to be able to check them through the bot.\n\n    The linux_monitoring directory has three text files:\n    - `monitoring_containers.txt`\n        List all the containers you want to check by their names on separate lines if you want the bot to monitor them.\n    - `monitoring_servers.txt`\n        Set all the servers you want to ping on separate lines if you want the bot to monitor them. You can also put websites here. Use port 80.\n    - `monitoring_services.txt`\n        List all the services you want to check by their names on separate lines if you want the bot to monitor them.\n\n        **Important:** The bot needs admin privileges to use certain features.\n\n        **Tip:** Add the linux_bot to the `monitoring_services.txt` so that the bot can monitor it as well.\n\n7. **Start services**\n    ```bash\n    sudo systemctl daemon-reload\n    sudo systemctl enable linux_monitoring.service\n    sudo systemctl enable linux_bot.service\n    sudo systemctl start linux_bot.service\n    sudo systemctl start linux_monitoring.service\n    ```\n\n## Usage\n\n### Monitoring\nThe monitoring service will check all the listed services, servers, containers and certain system info every 5 minutes. When a service or container is down, it will try to restart it. It will inform you when this happens and the restart was successful.\n\nIt will inform you if the server you listed is online (ping) or not. If not, it will try again within 2 minutes. If the server still did not respond it will tell you so.\n\nIt will notify you if your CPU, memory usage, disk usage or temperature is high.\n\n### Bot\nSend /menu and you will get a menu with all the options:\n- menu - Show the menu\n- start - Start the bot\n\nTo use the WoL option, you need to install etherwake on your server\n\nTo use the stress test option, you need to install stress-ng on your server\n\n## Contributing\nFeel free to submit issues or pull requests if you have suggestions for improvements or new features. Please follow the existing coding style.\n\n## License\nThis project is licensed under the Custom License. See the [LICENSE](LICENSE) file for more details.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmadebyadem%2Flinux-server-telegram-bot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmadebyadem%2Flinux-server-telegram-bot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmadebyadem%2Flinux-server-telegram-bot/lists"}