I have a Python daemon running on my Ubuntu 20.04 server. The daemon performs as a telegram bot which sends requests to the telegram server every the other second in a loop.
My daemon configuration telebot.service
is as bellow:
[Unit]
Description=my telegram bot
[Service]
WorkingDirectory=/etc/telebot/dev
Environment=PYTHONPATH=/etc/telebot/dev
ExecStart=/etc/telebot/dev/venv/bin/telebot.py
TimeoutStartSec=0
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=telebot
Restart=on-failure
[Install]
WantedBy=multi-user.target
Whenever an exception is thrown inside my python code the daemon will restart automatically and this is a very good option. I also can read the logs and see why the exception happened and debug if applicable.
Sometimes however my daemon freezes. And I have to perform a restart manually to bring it back to execution. I do it with systemctl restart telebot
.
Here I have two questions. Firstly in case of such freezes how one can investigate the issue? because there is no exception happened in the logs. How do I find out what is causing this?
Secondly, Does systemd provide and option to auto restart a freezing daemon? If not, are there any complementary tools which can do this?