sed命令修改tomcat配置文件,并重启应用生效
channelFile=./spring-dubbo.xml
restartApp=./restartServer.sh
usage()
{
echo -e "Usage: `basename $0` [enable|disable]\nNotice: please execute with root or sudo privilege user"
exit -1
}
enable_mock()
{
chattr -i $1
#去掉渠道mock,去掉版本号
sed -i "/<dubbo:reference id=\"iChannelRefundService\" interface=\"com.jdpay.channel.refund.service.api.service.IChannelRefundService\"/{n;s# version=\"1.0\"##g}" $1
#配置渠道mock,添加版本号
sed -i "/<dubbo:reference id=\"iChannelRefundService\" interface=\"com.jdpay.channel.refund.service.api.service.IChannelRefundService\"/{n;s#\(timeout=\"12000\"\)/>#\1 version=\"1.0\"/>#g}" $1
chattr +i $1
echo "disable mock success"
}
disable_mock()
{
chattr -i $1
#去掉渠道mock,去掉版本号
sed -i "/<dubbo:reference id=\"iChannelRefundService\" interface=\"com.jdpay.channel.refund.service.api.service.IChannelRefundService\"/{n;s# version=\"1.0\"##g}" $1
chattr +i $1
echo "disable_mock success"
}
[ $# -lt 1 ] && usage
case $1 in
e|enable|Enable|ENABLE)
enable_mock $channelFile
;;
d|disable|Disable|DISABLE)
disable_mock $channelFile
;;
*)
usage
;;
esac
restartApp