#!/bin/sh /etc/rc.common

######################################################################
#
# Function  : Run adbyby in RAM
#
# Creater   : ywb94@qq.com, 2017-02-13
#
# Copyright : yushi studio
#
######################################################################

START=80

start() {
#不重复启动
icount=`ps -w|grep adbyby.sh|grep -v grep|wc -l`
icount2=`netstat -nautp|grep adbyby|grep -v grep|wc -l`

if [ $icount = 0 -a $icount2 = 0 ] ;then
/root/adbyby.sh &
fi

}

stop() {
#确保清除防火墙规则
i=0
icount=`iptables -t nat -L|grep "ports 8118"|wc -l`  
while [ $i -le 10  -a $icount -gt 1 ]  
do 
let i=i+1
iptables -t nat -D PREROUTING -p tcp --dport 80 -j REDIRECT --to-ports 8118
icount=`iptables -t nat -L|grep "ports 8118"|wc -l`  
done


if [ -f /tmp/adbyby/bin/stopadbb ] ;then
cd /tmp/adbyby/bin
./stopadbb 2>/dev/null
fi

}

restart() {
  stop
  start
}
