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.

54 lines
1.3 KiB

  1. #!/bin/sh /etc/rc.common
  2. # Copyright (C) 2015 OpenWrt.org
  3. START=90
  4. STOP=10
  5. USE_PROCD=1
  6. PROG=/usr/sbin/squid
  7. CONFIGFILE="/tmp/squid/squid.conf"
  8. validate_squid_section() {
  9. uci_validate_section squid squid "${1}" \
  10. 'config_file:string' \
  11. 'http_port:port:3128' \
  12. 'coredump_dir:string' \
  13. 'visible_hostname:string:OpenWrt' \
  14. 'pinger_enable:string:off'
  15. }
  16. start_service() {
  17. local config_file http_port coredump_dir visible_hostname pinger_enable
  18. validate_squid_section squid || {
  19. echo "validation failed"
  20. return 1
  21. }
  22. config_dir=$(dirname $CONFIGFILE)
  23. [ -d $config_dir ] || mkdir -p $config_dir && chown nobody:nogroup $config_dir
  24. [ -d $coredump_dir ] || mkdir -p $coredump_dir && chown nobody:nogroup $coredump_dir
  25. cat $config_file > $CONFIGFILE
  26. echo http_port $http_port >> $CONFIGFILE
  27. echo coredump_dir $coredump_dir >> $CONFIGFILE
  28. echo visible_hostname $visible_hostname >> $CONFIGFILE
  29. echo pinger_enable $pinger_enable >> $CONFIGFILE
  30. procd_open_instance
  31. procd_set_param command $PROG -s -f $CONFIGFILE -N
  32. procd_set_param file $CONFIGFILE
  33. procd_set_param respawn
  34. procd_close_instance
  35. }
  36. stop_service()
  37. {
  38. ${PROG} -f $CONFIGFILE -N -k shutdown 2>/dev/null
  39. }
  40. service_triggers()
  41. {
  42. procd_add_reload_trigger "squid"
  43. procd_add_validation validate_squid_section
  44. }