123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- #!/bin/bash
- if [ ${UID} -ne 0 ]; then
- echo "FATAL: Need to run as root."
- exit 1
- fi
- if [ -z "$(capsh --decode=$(cat /proc/self/status | grep ^CapEff | cut -f2) | grep sys_pacct)" ]; then
- echo "FATAL: Need CAP_SYS_PACCT to run."
- exit 1
- fi
- if [ $$ -eq 1 ]; then
- echo "FATAL: Need access to host PID namespace, can't seriously be PID 1."
- exit 1
- fi
- trap_shutdown() {
- echo "Shutting down..."
- exit 0
- }
- trap trap_shutdown SIGHUP SIGINT SIGQUIT SIGABRT SIGTERM
- PERIOD=10
- if [ -n "$1" ]; then
- PERIOD=$1
- fi
- echo "Reporting on process activity every ${PERIOD} seconds."
- case ${CUMULATIVE:-0} in
- 1|yes|true)
- echo "Gathering cumulative accounting data since container start."
- CUMULATIVE=1
- ;;
- *)
- echo "Clearing accounting data between snapshots."
- CUMULATIVE=0
- ;;
- esac
- case ${STARTUP_SCRATCH:-0} in
- 1|yes|true)
- echo "Removing existing accounting data due to scratch-on-startup being ${STARTUP_SCRATCH}..."
- rm -f /var/account/pacct*
- ;;
- *)
- echo "Skipping scratch-on-startup..."
- ;;
- esac
- echo "Making sure /var/account/pacct is ready..."
- /usr/libexec/psacct/accton-create
- /usr/sbin/accton /var/account/pacct
- while [ 1 ]; do
- sleep ${PERIOD}
-
-
-
- /usr/sbin/sa -ajlp > /var/account/psacct-dump-all
-
-
-
-
-
-
-
- if [ ${CUMULATIVE} -eq 0 ]; then
- echo -n > /var/account/pacct
- fi
- done
|