12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- #!/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 -rf /var/account
- ;;
- *)
- 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
- /usr/sbin/dump-acct /var/account/pacct > /var/account/psacct-dump-raw
-
-
-
- if [ ${CUMULATIVE} -eq 0 ]; then
- echo -n > /var/account/pacct
- fi
- done
|