Revert package feed back
[librecmc/package-feed.git] / net / adblock / files / adblock.init
index 5ca4d1176a8e9be0af9c5b6f064f95c51d59b06d..ee94aa8228dabe6574a029c83bee18650cf6c3ab 100755 (executable)
@@ -1,7 +1,7 @@
 #!/bin/sh /etc/rc.common
 #
 
-START=30
+START=50
 USE_PROCD=1
 
 EXTRA_COMMANDS="suspend resume query status"
@@ -12,40 +12,30 @@ EXTRA_HELP="        suspend Suspend adblock processing
 
 adb_init="/etc/init.d/adblock"
 adb_script="/usr/bin/adblock.sh"
-adb_pidfile="/var/run/adblock.pid"
 
 boot()
 {
     adb_boot=1
+    ubus -t 30 wait_for network.interface 2>/dev/null
     rc_procd start_service
 }
 
 start_service()
 {
-    if [ $("${adb_init}" enabled; printf "%u" ${?}) -eq 0 ]
+    if [ $("${adb_init}" enabled; printf ${?}) -eq 0 ]
     then
         if [ -n "${adb_boot}" ]
         then
-            local trigger="$(uci_get adblock.global.adb_trigger)"
-            if [ "${trigger}" != "timed" ]
-            then
-                return 0
-            fi
+            return 0
         fi
         procd_open_instance "adblock"
         procd_set_param command "${adb_script}" "${@}"
-        procd_set_param pidfile "${adb_pidfile}"
         procd_set_param stdout 1
         procd_set_param stderr 1
         procd_close_instance
     fi
 }
 
-reload_service()
-{
-    rc_procd start_service reload
-}
-
 stop_service()
 {
     rc_procd "${adb_script}" stop
@@ -59,52 +49,34 @@ restart()
 
 suspend()
 {
-    [ -s "${adb_pidfile}" ] && return 1
     rc_procd "${adb_script}" suspend
 }
 
 resume()
 {
-    [ -s "${adb_pidfile}" ] && return 1
     rc_procd "${adb_script}" resume
 }
 
 query()
 {
-    [ -s "${adb_pidfile}" ] && return 1
     rc_procd "${adb_script}" query "${1}"
 }
 
 status()
 {
-    local key keylist value rtfile="$(uci_get adblock.extra.adb_rtfile)"
-
-    rtfile="${rtfile:-"/tmp/adb_runtime.json"}"
-    if [ -s "${rtfile}" ]
-    then
-        printf "%s\n" "::: adblock runtime information"
-        json_load "$(cat "${rtfile}" 2>/dev/null)"
-        json_select data
-        json_get_keys keylist
-        for key in ${keylist}
-        do
-            json_get_var value "${key}"
-            printf "  + %-15s : %s\n" "${key}" "${value}"
-        done
-    else
-        printf "%s\n" "::: no adblock runtime information available"
-    fi
+    rc_procd "${adb_script}" status
 }
 
 service_triggers()
 {
-    local trigger="$(uci_get adblock.global.adb_trigger)"
-    local delay="$(uci_get adblock.extra.adb_triggerdelay)"
+    local iface="$(uci -q get adblock.global.adb_iface)"
+    local delay="$(uci -q get adblock.global.adb_triggerdelay)"
 
-    if [ "${trigger}" != "none" ] && [ "${trigger}" != "timed" ]
-    then
-        PROCD_RELOAD_DELAY=$((${delay:-2} * 1000))
-        procd_add_interface_trigger "interface.*.up" "${trigger}" "${adb_init}" start
-    fi
-    procd_add_reload_trigger "adblock"
+    PROCD_RELOAD_DELAY=$((${delay:=2} * 1000))
+    for name in ${iface}
+    do
+        procd_add_interface_trigger "interface.*.up" "${name}" "${adb_init}" start
+    done
+    PROCD_RELOAD_DELAY=1000
+    procd_add_config_trigger "config.change" "adblock" "${adb_init}" start
 }