Skip to content

Commit

Permalink
crontab: cron reload only once
Browse files Browse the repository at this point in the history
  • Loading branch information
rufengsuixing committed Dec 25, 2019
1 parent a511eec commit 344111e
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions root/etc/init.d/AdGuardHome
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,7 @@ do_crontab
do_crontab(){
config_get crontab $CONFIGURATION crontab ""
local findstr default cronenable
local cronreload=0
findstr="/usr/share/AdGuardHome/update_core.sh"
default="#30 3 * * * /usr/share/AdGuardHome/update_core.sh 2>&1"
[ "$enabled" == "0" ] || [ "${crontab//autoupdate/}" == "$crontab" ] && cronenable=0 || cronenable=1
Expand All @@ -551,6 +552,7 @@ do_crontab(){
default="#30 3 * * * /usr/share/AdGuardHome/gfw2adg.sh"
[ "$enabled" == "0" ] || [ "${crontab//autogfw/}" == "$crontab" ] && cronenable=0 || cronenable=1
crontab_editor
[ "$cronreload" -gt 0 ] && /etc/init.d/cron restart
}
crontab_editor(){
local line="$(grep "$findstr" $CRON_FILE)"
Expand All @@ -560,14 +562,14 @@ crontab_editor(){
else
sed -i "\,$findstr,d" $CRON_FILE
echo "#$line" >> $CRON_FILE
/etc/init.d/cron restart
cronreload=$((cronreload+1))
fi
else
if [ $cronenable -eq 1 ]; then
[ -z "$line" ] && line="$default"
sed -i "\,$findstr,d" $CRON_FILE
echo "${line:1}" >> $CRON_FILE
/etc/init.d/cron restart
cronreload=$((cronreload+1))
else
return
fi
Expand Down

0 comments on commit 344111e

Please sign in to comment.