dnscrypt-proxy.initd-1.6.0-r1 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!/sbin/openrc-run
  2. # Copyright 1999-2014 Gentoo Foundation
  3. # Distributed under the terms of the GNU General Public License v2
  4. DNSCRYPT_LOGFILE=${DNSCRYPT_LOGFILE:-/var/log/dnscrypt-proxy.log}
  5. DNSCRYPT_RESOLVERS_LIST=${DNSCRYPT_RESOLVERS_LIST:-/usr/share/dnscrypt-proxy/dnscrypt-resolvers.csv}
  6. rundir=${rundir:-/var/run/dnscrypt-proxy}
  7. pidfile=${pidfile:-${rundir}/dnscrypt-proxy.pid}
  8. rundir=${rundir:-/var/run/dnscrypt-proxy}
  9. runas_user=${runas_user:-dnscrypt}
  10. runas_group=${runas_user:-dnscrypt}
  11. depend() {
  12. use net
  13. before dns
  14. after logger
  15. }
  16. start() {
  17. if [ ! -d "${rundir}" ]; then
  18. mkdir "${rundir}"
  19. if [ -n "${runas_user}" ]; then
  20. touch "${DNSCRYPT_LOGFILE}"
  21. chown ${runas_user}:${runas_group} "${DNSCRYPT_LOGFILE}"
  22. chown -R ${runas_user}:${runas_group} "${rundir}"
  23. fi
  24. fi
  25. if [ -n "$DNSCRYPT_RESOLVER_NAME" -a -n "$DNSCRYPT_RESOLVERIP" ]; then
  26. eerror "You must set exactly one of DNSCRYPT_RESOLVER_NAME or DNSCRYPT_RESOLVERIP!"
  27. return 1
  28. elif [ -n "$DNSCRYPT_RESOLVER_NAME" ]; then
  29. resolver_opts="--resolvers-list=${DNSCRYPT_RESOLVERS_LIST} --resolver-name=${DNSCRYPT_RESOLVER_NAME}"
  30. elif [ -n "$DNSCRYPT_RESOLVERIP" ]; then
  31. resolver_opts="--resolver-address=${DNSCRYPT_RESOLVERIP}:${DNSCRYPT_RESOLVERPORT} --provider-name=${DNSCRYPT_PROVIDER_NAME} --provider-key=${DNSCRYPT_PROVIDER_KEY}"
  32. else
  33. eerror "You must set exactly one of DNSCRYPT_RESOLVER_NAME or DNSCRYPT_RESOLVERIP!"
  34. return 1
  35. fi
  36. ebegin "Starting dnscrypt-proxy"
  37. start-stop-daemon --start --quiet \
  38. --exec /usr/sbin/dnscrypt-proxy \
  39. -- \
  40. ${DNSCRYPT_OPTIONS} \
  41. --pidfile="${pidfile}" \
  42. --logfile="${DNSCRYPT_LOGFILE}" \
  43. --daemonize --user=${runas_user} \
  44. --local-address=${DNSCRYPT_LOCALIP}:${DNSCRYPT_LOCALPORT} \
  45. $resolver_opts
  46. eend $?
  47. }
  48. stop() {
  49. ebegin "Stopping dnscrypt-proxy"
  50. start-stop-daemon --stop --quiet --exec /usr/sbin/dnscrypt-proxy
  51. eend $?
  52. }