This script is for scheduling server restarts on 3D printers running OctoPrint on a raspberry pi. It utilizes the OctoPrint API so it will not restart if a print is running or the printer is disconnected. It does attempt to reconnect once.
- Clone the script to your pi
cd /home/pi/
git clone https://github.com/dorfman2/nightly_octopi_restart.git
- Navigate inside the folder
cd nightly_octopi_restart/
-
Using an editor of your choice, fill in your API key and IP address into the config.py file.
-
Make the script executable
chmod +x restart_print_check.py
-
Create/Edit your root user crontab
-
Type
sudo crontab -e
and press enter. -
If this is your first time editing crontab, select option '1.'
-
Add this line to the end of the file. By default it runs at 2 am.
0 2 * * * /home/pi/nightly_octopi_restart/restart_print_check.py >> /home/pi/nightly_octopi_restart/restart_cron.log 2>&1
- Press CTRL S and then CTRL X.
More information about how to use cron can be found here.
I find this tool to be incredibly useful for helping to change
- Type into terminal
env -i /bin/bash --noprofile --norc
and press enter. - Then paste this and press enter.
/home/pi/nightly_octopi_restart/restart_print_check.py >> /home/pi/nightly_octopi_restart/restart_cron.log 2>&1
- If the Pi restarts, your script has correct permissions and is in the correct location.
- If not, check
restart_cron.log
.