You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

86 lines
1.6 KiB

  1. #!/bin/sh /etc/rc.common
  2. #
  3. START=99
  4. exec 2>/dev/null
  5. adb_pid="${$}"
  6. adb_script="/usr/bin/adblock-update.sh"
  7. adb_pidfile="/var/run/adblock.pid"
  8. adb_logger="/usr/bin/logger"
  9. adb_uci="/sbin/uci"
  10. if [ -t 1 ]
  11. then
  12. log_parm="-s"
  13. unset bg_parm
  14. else
  15. unset log_parm
  16. bg_parm="&"
  17. fi
  18. if [ -r "${adb_pidfile}" ]
  19. then
  20. "${adb_logger}" ${log_parm} -t "adblock[${adb_pid}] error" "adblock service already running ($(cat ${adb_pidfile})" 2>&1
  21. exit 255
  22. fi
  23. remove_config()
  24. {
  25. local value opt section="${1}" options="adb_src_timestamp adb_src_count"
  26. for opt in ${options}
  27. do
  28. ${adb_uci} -q delete "adblock.${section}.${opt}"
  29. done
  30. }
  31. boot()
  32. {
  33. return 0
  34. }
  35. start()
  36. {
  37. eval "${adb_script}" ${bg_parm}
  38. return 0
  39. }
  40. restart()
  41. {
  42. stop
  43. start
  44. }
  45. reload()
  46. {
  47. stop
  48. start
  49. }
  50. stop()
  51. {
  52. rm_done="$(find "/tmp/dnsmasq.d" -maxdepth 1 -type f -name "adb_list.*" -print -exec rm -f "{}" \;)"
  53. rc=${?}
  54. if [ $((rc)) -eq 0 ] && [ -n "${rm_done}" ]
  55. then
  56. . "/lib/functions.sh"
  57. config_load adblock
  58. config_foreach remove_config source
  59. ${adb_uci} -q delete "adblock.global.adb_overall_count"
  60. ${adb_uci} -q commit "adblock"
  61. /etc/init.d/dnsmasq restart
  62. /etc/init.d/firewall restart
  63. fi
  64. uhttpd_pid="$(ps | grep "[u]httpd.*\-h /www/adblock" | awk '{print $1}')"
  65. if [ -n "${uhttpd_pid}" ]
  66. then
  67. kill -9 "${uhttpd_pid}"
  68. fi
  69. if [ -n "${rm_done}" ] || [ -n "${uhttpd_pid}" ]
  70. then
  71. "${adb_logger}" ${log_parm} -t "adblock[${adb_pid}] info " "all adblock related services stopped" 2>&1
  72. fi
  73. return 0
  74. }