ICE中间件开发,IceGrid自动化布署Shell脚本封装

#!/bin/sh
#set -x

log_registry=registry.log
log_node=node.log
config_registry=config.grid
config_node=config.node
config_application=application.xml
tmp=

function usage(){
echo "Usage: ./iceserver.sh ( commands ... )"
echo "commands:"
echo " -r|reg Start the IceGrid Registry"
echo " -n Start the IceGrid Node"
echo " -a|app Deploy the IceGrid Application"
echo " -s Start or Stop the IceGrid Server"
echo " -h|help Help the IceGrid"
echo " -v|version Display the IceGrid Version"
echo "other comands:"
echo " application Manage the IceGrid"
echo " node Manage the IceGrid"
echo " registr Manage the IceGrid"
echo " server Manage the IceGrid"
echo " service Manage the IceGrid"
echo " adapter Manage the IceGrid"
echo " object Manage the IceGrid"
echo " server template Manage the IceGrid"
echo " service template Manage the IceGrid"
exit 1
}

function registry(){
if [ $# != 2 ]; then
echo "No registry config file. Please input $0 $1 registry_config_path"
exit 1
fi
if [ ! -f "$2" ] ; then
echo "$2 does not exist"
exit 1
fi
config_registry=$2
tmp=`ps -ef | grep icegridregistry | wc -l`
if [ $tmp -eq 1 ]; then
if [ ! -f "$log_registry" ]; then
touch "$log_registry"
fi
icegridregistry --Ice.Config\="$config_registry" > "$log_registry" &
else
icegridregistry --Ice.Config\="$config_registry" > "$log_registry"
fi

if [ $? -eq 0 ]; then
echo "Start IceGrid Registry Success"
else
echo "The IceGrid Already Registry"
exit 1
fi
}

function node(){
if [ $# != 2 ]; then
echo "No node config file. Please input $0 $1 node_config_path"
exit 1
fi
if [ ! -f "$2" ] ; then
echo "$2 does not exist"
exit 1
fi
config_node=$2
tmp=`ps -ef | grep icegridnode | wc -l`
if [ $tmp -eq 1 ]; then
if [ ! -f "$log_node" ]; then
touch "$log_node"
fi
icegridnode --Ice.Config\="$config_node" > "$log_node" &
else
echo "The IceGrid Node Already Start"
exit 1
fi

if [ $? -eq 0 ]; then
echo "Start IceGrid Node Start Success"
else
echo "The IceGrid NodeAlready Start"
exit 1
fi

}

function application(){
var_application="application"
if [ $# -gt 1 ]; then
shift
icegridadmin --Ice.Config\="$config_registry" -e "$var_application $1 $2 $3 $4 $5 $6 $7 $8 $9"
exit 1
fi

tmp=`icegridadmin --Ice.Config\="$config_registry" -e "application list"`

if [ X"$tmp" = "X" ]; then
icegridadmin --Ice.Config\="$config_registry" -e "application add $config_application"
echo "Add IceGrid Application Success"
else
icegridadmin --Ice.Config\="$config_registry" -e "application update $config_application"
echo "Update IceGrid Application Success"
fi
}

function server(){
var_server="server"
if [ $# -gt 1 ]; then
if [ "$3" = "all" ]; then
if [ "$2" = "start" ]; then
startall
elif [ "$2" = "stop" ]; then
stopall
fi
exit 1
fi

shift
icegridadmin --Ice.Config\="$config_registry" -e "$var_server $1 $2 $3 $4 $5 $6 $7 $8 $9"
exit 1
fi

tmp=`icegridadmin --Ice.Config\="$config_registry" -e "server list"`
for server_id in $tmp; do
icegridadmin --Ice.Config\="$config_registry" -e "server state $server_id"
if [ $? -eq 0 ]; then
echo "$server_id state success"
else
echo "$server_id state fail"
fi
done
}

function startall(){
tmp=`icegridadmin --Ice.Config\="$config_registry" -e "server list"`
for server_id in $tmp; do
icegridadmin --Ice.Config\="$config_registry" -e "server start $server_id"
if [ $? -eq 0 ]; then
echo "$server_id start success"
else
echo "$server_id start fail"
fi
done
}

function stopall(){
tmp=`icegridadmin --Ice.Config\="$config_registry" -e "server list"`
for server_id in $tmp; do
icegridadmin --Ice.Config\="$config_registry" -e "server stop $server_id"
if [ $? -eq 0 ]; then
echo "$server_id stop success"
else
echo "$server_id stop fail"
fi
done
}


function help(){

if [ $# -eq 1 ]; then
shift
icegridadmin --Ice.Config\="$config_registry" -e "help"
fi
}

function all(){

if [ $# -eq 1 ]; then
icegridadmin --Ice.Config\="$config_registry" -e "$1 help"
fi

if [ $# -gt 1 ]; then
icegridadmin --Ice.Config\="$config_registry" -e "$1 $2 $3 $4 $5 $6 $7 $8 $9"
fi
}

case $1 in
-r|reg)
registry $@
;;
-n)
node $@
;;
-a|app)
application $@
;;
-s)
server $@
;;
-h|help)
help $@
;;
-v|version)
echo "The IceGrid version is 3.4.1"
;;
application|node|registry|server|service|adapter|object)
all $@
;;
*)
usage
;;
esac

exit $?
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值