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.

69 lines
2.0 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. 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. create_squid_user() {
  22. user_exists squid || user_add squid $USERID
  23. group_exists squid || group_add squid $USERID && group_add_user squid squid
  24. }
  25. start_service() {
  26. local config_file http_port http_port_options ssldb ssldb_options coredump_dir visible_hostname pinger_enable
  27. validate_squid_section squid || {
  28. echo "validation failed"
  29. return 1
  30. }
  31. config_dir=$(dirname $CONFIGFILE)
  32. [ -d $config_dir ] || mkdir -p $config_dir && chown nobody:nogroup $config_dir
  33. [ -d $coredump_dir ] || mkdir -p $coredump_dir && chown nobody:nogroup $coredump_dir
  34. [ "$ssldb" ] && ( [ -f "$ssldb"/size ] || /usr/lib/squid/security_file_certgen -c -s $ssldb $ssldb_options && chown -R nobody:nogroup $ssldb )
  35. cat $config_file > $CONFIGFILE
  36. echo http_port $http_port $http_port_options >> $CONFIGFILE
  37. echo coredump_dir $coredump_dir >> $CONFIGFILE
  38. echo visible_hostname $visible_hostname >> $CONFIGFILE
  39. echo pinger_enable $pinger_enable >> $CONFIGFILE
  40. cat $mime_table > $MIMETABLE
  41. echo mime_table $MIMETABLE >> $CONFIGFILE
  42. [ "$ssldb" ] && echo sslcrtd_program /usr/lib/squid/security_file_certgen -s $ssldb $ssldb_options >> $CONFIGFILE
  43. $PROG -s -f $CONFIGFILE -N -z 2>/dev/null
  44. procd_open_instance
  45. procd_set_param command $PROG -s -f $CONFIGFILE -N
  46. procd_set_param file $CONFIGFILE
  47. procd_set_param respawn
  48. procd_close_instance
  49. }
  50. stop_service()
  51. {
  52. ${PROG} -f $CONFIGFILE -N -k shutdown 2>/dev/null
  53. }
  54. service_triggers()
  55. {
  56. procd_add_reload_trigger "squid"
  57. procd_add_validation validate_squid_section
  58. }