Skip to content

Commit

Permalink
Restoring Volumio Log Rotate Service
Browse files Browse the repository at this point in the history
  • Loading branch information
volumio committed Feb 1, 2024
1 parent f8baf7a commit b31d30e
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 0 deletions.
4 changes: 4 additions & 0 deletions scripts/volumio/configure.sh
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,8 @@ cp "${SRC}/volumio/etc/default/ifplugd" "${ROOTFS}/etc/default/ifplugd"
#TRIGGERHAPPY
cp "${SRC}/volumio/etc/triggerhappy/triggers.d/audio.conf" "${ROOTFS}/etc/triggerhappy/triggers.d/audio.conf"

#VOLUMIO LOG ROTATE
cp -rp "${SRC}/volumio/bin/volumiologrotate" "${ROOTFS}/bin/volumiologrotate"


log 'Done Copying Custom Volumio System Files' "okay"
3 changes: 3 additions & 0 deletions scripts/volumio/volumioconfig.sh
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,9 @@ ln -s /lib/systemd/system/volumiologrotate.service /etc/systemd/system/multi-use
log "Enable Volumio CPU Tweak Service"
ln -s /lib/systemd/system/volumio_cpu_tweak.service /etc/systemd/system/multi-user.target.wants/volumio_cpu_tweak.service

log "Enable Volumio Log Rotate Service"
ln -s /lib/systemd/system/volumiologrotate.service /etc/systemd/system/multi-user.target.wants/volumiologrotate.service

log "Disable MPD autostart"
systemctl disable mpd.service

Expand Down
37 changes: 37 additions & 0 deletions volumio/bin/volumiologrotate
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash

LOG_FOLDER=/var/log
MAX_TOTAL_LOG_SIZE=18000000

function clearLogs {
for LOG_FILE in $(find $LOG_FOLDER -type f);
do
SIZE=`ls -la "$LOG_FILE" | cut -d' ' -f 5 `
if [[ ${SIZE} -gt 0 ]];then
echo "Clearing $LOG_FILE"
echo "-------------- CLEARED LOG --------------" > $LOG_FILE
fi
done
}

function checkLogFilesTotalSize {
TOTAL_LOG_SIZE=0
for LOG_FILE in $(find $LOG_FOLDER -type f);
do
SIZE=`ls -la "$LOG_FILE" | cut -d' ' -f 5 `
if [[ ${SIZE} -gt 0 ]];then
TOTAL_LOG_SIZE=$((${TOTAL_LOG_SIZE}+${SIZE}))
fi
done

if [[ ${TOTAL_LOG_SIZE} -gt ${MAX_TOTAL_LOG_SIZE} ]];then
echo "Total log size is greater than 18MB, cleaning logs"
clearLogs
fi
}

while true
do
checkLogFilesTotalSize
sleep 60
done
15 changes: 15 additions & 0 deletions volumio/lib/systemd/system/volumiologrotate.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[Unit]
Description = Volumio Log Rotation Service

[Service]
ExecStart=/bin/volumiologrotate
Restart=always
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=volumiologrotate
User=root
Group=root

[Install]
WantedBy=multi-user.target

0 comments on commit b31d30e

Please sign in to comment.