gzenux / asuswrt-rtn18u

The UNOFFICIAL Asuswrt-Merlin ONLY for ASUS RT-N18U router.
https://gzenux.github.io/asuswrt-rtn18u
Other
62 stars 13 forks source link

syslog.log filling up router - not rotating #61

Open dieskim opened 1 year ago

dieskim commented 1 year ago

Hi, firstly thanks for you long term work and support for this router.

I am having an issue on my router where it does not seem to rotate the syslog.log file, this file then grows until the router gets filled up. I believe the log should be rotate at a certain size as I am seeing this happen on another router running Asus Merlin.

See current output from my router:

admin@RT-N18U-40AC:/tmp/home/root# ls -alh /tmp/syslog.log
-rw-r--r--    1 admin    root       36.7M Sep 27 10:14 /tmp/syslog.log

Is this a bug or something I can fix on my side?

I am running 386.3 so maybe if I upgrade to 386.3.1 it might fix it?

dieskim commented 1 year ago

I belive this is due to the rtn18u using rsyslogd and not syslogd

The Asus firmware runs syslogd with a logrotation enabled while nothing is currently set up to logrotate with rsyslogd

See: https://github.com/gzenux/asuswrt-rtn18u/blob/26b0f4b2c91b71fd34f6fb817005579f37173ab5/release/src/router/rc/services.c#L4204

We would need to do something like this: https://www.rsyslog.com/doc/master/tutorials/log_rotation_fix_size.html

gzenux commented 1 year ago

Hi dieskim, you are right. The rsyslog seems to not configure properly in current firmware and I will try to fix this problem.

You might need to manually remove /jffs/syslog.log if it gets a large file.

dieskim commented 1 year ago

Is there any way to just switch to syslogd or is that not possible? Since that would not need any additional scripts as rsyslog does.

If you don’t mind me asking, when do you think you would be able to work on this fix? If it’s going to be a while I will need to write my own script to rotate the logs for now.

dieskim commented 1 year ago

FYI to anyone else who needs a fix for this for now, I added an services-start user script with the following, this rotates the logs on reboot, saving the last 10k lines.

#!/bin/sh
logger "services-start" "startup"

# check if rsyslogd - clear and rotate logs
logger "services-start" "check if rsyslogd installed"
if type rsyslogd &> /dev/null
then  
    logger "services-start" "rsyslogd installed - rotating syslog"

    # clear jffs logs
    > /jffs/syslog.log
    > /jffs/syslog.log-1

    # move last 10k lines to from /tmp/syslog.log to /tmp/syslog.log-1
    tail -n 10000 /tmp/syslog.log > /tmp/syslog.log-1

    # clear /tmp/syslog.log
    > /tmp/syslog.log
fi
gzenux commented 1 year ago

I can apply the log rotation solution by using built-in output channels feature in rsyslog now.

Please see the preview patch, based on tag rtn18u_386.3_1, if someone would like to double check this solution before the next release.