File: atopacct.init

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 (90 lines) | stat: -rwxr-xr-x 1,786 bytes parent folder | download | duplicates (2)
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/bin/sh
#
# atopacctd	Startup script for the atopacctd daemon 
#
# chkconfig: 2345 91 9
# description: Process accounting control
#
### BEGIN INIT INFO
# Provides:             atopacct
# Required-Start:	$local_fs $remote_fs
# Required-Stop:	$local_fs $remote_fs
# Default-Start:	2 3 4 5
# Default-Stop:		0 1 6
# Description:          This daemon switches on process accounting and
#                       transfers the process accounting records 'realtime'
#                       to small shadow files to avoid huge disk space usage
# Short-Description:    Process accounting control
### END INIT INFO

. /lib/lsb/init-functions

# Check existance of binaries 
[ -f /usr/sbin/atopacctd ] || exit 0

RETVAL=0

# See how we were called.
case "$1" in
  start)
	# Check if process accounting already in use via psacct
	#
	for PACCTFILE in /var/account/pacct /var/log/pacct
	do
		if [ -f "$PACCTFILE" ]	# file exists?
		then
			BEFORSIZE=$(ls -lL "$PACCTFILE" | awk '{print $5}')
			AFTERSIZE=$(ls -lL "$PACCTFILE" | awk '{print $5}')

			# verify if accounting file grows, so is in use
			#
			if [ $BEFORSIZE -lt $AFTERSIZE ]
			then
			   echo Process accounting already used by psacct! >&2
			   exit $RETVAL		# do not start atopacctd
			fi
		fi
	done


	# Check if atopacctd runs already
	#
	if ps -e | grep -q atopacctd$
	then
		:
	else
		# Start atopacctd
		rm -rf /run/pacct_shadow.d 2> /dev/null
		/usr/sbin/atopacctd
	fi

	touch /run/lock/atopacctd
	;;

  stop)
	# Check if atopacctd runs
	#
	if ps -e | grep -q atopacctd$
	then
		kill $(ps -e | grep atopacctd$ | sed 's/^ *//' | cut -d' ' -f1)
	fi
	rm /run/lock/atopacctd
	;;

  status)
	;;

  reload)
	;;

  restart|force-reload)
  	$0 stop
        $0 start
	;;

  *)
	echo "Usage: $0 [start|stop]"
	exit 1
esac

exit $RETVAL