#!/bin/sh
### BEGIN INIT INFO
# Provides:          pyDNSMASQ
# Required-Start:    $local_fs $network
# Required-Stop:     $local_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: pyDNSMASQ service
# Description:       pyDNSMASQ service
### END INIT INFO

filepath="/etc/pyDNSMASQ/dns_proxy.py"

start(){
    nohup python $filepath $CURRENT_DNS>/dev/null 2>&1 &
    echo 'pyDNS service OK'
}


stop(){
    serverpid=`ps |grep "$filepath"|grep -v grep|awk '{print $1}'`
    kill -9 $serverpid
    echo 'pyDNS stop OK'
}


restart(){
    stop
    echo 'pyDNS stop OK'
    chmod 777 /tmp/dns_start
    /tmp/dns_start
    echo 'pyDNS service OK'
}


case $1 in
    start)
    start
    ;;
    stop)
    stop
    ;;
    restart)
    restart
    ;;
    *)
    start
esac
