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 $?
页:
[1]