root@kvmubuntu:~# ls /home/tuser/dato38itbot/
main.py requirements.txt telegaenv
root@kvmubuntu:~# vim /etc/systemd/system/dato38itbot.service
root@kvmubuntu:~# cat /etc/systemd/system/dato38itbot.service
[Unit]
Description=Telegram bot
After=network.target
[Service]
ExecStart=/usr/bin/python3 /home/tuser/dato38itbot/main.py
[Install]
WantedBy=multi-user.target
[Install]
WantedBy=multi-user.target
root@kvmubuntu:~# systemctl daemon-reload
root@kvmubuntu:~# systemctl enable dato38itbot.service
Created symlink /etc/systemd/system/multi-user.target.wants/dato38itbot.service → /etc/systemd/system/dato38itbot.service.
root@kvmubuntu:~# systemctl start dato38itbot.service
root@kvmubuntu:~# systemctl status dato38itbot.service
× dato38itbot.service - Telegram bot
Loaded: loaded (/etc/systemd/system/dato38itbot.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Tue 2024-09-03 15:09:34 MSK; 4s ago
Process: 3848 ExecStart=/usr/bin/python3 /home/tuser/dato38itbot/main.py (code=exited, status=1/FAILURE)
Main PID: 3848 (code=exited, status=1/FAILURE)
CPU: 127ms
Sep 03 15:09:33 kvmubuntu.net systemd[1]: Started Telegram bot.
Sep 03 15:09:34 kvmubuntu.net python3[3848]: Traceback (most recent call last):
Sep 03 15:09:34 kvmubuntu.net python3[3848]: File "/home/tuser/dato38itbot/main.py", line 1, in <module>
Sep 03 15:09:34 kvmubuntu.net python3[3848]: import psycopg2
Sep 03 15:09:34 kvmubuntu.net python3[3848]: ModuleNotFoundError: No module named 'psycopg2'
Sep 03 15:09:34 kvmubuntu.net systemd[1]: dato38itbot.service: Main process exited, code=exited, status=1/FAILURE
Sep 03 15:09:34 kvmubuntu.net systemd[1]: dato38itbot.service: Failed with result 'exit-code'.
[Unit]
Description=Bot
After=syslog.target
After=network.target
[Service]
Type=simple
User=dato
WorkingDirectory=/home/tuser/dato38itbo
ExecStart=/usr/bin/python3 /home/tuser/dato38itbot/main.py
Restart=always
[Install]
WantedBy=multi-user.target
[Unit]
Description=Telegram dato38it-bot
After=network.target
[Service]
User=tuser
Group=tuser
WorkingDirectory=/home/tuser/dato38itbot/
VIRTUAL_ENV=/home/tuser/dato38itbot/telegaenv
Environment=PATH=$VIRTUAL_ENV/bin:$PATH
ExecStart=/home/tuser/dato38itbot/telegaenv/bin/python /home/tuser/dato38itbot/main.py
Restart=on-failure
[Install]
WantedBy=multi-user.target