derdide / telegram_multi_llm_bot

ChatBot to allow prompting of multiple LLMs in parallel, among other things
MIT License
0 stars 0 forks source link

Document how to deploy it as a service on Linux #11

Closed derdide closed 1 month ago

derdide commented 1 month ago

As this bot is supposed to run on a server, making it a service will allow to have it run permanently, and restarted after reboots or crashes. This is mostly (only?) a documentation question

derdide commented 1 month ago

This will allow the bot to run automatically on startup and restart if it crashes. Here's a step-by-step guide to achieve this:

  1. Create a systemd service file:

First, we'll create a service file for your bot. Let's call it telegrambot.service.

[Unit]
Description=Telegram Bot Service
After=network.target

[Service]
ExecStart=/usr/bin/python3 /home/pi/your_bot_script.py
WorkingDirectory=/home/pi
StandardOutput=inherit
StandardError=inherit
Restart=always
User=pi

[Install]
WantedBy=multi-user.target
  1. Save this file:

    sudo nano /etc/systemd/system/telegrambot.service

    Paste the content from the artifact above into this file, save and exit (Ctrl+X, then Y, then Enter).

  2. Modify the service file:

    • Replace /home/pi/your_bot_script.py with the actual path to your bot script.
    • If your bot isn't in the home directory, adjust the WorkingDirectory accordingly.
  3. Set the correct permissions:

    sudo chmod 644 /etc/systemd/system/telegrambot.service
  4. Reload systemd to recognize the new service:

    sudo systemctl daemon-reload
  5. Enable the service to start on boot:

    sudo systemctl enable telegrambot.service
  6. Start the service:

    sudo systemctl start telegrambot.service
  7. Check the status of your service:

    sudo systemctl status telegrambot.service

Now your bot should be running as a service. It will start automatically when your Raspberry Pi boots up, and it will restart if it crashes for any reason.

Additional commands that might be useful: