squid.init 1.8 KB

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