Клонирование репозитория
git clone https://github.com/extremeORG/TelegramBot.git
Перейти в папку:
cd TelegramBot
Создать виртуальное окружение:
python -m venv .venvАктивировать виртуальное окружение (linux):
source .venv/bin/activate
Установить все зависимости:
pip install -r requirements.txtСоздать файл .env (пример ниже):
TOKEN = ""
ADMIN_ID = ["0", "1"]
SERVER_NAME="Ubuntu Server"
Создание без домашней директории:
sudo adduser serverbot --system --group --no-create-home --shell /binДобавление в группу sudo:
sudo usermod -aG sudo serverbotСоздайте файл /etc/sudoers.d/bot
sudo visudo -f /etc/sudoers.d/bot
Добавьте строку:
serverbot ALL=(ALL) NOPASSWD: /bin/systemctl, /sbin/reboot, /usr/bin/apt
sudo nano /etc/systemd/system/server-bot.service[Unit]
Description=Telegram Server Bot
After=network.target
[Service]
Type=simple
User=serverbot
Group=serverbot
WorkingDirectory=/root/TelegramBot
ExecStart=/root/TelegramBot/.venv/bin/python3 /root/TelegramBot/bot.py
Restart=always
RestartSec=15
EnviromentFile=/root/TelegramBot/.env
[Install]
WantedBy=multi-user.target
sudo systemctl enable server-bot
sudo systemctl start server-bot
sudo systemctl status server-bot