That is the same problem for many applications on linux. Ex, tomcat
web server creates a catalina.log
which can grow to GBs in size.
The solution doesn’t need the program/webapp “fixed” but to leverage the Linux system utility called logrotate
.
Logrotate is with every linux distro. This config should work for WebControl and Raspberry Pi OS but likely needs specifics adjusted. Here’s an example that should work.
If you’re comfortable with the commandline, you can do the following:
sudo -i # become the root user
vi /etc/logrotate.d/webcontrol
# if you don't know Vi, use what works for your root user edits like 'nano'
# paste in the following, then save & exit
/home/pi/.WebControl/alog.txt
{
missingok
notifempty
copytruncate
weekly
maxage 30
maxsize 100M
rotate 4
su pi pi
}
/home/pi/.WebControl/log.txt
{
missingok
notifempty
copytruncate
weekly
maxage 30
maxsize 100M
rotate 4
su pi pi
}
# /home/pi/.WebControl/param-examples
# {
# missingok # no error if missing
# notifempty # if empty no need to rotate
# copytruncate # maintain orig file if open by copying content to the
# # rotated logthen zeros out orig file. could be a
# # performance hit if WebControl is sensitive to hiccups
# # (due to weak Pi CPUs like OG Zero W with one core
# # vs Zero 2 W or newer having 4 cores.)
# weekly # regardless of size, rotate weekly
# maxage 30 # regardless of size, 30 days max each -- helpful if unused
# maxsize 100M # rotate once file reaches this size
# rotate 4 # keep only 4 rotation
# su pi pi # not being root user owned, use the file's user and group
# }
Please adjust according as I have not used WebControl yet. The numbers will depend on the size of storage and log sizes created per CNC run.
I have deliberately left off compression as that creates a CPU load burst which could cause hiccups for the CNC operation. Seeing folks are dealing with GB sized files, the maxsize
& rotate count
will suffice. I wouldn’t use maxsize 1G
with rotate 4
as you have two log rotating yielding 8G of space used. It would be better to use maxsize 100M
and adjust your rotate count
for more.
Check for typos and errors:
logrotate -d /etc/logrotate.d/webcontrol
If good, when logrotates crontab entry kicks in, it will do what it does best. But being the root user, you can run it early.
logrotate -v /etc/logrotate.d/webcontrol
# using -v verbose to see all the gritty details
My plug for Alpine Linux (& PostmarketOS) vs Raspberry Pi OS
I’ll likely try to get WebControl working on Alpine Linux for myself with a similar logrotate config. It’s been a moment since I’ve run Raspberry Pi OS.
Alpine Linux is super small (100MB’s base install), very lightweight (no systemd & extra services in the background, no GUI by default), and security focused. That should mean less hiccups for even the “Potato” Pi (OG Zero, RPi 1 & 2) running WebControl – I wouldn’t though as I’ll want 4 cores in a Zero 2 W or better.
If I have a cycle I might even create a post on how to setup Alpine Linux for Pi with WebControl once I’ve refined it.
If curious, there’s even another Alpine-based distro that is “user friendly” focused call PostmarketOS having a lightweight Desktop UI for those folks using a display - Raspberry Pi - postmarketOS . Again, being headless, PostmarketOS would be best for you to tryout Alpine in a friendly way.