PageRenderTime 260ms CodeModel.GetById 257ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/logrotate.d/psaccs_atop

http://github.com/brinkman83/bashrc
#! | 42 lines | 39 code | 3 blank | 0 comment | 0 complexity | 354bf984e07dec33ef0832fe3ff6c3e0 MD5 | raw file
 1# Logrotate file to take action before psacct is rotated
 2/var/log/atop/dummy_before {
 3    missingok
 4    daily
 5    rotate 1
 6    ifempty
 7    create 0600 root root
 8    postrotate
 9	# check if process accounting is installed
10	#
11	if [ -e /etc/logrotate.d/psacct ]
12	then
13	    # check if process accounting is actually in use
14	    #
15	    ACCTFILE=`awk '$2 == "{" {print $1}' /etc/logrotate.d/psacct`
16
17	    if [ -f "$ACCTFILE" ]
18	    then
19	        ACCTSIZE1=`ls -l "$ACCTFILE" | awk '{print $5}'`
20	        ACCTSIZE2=`ls -l "$ACCTFILE" | awk '{print $5}'`
21
22	        if [ $ACCTSIZE1 -lt $ACCTSIZE2 ]
23	        then
24	            # stop atop daemon before accounting file
25	            # is rotated
26	            #
27	            PIDFILE=/var/run/atop.pid
28
29	            if [ -e $PIDFILE ] && \
30	                   ps -p `cat $PIDFILE` | grep 'atop$' > /dev/null
31	            then
32			kill -USR1 `cat $PIDFILE` # take final sample
33			sleep 3
34	                kill -TERM `cat $PIDFILE`
35	                rm $PIDFILE
36			sleep 1
37	            fi
38	        fi
39	    fi
40	fi
41    endscript
42}