File: 45atoppm

package info (click to toggle)
atop 2.4.0-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 1,692 kB
  • sloc: ansic: 20,731; python: 253; sh: 220; makefile: 170
file content (73 lines) | stat: -rwxr-xr-x 1,182 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/bin/sh

. "${PM_FUNCTIONS}"

LOGPATH=/var/log/atop
BINPATH=/usr/bin
PIDFILE=/run/atop.pid
INTERVAL=600		# interval 10 minutes
CURDAY=`date +%Y%m%d`	# current date in same format

# If the system suspends, one final sample will be taken for the logfile
#
suspend_atop()
{
	if [ -e $PIDFILE ] && ps -p `cat $PIDFILE` | grep 'atop$' > /dev/null
	then
		kill -USR2 `cat $PIDFILE`	# final sample and terminate

		CNT=0

		while ps -p `cat $PIDFILE` > /dev/null
		do
			let CNT+=1

			if [ $CNT -gt 5 ]
			then
				break;
			fi

			sleep 1
		done
	fi
}

# If the system resumes, a new atop will be started (similar to boot)
#
resume_atop()
{
	# in case atop is running, stop it
	#
	if [ -e $PIDFILE ] && ps -p `cat $PIDFILE` | grep 'atop$' > /dev/null
	then
		kill -TERM `cat $PIDFILE`
		rm $PIDFILE
		sleep 1
	fi

	# start atop
	#
	$BINPATH/atop -R -w $LOGPATH/atop_$CURDAY $INTERVAL \
					 > $LOGPATH/daily.log 2>&1 &
	echo $! > $PIDFILE
	
	# delete logfiles older than four weeks
	#
	(
	 	sleep 3;
		find $LOGPATH -name 'atop_*' -mtime +28 -exec rm {} \;
	)&

	exit 0
}

case "$1" in
	hibernate|suspend)
		suspend_atop
		;;
	thaw|resume)
		resume_atop
		;;
	*) 	exit $NA
		;;
esac