#!/bin/sh
# /usr/lib64/sa/sa1
# (C) 1999-2018 Sebastien Godard (sysstat <at> orange.fr)
#
#@(#) sysstat-12.0.2
#@(#) sa1: Collect and store binary data in system activity data file.
#

# Set default value for some variables.
# Used only if ${SYSCONFIG_DIR}/sysstat doesn't exist!
HISTORY=0
SADC_OPTIONS=""
SA_DIR=/var/log/sa
SYSCONFIG_DIR=/etc/sysstat
umask 0022

[ -r ${SYSCONFIG_DIR}/sysstat ] && . ${SYSCONFIG_DIR}/sysstat
[ -d ${SA_DIR} ] || SA_DIR=/var/log/sa

if [ ${HISTORY} -gt 28 ]
then
	SADC_OPTIONS="${SADC_OPTIONS} -D"
fi

set -e
ENDIR=/usr/lib64/sa
cd ${ENDIR}
LOCKFILE=/var/run/sysstat/sadc.LOCK
mkdir -p /var/run/sysstat
lockfile -r2 -30 "$LOCKFILE" 2>/dev/null
trap "/bin/rm -f $LOCKFILE" EXIT

[ "$1" = "--boot" ] && shift && BOOT=y || BOOT=n
if [ $# = 0 ] && [ "${BOOT}" = "n" ]
then
# Note: Stats are written at the end of previous file *and* at the
# beginning of the new one (when there is a file rotation) only if
# outfile has been specified as '-' on the command line...
	 ${ENDIR}/sadc -F -L ${SADC_OPTIONS} 1 1 ${SA_DIR}
else
	 ${ENDIR}/sadc -F -L ${SADC_OPTIONS} $* ${SA_DIR}
fi
