Skip to content

Instantly share code, notes, and snippets.

@ayanamist
Last active December 10, 2015 01:34
Show Gist options
  • Save ayanamist/4358761 to your computer and use it in GitHub Desktop.
Save ayanamist/4358761 to your computer and use it in GitHub Desktop.
OpenDNS DNSCrypt Watch
#!/bin/sh
PIDFILE=/var/run/dnscryptwatch.pid
BINPATH=/usr/sbin/dnscrypt-proxy -a 127.0.0.1:40
DNSCRYPT_PIDFILE=/var/run/dnscrypt.pid
# Check whether script is running, and if running, exit directly
if [ -s $PIDFILE ] && [ -s /proc/$(cat $PIDFILE)/exe ]; then
exit 0
fi
# Fork current script to background daemon
if [ -z "$_BACKGROUNDED" ]; then
_BACKGROUNDED=1 nohup $0 > /var/log/dnscryptwatch 2>&1 &
exit 0
fi
# Main script
echo $$ > $PIDFILE
while :
do
if [ -s $DNSCRYPT_PIDFILE ] && [ -s /proc/$(cat $DNSCRYPT_PIDFILE)/exe ]; then
exit 0
fi
$BINPATH -p $DNSCRYPT_PIDFILE
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment