aboutsummaryrefslogtreecommitdiff
path: root/network/dnscrypt-proxy/rc.dnscrypt-proxy
diff options
context:
space:
mode:
authorT3slider <t3slider@gmail.com>2014-10-05 23:38:01 +0700
committerWilly Sudiarto Raharjo <willysr@slackbuilds.org>2014-10-11 00:13:58 +0700
commit1bbffca294904b2db7942a22b4b5c6fe6e7313fc (patch)
treef716f2ecc256984b0fab82c952fe1319b85cd208 /network/dnscrypt-proxy/rc.dnscrypt-proxy
parent7d79d345593986b00d9d2d509b419d5a8b3254df (diff)
network/dnscrypt-proxy: Updated for version 1.4.1.
Signed-off-by: Willy Sudiarto Raharjo <willysr@slackbuilds.org>
Diffstat (limited to 'network/dnscrypt-proxy/rc.dnscrypt-proxy')
-rw-r--r--network/dnscrypt-proxy/rc.dnscrypt-proxy175
1 files changed, 175 insertions, 0 deletions
diff --git a/network/dnscrypt-proxy/rc.dnscrypt-proxy b/network/dnscrypt-proxy/rc.dnscrypt-proxy
new file mode 100644
index 000000000000..84eb12c74dca
--- /dev/null
+++ b/network/dnscrypt-proxy/rc.dnscrypt-proxy
@@ -0,0 +1,175 @@
+#!/bin/bash
+
+CONFIGFILE="/etc/default/dnscrypt-proxy"
+DAEMON="/usr/sbin/dnscrypt-proxy"
+
+. $CONFIGFILE
+
+start_instance() {
+ if [ -z ${PIDFILE[$1]} ]; then
+ echo "No configuration for instance $1 found!"
+ return
+ fi
+ if [ -r ${PIDFILE[$1]} ]; then
+ echo "dnscrypt-proxy (instance $1) already running!"
+ return
+ fi
+
+ # dnscrypt-proxy will work without this, but it drops privileges before
+ # seeding the PRNG. libevent tries to work around a missing /dev/urandom
+ # but it's safer just to make sure it is available in the chroot.
+ if [ -n "${CHROOTDIR[$1]}" ]; then
+ if [ "$(readlink -f ${CHROOTDIR[$1]})" != "/" ]; then
+ if [ ! -d ${CHROOTDIR[$1]} ]; then
+ mkdir -p ${CHROOTDIR[$1]}
+ chmod 755 ${CHROOTDIR[$1]}
+ fi
+ if [ ! -d ${CHROOTDIR[$1]}/dev ]; then
+ mkdir -p ${CHROOTDIR[$1]}/dev
+ chmod 755 ${CHROOTDIR[$1]}/dev
+ fi
+ if [ ! -c ${CHROOTDIR[$1]}/dev/urandom ]; then
+ mknod -m 666 ${CHROOTDIR[$1]}/dev/urandom c 1 9
+ fi
+ fi
+ fi
+
+ OPTIONS="-d"
+ if [ -n "${LOCALADDRESS[$1]}" ]; then
+ OPTIONS="${OPTIONS} --local-address=${LOCALADDRESS[$1]}"
+ fi
+ if [ -n "${PIDFILE[$1]}" ]; then
+ OPTIONS="${OPTIONS} --pidfile=${PIDFILE[$1]}"
+ fi
+ if [ -n "${USER[$1]}" ]; then
+ OPTIONS="${OPTIONS} --user=${USER[$1]}"
+ fi
+ if [ -n "${RESOLVERNAME[$1]}" ]; then
+ OPTIONS="${OPTIONS} --resolver-name=${RESOLVERNAME[$1]}"
+ fi
+ if [ -n "${RESOLVERSLIST[$1]}" ]; then
+ OPTIONS="${OPTIONS} --resolvers-list=${RESOLVERSLIST[$1]}"
+ fi
+ if [ -z "${RESOLVERNAME[$1]}" ] && [ -n "${RESOLVERADDRESS[$1]}" ]; then
+ OPTIONS="${OPTIONS} --resolver-address=${RESOLVERADDRESS[$1]}"
+ fi
+ if [ -z "${RESOLVERNAME[$1]}" ] && [ -n "${PROVIDERNAME[$1]}" ]; then
+ OPTIONS="${OPTIONS} --provider-name=${PROVIDERNAME[$1]}"
+ fi
+ if [ -z "${RESOLVERNAME[$1]}" ] && [ -n "${PROVIDERKEY[$1]}" ]; then
+ OPTIONS="${OPTIONS} --provider-key=${PROVIDERKEY[$1]}"
+ fi
+ if [ -n "${EDNSPAYLOADSIZE[$1]}" ]; then
+ OPTIONS="${OPTIONS} --edns-payload-size=${EDNSPAYLOADSIZE[$1]}"
+ fi
+ if [ -n "${MAXACTIVEREQUESTS[$1]}" ]; then
+ OPTIONS="${OPTIONS} --max-active-requests=${MAXACTIVEREQUESTS[$1]}"
+ fi
+ if [ "${TCPONLY[$1]}" == "yes" ]; then
+ OPTIONS="${OPTIONS} --tcp-only"
+ fi
+ if [ -n "${PLUGINS[$1]}" ]; then
+ for plugin in ${PLUGINS[$1]}
+ do
+ OPTIONS="${OPTIONS} --plugin=${plugin}"
+ done
+ fi
+ if [ -n "${LOGLEVEL[$1]}" ]; then
+ OPTIONS="${OPTIONS} --loglevel=${LOGLEVEL[$1]}"
+ fi
+ if [ -n "${LOGFILE[$1]}" ]; then
+ OPTIONS="${OPTIONS} --logfile=${LOGFILE[$1]}"
+ fi
+ $DAEMON $OPTIONS
+}
+
+stop_instance() {
+ if [ -z ${PIDFILE[$1]} ]; then
+ echo "No configuration for instance $1 found!"
+ return
+ fi
+ if [ ! -r ${PIDFILE[$1]} ]; then
+ echo "dnscrypt-proxy (instance $1) is not running!"
+ return
+ fi
+ echo "Stopping dnscrypt-proxy (instance $1)..."
+ kill $(cat ${PIDFILE[$1]})
+}
+
+status_instance() {
+ if [ -z ${PIDFILE[$1]} ]; then
+ echo "No configuration for instance $1 found!"
+ return
+ fi
+ if [ ! -r ${PIDFILE[$1]} ]; then
+ echo "dnscrypt-proxy (instance $1) is not running."
+ return
+ fi
+ PID=$(cat ${PIDFILE[$1]})
+ if [ -z "$PID" ]; then
+ echo "PID file is empty! dnscrypt-proxy (instance $1) does not appear to be running, but there is a stale PID file."
+ elif kill -0 $PID ; then
+ echo "dnscrypt-proxy (instance $1) is running."
+ else
+ echo "dnscrypt-proxy (instance $1) is not running, but there is a stale PID file."
+ fi
+}
+
+start() {
+ for i in `/usr/bin/seq 0 $((${#PIDFILE[@]}-1))`
+ do
+ start_instance $i
+ done
+}
+
+stop() {
+ for i in `/usr/bin/seq 0 $((${#PIDFILE[@]}-1))`
+ do
+ stop_instance $i
+ done
+}
+
+status() {
+ for i in `/usr/bin/seq 0 $((${#PIDFILE[@]}-1))`
+ do
+ status_instance $i
+ done
+}
+
+case "$1" in
+ 'start')
+ start
+ ;;
+ 'stop')
+ stop
+ ;;
+ 'restart')
+ stop
+ start
+ ;;
+ 'status')
+ status
+ ;;
+ *_start)
+ INSTANCE=`echo $1 | /bin/cut -d '_' -f 1`
+ start_instance $INSTANCE
+ ;;
+ *_stop)
+ INSTANCE=`echo $1 | /bin/cut -d '_' -f 1`
+ stop_instance $INSTANCE
+ ;;
+ *_restart)
+ INSTANCE=`echo $1 | /bin/cut -d '_' -f 1`
+ stop_instance $INSTANCE
+ sleep 1
+ start_instance $INSTANCE
+ ;;
+ *_status)
+ INSTANCE=`echo $1 | /bin/cut -d '_' -f 1`
+ status_instance $INSTANCE
+ ;;
+ *)
+ echo "Usage: $0 {start|stop|restart|status|#_start|#_stop|#_restart}"
+ exit 1
+ ;;
+esac