Created
May 19, 2014 15:31
-
-
Save akiyoshi83/4ec5aaa152e2d0e9a3e8 to your computer and use it in GitHub Desktop.
tiny dns by twisted
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
zone = [ | |
SOA( | |
'example.com', | |
mname = 'ns1.example.com', | |
serial = 2014051901, | |
refresh = '1H', | |
retry = '1H', | |
expire = '1H', | |
minimum = '1H' | |
), | |
# NS Record | |
NS('example.com', 'ns1.example.com'), | |
# A Record | |
A('example.com', '10.0.0.10'), | |
# CNAME Record | |
CNAME('www.example.com', 'example.com') | |
] | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#---------------------------------------- | |
# tiny dns by twisted | |
# | |
# please `yum install python-twisted` | |
#---------------------------------------- | |
user=root | |
cmd=$1 | |
zone=$2 | |
curdir=`dirname $0` | |
pidfile="$curdir/tdns.pid" | |
usage() | |
{ | |
echo "sh tdns.sh {start|stop|restart|status} [ZONEFIEL]" | |
echo "if ZONEFILE omitted, use default.zone." | |
} | |
start() | |
{ | |
if [ -f "$pidfile" ]; then | |
echo "already running..." | |
return 1 | |
fi | |
sudo -u $user twistd --pidfile=$pidfile --syslog dns --recursive --cache --pyzone $zone | |
sleep 1 | |
echo "start tdns pid=`cat $pidfile`" | |
return 0 | |
} | |
stop() | |
{ | |
if [ ! -f "$pidfile" ]; then | |
echo "not running..." | |
return 1 | |
fi | |
echo "stop tdns pid=`cat $pidfile`" | |
sudo -u $user kill `cat $pidfile` | |
sleep 1 | |
} | |
status() | |
{ | |
if [ -f "$pidfile" ]; then | |
echo "running..." | |
return 0 | |
else | |
echo "not running..." | |
return 1 | |
fi | |
} | |
[ -z "$zone" ] && zone="$curdir/default.zone" | |
[ ! -f "$zone" ] && echo "$zone is not found." && exit 1 | |
case $cmd in | |
"start" ) | |
start | |
;; | |
"stop" ) | |
stop | |
;; | |
"restart" ) | |
stop | |
start | |
;; | |
"status" ) | |
status | |
;; | |
* ) | |
usage | |
;; | |
esac | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
REF: http://qiita.com/futoase/items/174883d7fa8d2dd4240a