ufdb.initd 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #!/sbin/openrc-run
  2. # Copyright 1999-2011 Gentoo Foundation
  3. # Distributed under the terms of the GNU General Public License v2
  4. # reconfig is what the upstream documentation suggests, so let's
  5. # provide it for compatibility.
  6. extra_started_commands="reload reconfig"
  7. depend() {
  8. need net
  9. before squid
  10. use logger
  11. }
  12. get_config() {
  13. awk '$1 == "'$1'" { print $2 }' "/etc/ufdbGuard.conf"
  14. }
  15. gentables() {
  16. local dbhome=$(get_config dbhome)
  17. for gt in ${UFDB_GT} ; do
  18. [ -f "${dbhome}/${gt}/domains" ] || continue
  19. urls=
  20. [ -f "${dbhome}/${gt}/urls" ] && urls="${dbhome}/${gt}/urls"
  21. ebegin "Generating domainlist ${gt}"
  22. ufdbGenTable ${GENTABLE_OPTIONS} -t "${gt}" -d "${dbhome}/${gt}/domains" ${urls:+-u "${urls}"}
  23. eend $?
  24. done
  25. }
  26. start() {
  27. gentables
  28. local logdir=$(get_config logdir)
  29. if [ ! -d "${logdir}" ] ; then
  30. mkdir -p ${logdir}
  31. chown -R ${UFDB_USER} ${logdir}
  32. fi
  33. if [ ! -d /var/run/ufdbguardd ] ; then
  34. mkdir -p /var/run/ufdbguard
  35. chown -R ${UFDB_USER} /var/run/ufdbguard
  36. fi
  37. ebegin "Starting ufdbGuard"
  38. start-stop-daemon --start \
  39. --user ${UFDB_USER} \
  40. --wait 1500 \
  41. --exec /usr/libexec/ufdbguard/ufdbguardd \
  42. --pidfile /var/run/ufdbguard/ufdbguardd.pid -- \
  43. -c /etc/ufdbGuard.conf ${UFDB_OPTS}
  44. eend $? "Failed to start ufdbGuard"
  45. }
  46. stop() {
  47. ebegin "Stopping ufdbGuard"
  48. start-stop-daemon --stop \
  49. --exec /usr/libexec/ufdbguard/ufdbguardd \
  50. --pidfile /var/run/ufdbguard/ufdbguardd.pid
  51. eend $? "Failed to stop ufdbGuard"
  52. }
  53. reload() {
  54. if ! [ -f /var/run/ufdbguard/ufdbguardd.pid ]; then
  55. eerror "Unable to find PID file for ufdbguardd, was it just started?"
  56. return 1
  57. fi
  58. gentables
  59. ebegin "Reloading ufdbGuard"
  60. kill -HUP "$(cat /var/run/ufdbguard/ufdbguardd.pid)"
  61. eend $? "Failed to reload ufdbGuard"
  62. }
  63. reconfig() {
  64. reload
  65. }