- in Python script, make sure include
#!/path/to/venv/python
in the first line - add a systemd service
$ sudo systemctl edit --force --full name.service
. In the editor complete at least these statments,
[Unit]
Description=Python Service
Wants=network.target
After=network.target
[Service]
ExecStartPre=/bin/sleep 10
ExecStart=/path/to/bot.py
Restart=always
[Install]
WantedBy=multi-user.target
- enable the systemd service,
sudo systemctl enable name.service
and start the servicesudo systemctl start name.service