Skip to content

Commit

Permalink
Replaces grpc_launch_server with grpc_launch_servers
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Emiola committed Feb 4, 2015
1 parent f2c8901 commit 5ebf880
Showing 1 changed file with 44 additions and 36 deletions.
80 changes: 44 additions & 36 deletions tools/gce_setup/grpc_docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -590,63 +590,71 @@ grpc_sync_images() {
done
}

grpc_launch_server_args() {
_grpc_launch_servers_args() {
[[ -n $1 ]] && { # host
host=$1
shift
} || {
echo "$FUNCNAME: missing arg: host" 1>&2
return 1
}

[[ -n $1 ]] && { # server_type
case $1 in
cxx) grpc_port=8010 ;;
go) grpc_port=8020 ;;
java) grpc_port=8030 ;;
node) grpc_port=8040 ;;
python) grpc_port=8050 ;;
ruby) grpc_port=8060 ;;
*) echo "bad server_type: $1" 1>&2; return 1 ;;
esac
docker_label="grpc/$1"
docker_name="grpc_interop_$1"
shift
[[ -n $1 ]] && {
servers="$@"
} || {
echo "$FUNCNAME: missing arg: server_type" 1>&2
return 1
servers="cxx java go node ruby"
echo "$FUNCNAME: no servers specified, will launch defaults '$servers'"
}
}

# Launches a server on a docker instance.
# Launches servers on a docker instance.
#
# call-seq;
# grpc_launch_server <server_name> <server_type>
# grpc_launch_servers <server_name> [server1 server2 ...]
# E.g
# grpc_launch_server grpc-docker-server ruby node
#
# Runs the server_type on a GCE instance running docker with server_name
grpc_launch_server() {
# Restarts all the specified servers on the GCE instance <server_name>
# If no servers are specified, it launches all known servers
grpc_launch_servers() {
# declare vars local so that they don't pollute the shell environment
# where they this func is used.
local grpc_zone grpc_project dry_run # set by _grpc_set_project_and_zone
# set by grpc_launch_server_args
local docker_label docker_name host grpc_port
# set by grpc_launch_servers_args
local servers

# set the project zone and check that all necessary args are provided
_grpc_set_project_and_zone -f grpc_launch_server_args "$@" || return 1
_grpc_set_project_and_zone -f _grpc_launch_server_args "$@" || return 1
gce_has_instance $grpc_project $host || return 1;

cmd="sudo docker kill $docker_name > /dev/null 2>&1; "
cmd+="sudo docker rm $docker_name > /dev/null 2>&1; "
cmd+="sudo docker run -d --name $docker_name"
cmd+=" -p $grpc_port:$grpc_port $docker_label"
local project_opt="--project $grpc_project"
local zone_opt="--zone $grpc_zone"
local ssh_cmd="bash -l -c \"$cmd\""
echo "will run:"
echo " $ssh_cmd"
echo "on $host"
[[ $dry_run == 1 ]] && return 0 # don't run the command on a dry run
gcloud compute $project_opt ssh $zone_opt $host --command "$cmd"
# launch each of the servers in turn
for server in $servers
do
local grpc_port
case $server in
cxx) grpc_port=8010 ;;
go) grpc_port=8020 ;;
java) grpc_port=8030 ;;
node) grpc_port=8040 ;;
python) grpc_port=8050 ;;
ruby) grpc_port=8060 ;;
*) echo "bad server_type: $1" 1>&2; return 1 ;;
esac
local docker_label="grpc/$server"
local docker_name="grpc_interop_$server"

cmd="sudo docker kill $docker_name > /dev/null 2>&1; "
cmd+="sudo docker rm $docker_name > /dev/null 2>&1; "
cmd+="sudo docker run -d --name $docker_name"
cmd+=" -p $grpc_port:$grpc_port $docker_label"
local project_opt="--project $grpc_project"
local zone_opt="--zone $grpc_zone"
local ssh_cmd="bash -l -c \"$cmd\""
echo "will run:"
echo " $ssh_cmd"
echo "on $host"
[[ $dry_run == 1 ]] && return 0 # don't run the command on a dry run
gcloud compute $project_opt ssh $zone_opt $host --command "$cmd"
done
}

# Runs a test command on a docker instance.
Expand Down

0 comments on commit 5ebf880

Please sign in to comment.