| 1 |
#!/bin/shscip-shell filesystem . . `/bin/sh`. |
| 2 |
|
| 3 |
. "${PM_FUNCTIONS}" |
| 4 |
|
| 5 |
LOGPATH=/var/log/atopscip-shell filesystem . . `/var/log/atop`. |
| 6 |
BINPATH=/usr/binscip-shell filesystem . . `/usr/bin`. |
| •7 |
PIDFILE=/run/atop.pidscip-shell filesystem . . `/run/atop.pid`. |
| 8 |
INTERVAL=600 # interval 10 minutes |
| 9 |
CURDAY=`datescip-shell system . . date. +%Y%m%d` # current date in same format |
| 10 |
|
| 11 |
# If the system suspends, one final sample will be taken for the logfile |
| 12 |
# |
| 13 |
suspend_atopscip-shell shell shell-project 0.0.0 suspend_atop().() |
| 14 |
{ |
| 15 |
if [scip-shell system . . `[`. -e $PIDFILE ] && psscip-shell system . . ps. -p `catscip-shell system . . cat. $PIDFILE` | grepscip-shell system . . grep. 'atop$' > /dev/nullscip-shell filesystem . . `/dev/null`. |
| 16 |
then |
| 17 |
killscip-shell system . . kill. -USR2 `catscip-shell system . . cat. $PIDFILE` # final sample and terminate |
| 18 |
|
| 19 |
CNT=0 |
| 20 |
|
| 21 |
while psscip-shell system . . ps. -p `catscip-shell system . . cat. $PIDFILE` > /dev/nullscip-shell filesystem . . `/dev/null`. |
| 22 |
do |
| 23 |
let CNT+=1 |
| 24 |
|
| 25 |
if [scip-shell system . . `[`. $CNT -gt 5 ] |
| 26 |
then |
| 27 |
break; |
| 28 |
fi |
| 29 |
|
| 30 |
sleepscip-shell system . . sleep. 1 |
| 31 |
done |
| 32 |
fi |
| 33 |
} |
| 34 |
|
| 35 |
# If the system resumes, a new atop will be started (similar to boot) |
| 36 |
# |
| 37 |
resume_atopscip-shell shell shell-project 0.0.0 resume_atop().() |
| 38 |
{ |
| 39 |
# in case atop is running, stop it |
| 40 |
# |
| 41 |
if [scip-shell system . . `[`. -e $PIDFILE ] && psscip-shell system . . ps. -p `catscip-shell system . . cat. $PIDFILE` | grepscip-shell system . . grep. 'atop$' > /dev/nullscip-shell filesystem . . `/dev/null`. |
| 42 |
then |
| 43 |
killscip-shell system . . kill. -TERM `catscip-shell system . . cat. $PIDFILE` |
| 44 |
rmscip-shell system . . rm. $PIDFILE |
| 45 |
sleepscip-shell system . . sleep. 1 |
| 46 |
fi |
| 47 |
|
| 48 |
# start atop |
| 49 |
# |
| 50 |
$BINPATH/atop -R -w $LOGPATH/atop_$CURDAY $INTERVAL \ |
| 51 |
> $LOGPATH/daily.log 2>&1 & |
| 52 |
echoscip-shell system . . echo. $! > $PIDFILE |
| 53 |
|
| 54 |
# delete logfiles older than four weeks |
| 55 |
# |
| 56 |
( |
| 57 |
sleepscip-shell system . . sleep. 3; |
| 58 |
findscip-shell system . . find. $LOGPATH -name 'atop_*' -mtime +28 -exec rm {} \; |
| 59 |
)& |
| 60 |
|
| 61 |
exit 0 |
| 62 |
} |
| 63 |
|
| 64 |
case "$1" in |
| 65 |
hibernate|suspend) |
| 66 |
suspend_atopscip-shell shell shell-project 0.0.0 suspend_atop(). |
| 67 |
;; |
| 68 |
thaw|resume) |
| 69 |
resume_atopscip-shell shell shell-project 0.0.0 resume_atop(). |
| 70 |
;; |
| 71 |
*) exit $NA |
| 72 |
;; |
| 73 |
esac |