mystic/dbp/cron.sh

104 lines
4.1 KiB
Bash
Raw Normal View History

2023-01-08 11:57:13 +01:00
#!/bin/bash
2023-01-08 12:11:41 +01:00
usage() { echo "Usage: $0 [-f dbp.ini]" 1>&2; exit 1; }
while getopts ":f:" o; do
case "${o}" in
f)
INIFILE=${OPTARG}
2023-01-08 12:54:07 +01:00
;;
2023-01-08 12:11:41 +01:00
*)
usage
;;
esac
2023-01-08 11:57:13 +01:00
done
2023-01-08 12:11:41 +01:00
shift $((OPTIND-1))
2023-01-08 12:48:38 +01:00
if [ -z "${INIFILE}" ]; then
2023-01-08 12:11:41 +01:00
usage
fi
2023-01-08 11:57:13 +01:00
2023-01-08 12:11:41 +01:00
MYSTIC_DIR="@MYSTIC_DIR@"
2023-01-08 11:57:13 +01:00
TMP_DIR=$(mktemp -d)
MIS_ENABLE=`${MYSTIC_DIR}/inimod r ${INIFILE} -S GeneralDbP -k MisLog --silent`
MIS_KEEP=`${MYSTIC_DIR}/inimod r ${INIFILE} -S MisLog -k RetentionTime --silent`
2023-01-08 11:57:13 +01:00
MUTIL_ENABLE=`${MYSTIC_DIR}/inimod r ${INIFILE} -S GeneralDbP -k MutilLog --silent`
MUTIL_KEEP=`${MYSTIC_DIR}/inimod r ${INIFILE} -S MutilLog -k RetentionTime --silent`
2023-01-08 11:57:13 +01:00
ERROR_ENABLE=`${MYSTIC_DIR}/inimod r ${INIFILE} -S GeneralDbP -k ErrorLog --silent`
ERROR_KEEP=`${MYSTIC_DIR}/inimod r ${INIFILE} -S ErrorLog -k RetentionTime --silent`
2023-01-08 11:57:13 +01:00
MRCCHAT_ENABLE=`${MYSTIC_DIR}/inimod r ${INIFILE} -S GeneralDbP -k MrcChatLog --silent`
MRCCHAT_KEEP=`${MYSTIC_DIR}/inimod r ${INIFILE} -S MrcChatLog -k RetentionTime --silent`
2023-01-08 11:57:13 +01:00
NODE_ENABLE=`${MYSTIC_DIR}/inimod r ${INIFILE} -S GeneralDbP -k NodeLog --silent`
NODE_COUNT=`${MYSTIC_DIR}/inimod r ${INIFILE} -S NodeLog -k MaxNodes --silent`
NODE_KEEP=`${MYSTIC_DIR}/inimod r ${INIFILE} -S NodeLog -k RetentionTime --silent`
2023-01-14 11:32:27 +01:00
NODE_START=0
2023-01-08 11:57:13 +01:00
IP2L_ENABLE=`${MYSTIC_DIR}/inimod r ${INIFILE} -S GeneralDbP -k Ip2Location --silent`
IP2L_TOKEN=`${MYSTIC_DIR}/inimod r ${INIFILE} -S Ip2Location -k Token --silent`
IP2L_DB=`${MYSTIC_DIR}/inimod r ${INIFILE} -S Ip2Location -k Database --silent`
YESTERDAY=$(date '+%Y%m%d' -d "-1days")
NOW=$(date '+%Y%m%d')
TOMORROW=$(date '+%Y%m%d' -d "+1days")
if [ $MIS_ENABLE = "true" ]; then
touch ${MYSTIC_DIR}/logs/mis.${NOW}.log
touch ${MYSTIC_DIR}/logs/mis.${TOMORROW}.log
ln -sf mis.${NOW}.log ${MYSTIC_DIR}/logs/mis.log
[ -f /${MYSTIC_DIR}/logs/mis.${YESTERDAY}.log ] && gzip -9 ${MYSTIC_DIR}/logs/mis.${YESTERDAY}.log
find ${MYSTIC_DIR}/logs/ -type f -mtime +${MIS_KEEP} -name 'mis.*' -exec rm {} \;
2023-01-08 11:57:13 +01:00
fi
if [ $MUTIL_ENABLE = "true" ]; then
touch ${MYSTIC_DIR}/logs/mutil.${NOW}.log
touch ${MYSTIC_DIR}/logs/mutil.${TOMORROW}.log
ln -sf mutil.${NOW}.log ${MYSTIC_DIR}/logs/mutil.log
[ -f /${MYSTIC_DIR}/logs/mutil.${YESTERDAY}.log ] && gzip -9 ${MYSTIC_DIR}/logs/mutil.${YESTERDAY}.log
find ${MYSTIC_DIR}/logs/ -type f -mtime +${MUTIL_KEEP} -name 'mutil.*' -exec rm {} \;
2023-01-08 11:57:13 +01:00
fi
if [ $ERROR_ENABLE = "true" ]; then
touch ${MYSTIC_DIR}/logs/errors.${NOW}.log
touch ${MYSTIC_DIR}/logs/errors.${TOMORROW}.log
ln -sf errors.${NOW}.log ${MYSTIC_DIR}/logs/errors.log
[ -f /${MYSTIC_DIR}/logs/errors.${YESTERDAY}.log ] && gzip -9 ${MYSTIC_DIR}/logs/errors.${YESTERDAY}.log
find ${MYSTIC_DIR}/logs/ -type f -mtime +${ERROR_KEEP} -name 'error.*' -exec rm {} \;
2023-01-08 11:57:13 +01:00
fi
if [ $MRCCHAT_ENABLE = "true" ]; then
touch ${MYSTIC_DIR}/logs/mrcchat.${NOW}.log
touch ${MYSTIC_DIR}/logs/mrcchat.${TOMORROW}.log
2023-01-08 12:54:07 +01:00
mkdir -p ${MYSTIC_DIR}/data/mrc/
2023-01-08 11:57:13 +01:00
ln -sf ../../logs/mrcchat.${NOW}.log ${MYSTIC_DIR}/data/mrc/mrcchat.log
ln -sf mrcchat.${NOW}.log ${MYSTIC_DIR}/logs/mrcchat.log
[ -f /${MYSTIC_DIR}/logs/mrcchat.${YESTERDAY}.log ] && gzip -9 ${MYSTIC_DIR}/logs/mrcchat.${YESTERDAY}.log
find ${MYSTIC_DIR}/logs/ -type f -mtime +${MRCCHAT_KEEP} -name 'mrcchat.*' -exec rm {} \;
2023-01-08 11:57:13 +01:00
fi
if [ $NODE_ENABLE = "true" ]; then
2023-01-14 11:32:27 +01:00
for i in $(eval echo "{$NODE_START..$NODE_COUNT}")
2023-01-08 11:57:13 +01:00
do
touch ${MYSTIC_DIR}/logs/node${i}.${NOW}.log
touch ${MYSTIC_DIR}/logs/node${i}.${TOMORROW}.log
ln -sf node${i}.${NOW}.log ${MYSTIC_DIR}/logs/node${i}.log
[ -f ${MYSTIC_DIR}/logs/node${i}.${YESTERDAY}.log ] && gzip -9 ${MYSTIC_DIR}/logs/node${i}.${YESTERDAY}.log
find ${MYSTIC_DIR}/logs/ -type f -mtime +${NODE_KEEP} -name 'node*' -exec rm {} \;
2023-01-08 11:57:13 +01:00
done
fi
if [ $IP2L_ENABLE = "true" ]; then
2023-01-08 12:48:38 +01:00
${MYSTIC_DIR}/ip2location -package ${IP2L_DB} -token ${IP2L_TOKEN} -output ${TMP_DIR}/IP2LOCATION.ZIP
unzip -o ${TMP_DIR}/IP2LOCATION.ZIP -x *.TXT -d ${TMP_DIR}
2023-01-08 11:57:13 +01:00
unzip -o ${TMP_DIR}/IP2LOCATION.ZIP -x *.BIN -d ${MYSTIC_DIR}/docs
2023-01-08 12:48:38 +01:00
mv ${TMP_DIR}/IP2LOCATION-*.BIN ${MYSTIC_DIR}/data/iplocation.bin
2023-01-08 11:57:13 +01:00
rm -rf ${TMP_DIR}
fi
exit 0