mirror of
https://github.com/remittor/zapret-openwrt.git
synced 2025-12-06 03:26:49 +03:00
init: Add cron task for removing huge log-files
This commit is contained in:
@@ -17,6 +17,8 @@ ZAPRET_CFG_SEC_NAME="$( uci -q get $ZAPRET_CFG_NAME.config )"
|
||||
|
||||
. $ZAPRET_BASE/def-cfg.sh
|
||||
|
||||
CRONTAB_FILE="/etc/crontabs/root"
|
||||
|
||||
function adapt_for_sed
|
||||
{
|
||||
local str=$( ( echo $1|sed -r 's/([\$\.\*\/\[\\^])/\\\1/g'|sed 's/[]]/\\]/g' )>&1 )
|
||||
@@ -122,3 +124,34 @@ function merge_cfg_with_def_values
|
||||
return 0
|
||||
}
|
||||
|
||||
function remove_cron_task_logs
|
||||
{
|
||||
if [ -f "$CRONTAB_FILE" ]; then
|
||||
sed -i "/-name 'zapret\*.log' -size +/d" "$CRONTAB_FILE"
|
||||
fi
|
||||
}
|
||||
|
||||
function insert_cron_task_logs
|
||||
{
|
||||
[ ! -f "$CRONTAB_FILE" ] && touch "$CRONTAB_FILE"
|
||||
[ ! -f "$CRONTAB_FILE" ] && return 1
|
||||
if ! grep -q -e "-name 'zapret\*\.log' -size \+" "$CRONTAB_FILE"; then
|
||||
echo "*/2 * * * * /usr/bin/find /tmp -maxdepth 1 -type f -name 'zapret*.log' -size +2600k -exec rm -f {} \;" >> "$CRONTAB_FILE"
|
||||
/etc/init.d/cron restart 2> /dev/null
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
function init_before_start
|
||||
{
|
||||
local DAEMON_LOG_ENABLE=$1
|
||||
chmod 644 $ZAPRET_BASE/ipset/*.txt
|
||||
chmod 666 $ZAPRET_BASE/ipset/*.log
|
||||
rm -f /tmp/zapret*.log
|
||||
#*/
|
||||
if [ "$DAEMON_LOG_ENABLE" = "1" ]; then
|
||||
insert_cron_task_logs
|
||||
else
|
||||
remove_cron_task_logs
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -68,13 +68,18 @@ function boot
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
init_before_start "$DAEMON_LOG_ENABLE"
|
||||
/bin/sh /etc/rc.common $ZAPRET_ORIG_INITD start "$@"
|
||||
}
|
||||
|
||||
function start
|
||||
{
|
||||
init_before_start "$DAEMON_LOG_ENABLE"
|
||||
/bin/sh /etc/rc.common $ZAPRET_ORIG_INITD start "$@"
|
||||
}
|
||||
|
||||
function restart
|
||||
{
|
||||
chmod 644 /opt/zapret/ipset/*.txt
|
||||
chmod 666 /opt/zapret/ipset/*.log
|
||||
rm -f /tmp/zapret*.log
|
||||
init_before_start "$DAEMON_LOG_ENABLE"
|
||||
/bin/sh /etc/rc.common $ZAPRET_ORIG_INITD restart "$@"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user