#!/bin/sh
:<<!
This use case is used to check the cleanup function of the service-side
tool logs, with a maximum of 50 files retained and a maximum size of 16MB
per file. It is not only applicable to gs_ctl, but also to other tools
such as gs_restore, gs_dumpall, gs_guc, gs_dump, gs_clean, or gs_cgroup.
!
source ./util.sh
function gs_ctl_log_remove()
{
export GAUSSLOG=$GAUSSHOME/logs
gs_ctl query -D $primary_data_dir
if [ "$?" -ne 0 ]; then
echo "gs_ctl query error: $failed_keyword"
fi
count=`ls -l $GAUSSLOG/bin/gs_ctl | grep log | wc -l`
if [ $count -ne 1 ]; then
echo "gs_ctl create logfile error: $failed_keyword"
fi
curr=`ls -l $GAUSSLOG/bin/gs_ctl | grep current | awk '{print $9}'`
dd if=/dev/zero of=$GAUSSLOG/bin/gs_ctl/$curr bs=16M count=1
date=`echo $(date "+%Y-%m-%d")`
for i in `seq 1 50`
do
time=`echo $i | awk '{printf("%06d\n", $0)}'`
name="gs_ctl-""$date"_"$time".log
dd if=/dev/zero of=$GAUSSLOG/bin/gs_ctl/$name bs=16M count=1
done
gs_ctl query -D $primary_data_dir
if [ "$?" -ne 0 ]; then
echo "gs_ctl query error: $failed_keyword"
fi
count=`ls -l $GAUSSLOG/bin/gs_ctl | grep log | wc -l`
if [ $count -ne 50 ]; then
echo "gs_ctl remove log error: $failed_keyword"
fi
for i in `seq 1 10`
do
gs_ctl query -D $primary_data_dir &
done
}
function tear_down()
{
tms=0
while true
do
count=`ps ux | grep "gs_ctl query" | grep -v grep | wc -l`
if [ $count -ne 0 -a $tms -lt 30 ]; then
let $tms+1
sleep 1
else
break
fi
done
rm -rf $GAUSSLOG/bin
if [ "$?" -ne 0 ]; then
echo "remove file error: $failed_keyword"
fi
}
gs_ctl_log_remove
tear_down