Hello,
I use an RPI as my print server, RPI's are notorious for corrupting SD cards after just a single power failure.
I run all of my RPI's read-only, and recently I've configured a service, to manage octoprint serve on a RO root file system.
Assumes:
You already have a ReadOnly root file system setup on RPI SD card. If not you'll have to google how to get here, as I'm not going over that process.
3 files are created / edited,
New files:
- /etc/systemd/system/octoprinter.service
- /usr/bin/octoprint
Edited file
- /etc/fstab
New directory to save your last configuration before a safe shutdown
mkdir /home/pi/octoprint-lastshutdown
Create the script file
nano /usr/bin/octoprint
#!/bin/bash
ro() {
sudo mount -o remount,ro / ; sudo mount -o remount,ro /boot
}
rw() {
sudo mount -o remount,rw / ; sudo mount -o remount,rw /boot
}
start() {
rw
rsync -r /home/pi/octoprint-lastshutdown/ /home/pi/.octoprint
ro
octoprint daemon start
}
stop() {
# copies current runing file to backup.
octoprint daemon stop
rw
rsync -r /home/pi/.octoprint/ /home/pi/octoprint-lastshutdown
ro
}
case $1 in
start|stop) "$1" ;;
esac
Create the service
nano /etc/systemd/system/octoprinter.service
octoprinter.service file content
[Unit]
Description=Create RAM disk for octoprint service to run in
[Service]
ExecStart=/usr/bin/octoprint start
ExecStop=/usr/bin/octoprint stop
RemainAfterExit=yes
User=pi
[Install]
WantedBy=multi-user.target
Edit - Create RAM drive to run while in RO root
nano /etc/fstab
tmpfs /home/pi/.octoprint tmpfs nosuid,nodev,size=25120k 0 0
Last you just need to include your new service in systemctrl
systemctl enable octoprinter.service