diff --git a/app/sbin/api b/app/sbin/api index bc96db0..fc2c015 100755 --- a/app/sbin/api +++ b/app/sbin/api @@ -501,7 +501,7 @@ async def get_odoo_log_summary(uuid: str): # --- Main logic --- try: # Last 500 lines from Odoo log - last_500_lines = read_last_lines(odoo_log_file, 500) + last_500_lines = read_last_lines(odoo_log_file, 5000) important_odoo_lines = [ line for line in last_500_lines if is_important_line(line) ] diff --git a/app/sbin/rotateLogs b/app/sbin/rotateLogs index ad9f48f..89f279e 100755 --- a/app/sbin/rotateLogs +++ b/app/sbin/rotateLogs @@ -1,8 +1,21 @@ #!/bin/bash # rotateLogs — rotate odoo.log for all UUID containers, keep 4 weeks +# Runs as a daemon: waits for midnight, rotates, then waits for next midnight RETENTION_DAYS=28 +wait_for_midnight() { + NOW=$(date +%s) + MIDNIGHT=$(date -d 'tomorrow 00:00' +%s 2>/dev/null || \ + date -d "$(date -d tomorrow '+%Y-%m-%d') 00:00:00" +%s) + SLEEP=$(( MIDNIGHT - NOW )) + echo "Waiting ${SLEEP}s until midnight..." + sleep "$SLEEP" +} + +while true; do + wait_for_midnight + for log in /4server/data/00*/logs/odoo.log; do [[ -f "$log" ]] || continue DIR=$(dirname "$log") @@ -28,3 +41,5 @@ for log in /4server/data/00*/logs/odoo.log; do find "$DIR" -name 'odoo.log.*.gz' -mtime +$RETENTION_DAYS -exec rm -f {} \; \ -exec echo "$UUID deleted: {}" \; done + +done diff --git a/app/templates/init.d/rotateLogs b/app/templates/init.d/rotateLogs new file mode 100644 index 0000000..a9de1fd --- /dev/null +++ b/app/templates/init.d/rotateLogs @@ -0,0 +1,22 @@ +#!/sbin/openrc-run + +name="rotateLogs" +description="Daily Odoo log rotation" + +pidfile="/run/${RC_SVCNAME}.pid" +output_log="/4server/data/log/rotateLogs.log" +error_log="/4server/data/log/rotateLogs.log" + +command="/4server/sbin/rotateLogs" +command_background="yes" + +stop() { + ebegin "Stopping rotateLogs" + start-stop-daemon --stop --pidfile "$pidfile" + eend $? +} + +depend() { + need localmount + after bootmisc +} diff --git a/app/update b/app/update index 5595d66..f29d46e 100755 --- a/app/update +++ b/app/update @@ -68,6 +68,13 @@ rex doas chown root:root /etc/init.d/cleanTmp rex doas rc-update add cleanTmp default rex doas rc-service cleanTmp restart +#INSTALL rotateLogs SERVICE +template templates/init.d/rotateLogs /etc/init.d/rotateLogs +rex doas chmod 0755 /etc/init.d/rotateLogs +rex doas chown root:root /etc/init.d/rotateLogs +rex doas rc-update add rotateLogs default +rex doas rc-service rotateLogs restart + #INSTALL cpu service template templates/init.d/cpu /etc/init.d/cpu rex doas chmod 0755 /etc/init.d/cpu