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

START=90
STOP=10

NGINX_BIN=/usr/sbin/nginx
NGINX_CONFIG=/etc/portal_mgmt/nginx.conf 
. /usr/lib/portal_mgmt/portal_status.sh

start(){
	try_to_start_daemon
}

stop(){
    #fix security bugs, reject connections to localhost:4433
    #vnete iptables -t filter -w -D INPUT -m mark ! --mark 0x10000000/0x10000000 -p tcp --dport 4433 -j REJECT
	vnete iptables -t raw -w -D PREROUTING -m set --match-set VMe dst -p tcp --dport 4433 -j DROP 2>/dev/null
	vnete iptables -t nat -w -D PREROUTING -m mark --mark 0x10000000/0x10000000 -p tcp --dport 443 -j REDIRECT --to-ports 4433 2>/dev/null
	[ -f "/tmp/nginx.pid" ] &&  kill -QUIT $(cat /tmp/nginx.pid)
	
	pid=$(ps | grep "portal_mgmt_mon" | grep -v grep | awk '{print $1}')
	[ "$pid" != "" ] && kill -9 $pid
}

shutdown() {
    #fix security bugs, reject connections to localhost:4433
    #vnete iptables -t filter -w -D INPUT -m mark ! --mark 0x10000000/0x10000000 -p tcp --dport 4433 -j REJECT
	vnete iptables -t raw -w -D PREROUTING -m set --match-set VMe dst -p tcp --dport 4433 -j DROP 2>/dev/null
	vnete iptables -t nat -w -D PREROUTING -m mark --mark 0x10000000/0x10000000 -p tcp --dport 443 -j REDIRECT --to-ports 4433 2>/dev/null
	[ -f "/tmp/nginx.pid" ] &&  kill -QUIT $(cat /tmp/nginx.pid)
	
	pid=$(ps | grep "portal_mgmt_mon" | grep -v grep | awk '{print $1}')
	[ "$pid" != "" ] && kill -9 $pid
}

reload(){
	stop
	start
}
