diff --git a/zapret/comfunc.sh b/zapret/comfunc.sh index 13702e4..50e3fbd 100755 --- a/zapret/comfunc.sh +++ b/zapret/comfunc.sh @@ -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 +} diff --git a/zapret/init.d.sh b/zapret/init.d.sh index 4aec1cc..9dd1146 100755 --- a/zapret/init.d.sh +++ b/zapret/init.d.sh @@ -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 "$@" }