update_fx_config.sh 3.46 KB
#!/bin/bash

if [[ $# == 2 ]]
then
	type=slave
	slave_int_ip=$1
	master_int_ip=$2
elif [[ $# == 3 ]]
then
	type=master
	master_ext_ip=$1
	master_int_ip=$2
	plat_ip=$3
else
	echo Update Config ERROR!
	exit 0
fi
master_int_short=`egrep -o [0-9]+.[0-9]+$ <<< $master_int_ip`

update_slave(){
	slave_type='slave-'$master_int_short
	if [[ `cat /proc/net/dev|egrep -o eth1`	&& `grep ^if /root/UserApp/Daemon/start.sh|grep eth1` ]]
	then
		#sed -i '/.\/OpsDaemon/a \\n=====' /root/UserApp/Daemon/start.sh
		#sed -i '/^else/a \\n=====' /root/UserApp/Daemon/start.sh
		#sed -i '/=====/,/=====/s/^/#/' /root/UserApp/Daemon/start.sh
		#sed -i '/^fi/,$s/^/#/' /root/UserApp/Daemon/start.sh
		mv /root/UserApp/Daemon/start.sh /root/UserApp/Daemon/start.sh.bk
		echo -e '#!/bin/bash\n\ncd /root/UserApp/Daemon\nchmod +x OpsDaemon.sh\n./OpsDaemon.sh &\n\ncd /root/UserApp/Daemon\nchmod +x AnalysisDaemon.sh\n./AnalysisDaemon.sh &' > /root/UserApp/Daemon/start.sh
		chmod +x /root/UserApp/Daemon/start.sh
		cp /root/UserApp/vioncfg/Ops/ServerConfig_slave.xml /root/UserApp/vioncfg/Ops/ServerConfig.xml
		pkill -9 mediaSvr
		pkill -9 MediaServer
		pkill -9 dataExport
		pkill -9 DataExport
		pkill -9 OpeateServer
		pkill -9 Nginx
		/root/UserApp/Daemon/AnalysisDaemon.sh
	fi
	
	sed -i "1s/[0-9]\+.[0-9]\+.[0-9]\+.[0-9]\+/$slave_int_ip/" /root/UserApp/vioncfg/VAServer_System.xml
	sed -i "2,\$s/<IP>[0-9]\+.[0-9]\+.[0-9]\+.[0-9]\+/<IP>$master_int_ip/" /root/UserApp/vioncfg/VAServer_System.xml
	sed -i "s/>2</>10</2" /root/UserApp/vioncfg/VAServer_System.xml
	sed -i "1,/>8851</s/[0-9]\+.[0-9]\+.[0-9]\+.[0-9]\+/$master_int_ip/" /root/UserApp/vioncfg/Ops/ServerConfig.xml
	sed -i "s/deviceType1/$slave_type/" /root/UserApp/vioncfg/Ops/ServerConfig.xml
	sed -i "/<NTP/,/<NTP/s/[0-9]\+.[0-9]\+.[0-9]\+.[0-9]\+<\/NTP/$master_int_ip<\/NTP/" /root/UserApp/vioncfg/Ops/ServerConfig.xml
	pkill -9 VAServer
	pkill -9 OpeateServer
}


update_master(){
	master_type='master-'$master_int_short
	sed -i "1,/>8851</s/[0-9]\+.[0-9]\+.[0-9]\+.[0-9]\+/$plat_ip/" /root/UserApp/vioncfg/Ops/ServerConfig.xml
	sed -i "/<DNS/,/<\/DNS/s/IP>[0-9]\+.[0-9]\+.[0-9]\+.[0-9]\+/IP>$master_ext_ip/1" /root/UserApp/vioncfg/Ops/ServerConfig.xml
	sed -i "/<DNS/,/<\/DNS/s/IP>[0-9]\+.[0-9]\+.[0-9]\+.[0-9]\+/IP>$master_int_ip/2" /root/UserApp/vioncfg/Ops/ServerConfig.xml
	sed -i "/<NTP/,\$s/[0-9]\+.[0-9]\+.[0-9]\+.[0-9]\+<\/NTP/$plat_ip<\/NTP/" /root/UserApp/vioncfg/Ops/ServerConfig.xml
	sed -i "s/deviceType1/$master_type/" /root/UserApp/vioncfg/Ops/ServerConfig.xml
	sed -i "/<ip>/,/<port>/s/[0-9]\+.[0-9]\+.[0-9]\+.[0-9]\+/$master_int_ip/" /root/UserApp/vioncfg/DataExportService/DataExportConfig.xml
	sed -i "s/<configServIp>[0-9]\+.[0-9]\+.[0-9]\+.[0-9]\+/<configServIp>$plat_ip/" /root/UserApp/vioncfg/DataExportService/DataExportConfig.xml
	sed -i "s/<LocalIp>[0-9]\+.[0-9]\+.[0-9]\+.[0-9]\+/<LocalIp>$master_ext_ip/" /root/UserApp/vioncfg/MediaServer/mediaServer.xml
	sed -i "s/<ServerIp>[0-9]\+.[0-9]\+.[0-9]\+.[0-9]\+/<ServerIp>$plat_ip/" /root/UserApp/vioncfg/MediaServer/mediaServer.xml
        if [[ -f /etc/haproxy/haproxy.cfg_ ]]
        then
            sed -i "/videoupload/,/server/s/ [0-9]\+.[0-9]\+.[0-9]\+.[0-9]\+/ $plat_ip/" /etc/haproxy/haproxy.cfg
            service haproxy restart
        fi
	pkill -9 OperateServer
	pkill -9 DataExport
	pkill -9 MediaServer
}


if [[ $type == slave ]]
then
	update_slave
	echo "子节点($slave_int_ip)配置更新完成!"
elif [[ $type == master ]]
then
	update_master
	echo "主节点($master_int_ip)配置更新完成!"
fi