1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
|
#!/bin/sh -e
### BEGIN INIT INFO
# Provides: dnscrypt-proxy
# Required-Start: $remote_fs
# Required-Stop: $remote_fs
# Should-Start: $network $syslog
# Should-Stop: $network $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start and stop dnscrypt-proxy
# Description: dnscrypt-proxy is Domain Name resolver with extra security
# features and enhanced privacy.
### END INIT INFO
PATH=/sbin:/bin:/usr/sbin:/usr/bin
. /lib/lsb/init-functions
DNSCRYPT_PROXY_BIN=/usr/sbin/dnscrypt-proxy
DNSCRYPT_PROXY_CONFDIR=/etc/dnscrypt-proxy
DNSCRYPT_PROXY_HOME=/run/dnscrypt-proxy
# Exit if the package is not installed
[ -x "${DNSCRYPT_PROXY_BIN}" ] || exit 0
get_config () {
if [ -e ${DNSCRYPT_PROXY_CONFDIR}/dnscrypt-proxy.conf ]; then
if [ $(find ${DNSCRYPT_PROXY_CONFDIR} -maxdepth 1 -type f \
-a -name "dnscrypt-proxy*.conf" \
-a ! -name "dnscrypt-proxy-common.conf" \
| wc -l) -gt 1 ]; then
log_warning_msg "${DNSCRYPT_PROXY_CONFDIR}/dnscrypt-proxy.conf found, using this as config file."
log_warning_msg "If you want multiple instances of dnscrypt-proxy then please rename"
log_warning_msg "dnscrypt-proxy.conf permanently by using the following command:"
log_warning_msg "dpkg-divert --local --divert FILENAME_OF_YOUR_CHOICE \\"
log_warning_msg "--rename ${DNSCRYPT_PROXY_CONFDIR}/dnscrypt-proxy.conf"
fi
DNSCRYPT_PROXY_CONFS=${DNSCRYPT_PROXY_CONFDIR}/dnscrypt-proxy.conf
else
if [ -z "$2" ]; then
DNSCRYPT_PROXY_CONFS=$(find ${DNSCRYPT_PROXY_CONFDIR} -maxdepth 1 -type f \
-a -name "dnscrypt-proxy*.conf" \
-a ! -name "dnscrypt-proxy-common.conf" | sort)
else
while shift ; do
[ -z "$1" ] && break
DNSCRYPT_PROXY_CONFS="${DNSCRYPT_PROXY_CONFS} ${DNSCRYPT_PROXY_CONFDIR}/dnscrypt-proxy-$1.conf"
done
fi
fi
}
start_instance () {
if [ -e ${DNSCRYPT_PROXY_CONF} ]; then
DNSCRYPT_PROXY_INSTANCE=$(basename ${DNSCRYPT_PROXY_CONF} | sed 's/.conf$//')
DNSCRYPT_PROXY_PIDFILE=$(grep "^PidFile" ${DNSCRYPT_PROXY_CONF} | awk '{print $2}')
log_daemon_msg "Starting dnscrypt proxy service..." ${DNSCRYPT_PROXY_INSTANCE}
if start_daemon -p "${DNSCRYPT_PROXY_PIDFILE}" ${DNSCRYPT_PROXY_BIN} \
${DNSCRYPT_PROXY_CONF} 2>/dev/null; then
if [ -x /sbin/resolvconf ]; then
grep "^LocalAddress" ${DNSCRYPT_PROXY_CONF} \
| awk '{print "nameserver "$2}' \
| cut -d ':' -f 1 \
| /sbin/resolvconf -a lo.${DNSCRYPT_PROXY_INSTANCE}
fi
log_success_msg
else
EXIT_STATUS=$?
log_failure_msg
fi
else
log_failure_msg "${DNSCRYPT_PROXY_CONF} not found" && EXIT_STATUS=3
fi
}
stop_instance () {
if [ -e ${DNSCRYPT_PROXY_CONF} ]; then
DNSCRYPT_PROXY_INSTANCE=$(basename ${DNSCRYPT_PROXY_CONF} | sed 's/.conf$//')
DNSCRYPT_PROXY_PIDFILE=$(grep "^PidFile" ${DNSCRYPT_PROXY_CONF} | awk '{print $2}')
log_daemon_msg "Stopping dnscrypt proxy service..." ${DNSCRYPT_PROXY_INSTANCE}
if [ -x /sbin/resolvconf ]; then
/sbin/resolvconf -d lo.${DNSCRYPT_PROXY_INSTANCE}
fi
if killproc -p "${DNSCRYPT_PROXY_PIDFILE}" ${DNSCRYPT_PROXY_BIN}; then
log_success_msg
else
echo $?
EXIT_STATUS=$?
log_failure_msg
fi
else
log_failure_msg "${DNSCRYPT_PROXY_CONF} not found" && EXIT_STATUS=3
fi
}
check_instance () {
if [ -e ${DNSCRYPT_PROXY_CONF} ]; then
DNSCRYPT_PROXY_INSTANCE=$(basename ${DNSCRYPT_PROXY_CONF} | sed 's/.conf$//')
DNSCRYPT_PROXY_PIDFILE=$(grep "^PidFile" ${DNSCRYPT_PROXY_CONF} | awk '{print $2}')
status_of_proc -p "${DNSCRYPT_PROXY_PIDFILE}" ${DNSCRYPT_PROXY_BIN} \
${DNSCRYPT_PROXY_INSTANCE} 2>/dev/null || EXIT_STATUS=$?
else
log_failure_msg "${DNSCRYPT_PROXY_CONF} not found" && EXIT_STATUS=3
fi
}
case "$1" in
start)
[ -d "${DNSCRYPT_PROXY_HOME}" ] || \
mkdir -m 0555 "${DNSCRYPT_PROXY_HOME}"
EXIT_STATUS=0
get_config "$@"
for DNSCRYPT_PROXY_CONF in ${DNSCRYPT_PROXY_CONFS}; do
start_instance
done
exit ${EXIT_STATUS}
;;
stop)
EXIT_STATUS=0
get_config "$@"
for DNSCRYPT_PROXY_CONF in ${DNSCRYPT_PROXY_CONFS}; do
stop_instance
done
exit ${EXIT_STATUS}
;;
restart|force-reload)
shift
$0 stop ${@}
$0 start ${@}
;;
status)
EXIT_STATUS=0
get_config "$@"
for DNSCRYPT_PROXY_CONF in ${DNSCRYPT_PROXY_CONFS}; do
check_instance
done
exit ${EXIT_STATUS}
;;
*)
log_action_msg "Usage: /etc/init.d/dnscrypt-proxy {start|stop|restart|force-reload|status}"
exit 1
;;
esac
exit 0
# vim: set ai sts=2 sw=2 tw=0 :
|