[arm-allstar] memory issue

Doug Crompton wa3dsp at gmail.com
Fri Aug 3 09:03:59 EST 2018


Ken,

 The message file could grow on a system that is never rebooted and sees a
lot of use. I have had some servers not booted for a half year or more.
Usually the only reason to reboot is if there is a kernel change which we
had back a few months ago. Here is a script I have used to maintain any
file that can grow. It is usually the message file so this should suffice.

#!/bin/bash

# trimlog.sh
# Trim a logfile. Usually run by cron at specific interval
# created for use with Asterisk messages log
# Can be used with other program created logfiles.
# Do not use with journalctl logs

if [ -z "$1" ] || [ ! -f "$1" ]
  then
   echo -e "\nFilename missing or not specified\n"
   echo -e "trimlog <filename> <maxlines>\n"
   echo -e "maxlines defaults to 500 if not specified\n\n"
   exit 1
fi

if [ -z "$2" ]
 then
   maxlines=500
else
   maxlines=$2
fi

lines=`wc -l < $1`
if [ "$lines" -gt "$maxlines" ]
 then
   tail -$maxlines $1 > /tmp/tmpfile.txt
   cp /tmp/tmpfile.txt $1
   rm /tmp/tmpfile.txt
fi

echo  "$1 - Lines - $lines / Maxlines = $maxlines"
# end of script

Then in a cron I use -

10,25,40,55 * * * * /usr/local/sbin/trimlog.sh /var/log/asterisk/messages
1000


and here is another one that works on multiple files that I run on my hubs
or anything that is busy and uses html like supermon or lsnodes -

# ! /bin/bash

# Truncate selected logs
#
# D. Crompton 9/2015
#
# FILE= full path and file name
# maximumsize= maximum size in bytes
# text_truncate= text to echo and log if truncated
# text_ok= text to echo and log if size OK

function truncate_log {

actualsize=$(wc -c <"$FILE")
if [ $actualsize -ge $maximumsize ]; then

    tail -c $maximumsize $FILE > /tmp/out.tmp
    cp /tmp/out.tmp $FILE
    rm -rf /tmp/out.tmp
    echo $text_truncate
    logger $text_truncate
else
    echo $text_ok
    logger $text_ok
fi
}

FILE="/var/log/httpd/access_log"
maximumsize=300000
text_truncate="LOG - httpd access_log size adjusted"
text_ok="LOG - httpd access_log size OK"
truncate_log

FILE="/var/log/asterisk/messages"
maximumsize=300000
text_truncate="LOG - Asterisk message log size adjusted"
text_ok="LOG - Asterisk message log size OK"
truncate_log

FILE="/var/log/httpd/error_log"
maximumsize=20000
text_truncate="LOG - httpd error_log size adjusted"
text_ok="LOG - httpd error_log size OK"
truncate_log

#end script

And I use this once a day cron -

05 04 * * * /etc/asterisk/local/truncate_logs

This script truncates the log so the last defined x amount is still there.
I have had busy systems run for a very long time with no oversize files
using this script. Do a df  once and awhile and check.

That just happened to be where I put the file way back when. Neither of
these scripts are in the distribution but this last one might be worthwhile
putting in.


*73 Doug*

*WA3DSP*

*http://www.crompton.com/hamradio <http://www.crompton.com/hamradio>*




On Fri, Aug 3, 2018 at 8:19 AM, "Ken via arm-allstar" <
arm-allstar at hamvoip.org> wrote:

> We had one of our hamvoip units go into a semi-nonfunctional mode this week
> - discovered during our weekly net.
>
>
>
> I suspect it was related to the fact that the file system partitions allow
> for 53M of files in /var/log/ and we had the /var/log/asterisk/messages
> file
> grow to something larger than 50M.  Perhaps something else was going on,
> but
> no way to tell now.  This is with a release dated the end of May.
>
>
>
> Since the allocated space for "messages" is limited and the size of the
> "messages" file is (apparently) unlimited, there is an inherent potential
> for a problem.
>
>
>
> I think one solution could be a "logrotate" function that limits the total
> storage that can be consumed by this log file.
>
>
>
> We have updated to the latest release Asterisk
> 1.4.23-pre.hamvoip-V1.5.3-36-app_rpt-0.327-07/15/2018
>
>
>
>
>
> Ken
>
> KE2N
>
>
>
> _______________________________________________
>
> arm-allstar mailing list
> arm-allstar at hamvoip.org
> http://lists.hamvoip.org/cgi-bin/mailman/listinfo/arm-allstar
>
> Visit the BBB and RPi2/3 web page - http://hamvoip.org
>


More information about the arm-allstar mailing list