How to run Python bot as a service in Ubuntu Linux?

I like building Python bots. Especially for telegram – I think this messenger is very relevant and convenient. All the time of development, debugging and working process of the bots was been on my home server with Windows OS.
But I live and work in Ukraine and fucking russian invaders destroys the energy infrastructure of the country. My UPS is enough for 8 hours of server and network equipment operation in a situation when electricity is down. But I would prefer to spend this charge for other purposes.
I have a great VPS on which I decided to move my bots to. So what is needed for this?

See also  How to create telegram bot with Aiogram and Finite State Machine

Create your virtual environment in work folder:

python3 -m venv venv
source venv/bin/activate

Create or upload your script


Create startup bash script:


with this content:

cd /home/Bot
source venv/bin/activate

Make in executable:

chmod +x /home/Bot/

Create service file:

nano /lib/systemd/system/Bot.service

with this content:

Description=My Bot
[email protected]

ExecStart=/bin/bash /home/Bot/


And run commands:

systemctl daemon-reload
systemctl enable Bot.service 
systemctl start Bot.service 
systemctl status Bot.service




Author: admin

1 thought on “How to run Python bot as a service in Ubuntu Linux?

Leave a Reply

Your email address will not be published. Required fields are marked *