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.

60 lines
1.7 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. 'http_port_options:string' \
  13. 'ssldb:string' \
  14. 'ssldb_options:string' \
  15. 'coredump_dir:string' \
  16. 'visible_hostname:string:OpenWrt' \
  17. 'pinger_enable:string:off'
  18. }
  19. start_service() {
  20. local config_file http_port http_port_options ssldb ssldb_options coredump_dir visible_hostname pinger_enable
  21. validate_squid_section squid || {
  22. echo "validation failed"
  23. return 1
  24. }
  25. config_dir=$(dirname $CONFIGFILE)
  26. [ -d $config_dir ] || mkdir -p $config_dir && chown nobody:nogroup $config_dir
  27. [ -d $coredump_dir ] || mkdir -p $coredump_dir && chown nobody:nogroup $coredump_dir
  28. [ "$ssldb" ] && ( [ -f "$ssldb"/size ] || /usr/lib/squid/ssl_crtd -c -s $ssldb && chown -R nobody:nogroup $ssldb )
  29. cat $config_file > $CONFIGFILE
  30. echo http_port $http_port $http_port_options >> $CONFIGFILE
  31. echo coredump_dir $coredump_dir >> $CONFIGFILE
  32. echo visible_hostname $visible_hostname >> $CONFIGFILE
  33. echo pinger_enable $pinger_enable >> $CONFIGFILE
  34. [ "$ssldb" ] && echo sslcrtd_program /usr/lib/squid/ssl_crtd -s $ssldb $ssldb_options >> $CONFIGFILE
  35. $PROG -s -f $CONFIGFILE -N -z 2>/dev/null
  36. procd_open_instance
  37. procd_set_param command $PROG -s -f $CONFIGFILE -N
  38. procd_set_param file $CONFIGFILE
  39. procd_set_param respawn
  40. procd_close_instance
  41. }
  42. stop_service()
  43. {
  44. ${PROG} -f $CONFIGFILE -N -k shutdown 2>/dev/null
  45. }
  46. service_triggers()
  47. {
  48. procd_add_reload_trigger "squid"
  49. procd_add_validation validate_squid_section
  50. }