I have a python3 script called bot.py which is running a simple (for now) telegram bot, and I can retrieve some PI system states.
It's required to maintain the bot online, so I added next string to
/etc/rc.local:
sudo bash /home/pi/piBoxBot/bash/bot_run.sh &
It runs ~/piBoxBot/bash/bot_run.sh:
#!/bin/sh
sudo python3 /home/pi/piBoxBot/py/bot.py;
.sh made executable, bot gets up on startup, everything is going fine, works as expected. I noticed that bot just stops after about 8 hours, time after time.
My goal is to have online 24/7. It looks like either a python runtime limitations or raspbian(bash) limits, seems that there is a little option to adjust somewhere. Didn't successfully google the solution, so will be appreciate for any advice.
Thanks in advance.
-
2I have a Python script which has been running for about 6 months without restarting - there's no runtime limit I'm aware of. Your problem probably lies elsewhere. Perhaps if you run it from the console, or capture its stout and stderr, and wait for it to go wrong, you'll get some idea what's happening.Mark Smith– Mark Smith2019年01月23日 09:23:17 +00:00Commented Jan 23, 2019 at 9:23
1 Answer 1
Please take note that using /etc/rc.local
has limitations due to Compatibility with SysV. Following the recommendation of the developers from systemd you should avoid using it. So that should be the first step if you have problems. Use a systemd unit to start your program. Create a new service with:
rpi ~$ sudo systemctl --force --full edit bot.service
In the editor insert these statements, save them and quit the editor:
[Unit]
Description=Telegram Bot
After=multi-user.target
[Service]
WorkingDirectory=/home/pi/piBoxBot/py/
ExecStart=/usr/bin/python3 /home/pi/piBoxBot/py/bot.py
[Install]
WantedBy=multi-user.target
Don't forget to clean up /etc/rc.local
. Enable the service and reboot:
rpi ~$ sudo systemctl enable bot.service
rpi ~$ sudo systemctl reboot
After reboot look at the status with:
rpi ~$ systemctl status bot.service
Tell us if it fails aber 8 houres.