A
A
Alex Fedorov2021-06-03 15:56:04
linux
Alex Fedorov, 2021-06-03 15:56:04

How to properly add a service to systemd with python bot on CentOS?

Hi all! During the holidays, I try to take my first steps in telegram bots. I want to run my bot on a virtual machine. I found a method to start a bot as a separate service in Linux, write a config file and get an error. The service does not start.

Here is the bot.service file config:

[Unit]
Description=Telegram bot 'TEST'
After=syslog.target
After=network.target

[Service]
Type=simple
User=root
WorkingDirectory=/root/Downloads/bot/
ExecStart=/root/Downloads/bot/env/bin /python3 /root/Downloads/bot/main.py
RestartSec=10
Restart=always

[Install]
WantedBy=multi-user.target



When you enter the systemctl status bot command, the following is output:

bot.service - Telegram bot 'TEST'
Loaded: loaded (/etc/systemd/system/bot.service; enabled; vendor preset: disabled)
Active: activating (auto-restart) (Result: exit-code) since Thu 2021- 06-03 22:51:09 +05; 651ms ago
Process: 9504 ExecStart=/root/Downloads/bot/env/bin/python3 /root/Downloads/bot/main.py (code=exited, status=1/FAILURE)
Main PID: 9504 (code=exited, status =1/FAILURE)


The project itself and its directories:

-rw-r--r--. 1 root root 1550 Jun 2 20:38 buttons.py
drwxr-xr-x. 2 root root 6 Jun 2 20:41 Documents ===>
drwxr-xr-x bot user data is stored here. 5 root root 74 Jun 3 22:21 env ===> set environment
-rw-r--r-- here. 1 root root 10835 Jun 2 20:36 main.py
-rw-r--r--. 1 root root 761 Jun 2 20:38 messages.py
drwxr-xr-x. 2 root root 38 Jun 2 21:12 __pycache__
-rw-r--r--. 1 root root 2496 Jun 2 20:39 registration.py
-rw-r--r--. 1 root root 2174 Jun 2 20:39 schedulled_msg.py
-rw-r--r--. 1 root root 478 Jun 2 20:39 states.py
-rw-r--r--. 1 root root 159 Jun 2 20:42 variables.py

Please help, what is the problem here. Sincerely.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question