Skip to content

Instantly share code, notes, and snippets.

@huafengw
Last active December 17, 2015 06:48
Show Gist options
  • Save huafengw/1796edb070343f0feec7 to your computer and use it in GitHub Desktop.
Save huafengw/1796edb070343f0feec7 to your computer and use it in GitHub Desktop.
Simple script for Gearpump deploy
#!/bin/bash
alias ssh="ssh -i ~/.ssh/id_rsa";
alias scp="scp -i ~/.ssh/id_rsa";
gearpumpVersion="pack-2.11.5-0.6.2-SNAPSHOT"
gearpumpDir="/root/gearpump-${gearpumpVersion}"
gearpumpPack="/root/gearpump-${gearpumpVersion}.tar.gz"
#cluster="intelidh-01 intelidh-03 intelidh-04 intelidh-06"
cluster="node10 node11 node12 node15"
masters="node10"
ui="node10"
worker_num=1
MASTER_CONFIG=""
function print_usage(){
echo "Usage: deployGearpump.sh COMMAND"
echo " where COMMAND is one of:"
echo " deploy deploy the Gearpump and start Master and Worker"
echo " stop stop all the Master and Worker"
echo " start start Master and Workers"
}
if [ $# = 0 ]; then
print_usage
exit
fi
COMMAND=$1
function deployTar(){
for node in $cluster; do
ssh root@$node "rm -rf ${gearpumpDir}"
ssh root@$node "rm -rf ${gearpumpPack}"
scp /root/gearpump-${gearpumpVersion}.tar.gz root@$node:~
ssh root@$node "tar -zxvf ${gearpumpPack}"
done
ssh root@$ui "rm -rf ${gearpumpDir}"
ssh root@$ui "rm -rf ${gearpumpPack}"
scp /root/gearpump-${gearpumpVersion}.tar.gz root@$ui:~
ssh root@$ui "tar -zxvf ${gearpumpPack}"
}
function startMaster(){
for node in $masters; do
jvmopt="\"\$JAVA_OPTS $MASTER_CONFIG -Dgearpump.hostname=$node\""
ssh root@$node "cd ${gearpumpDir};\\
export JAVA_OPTS=${jvmopt};\\
nohup bin/master -ip $node -port 3000 > master.log &"
done
}
function startUI(){
jvmopt="\"\$JAVA_OPTS $MASTER_CONFIG -Dgearpump.hostname=$ui -Dgearpump.services.host=$ui \""
ssh root@$ui "cd ${gearpumpDir};\\
export JAVA_OPTS=${jvmopt};\\
nohup bin/services > service.log &"
}
function startWorker(){
worker=0
while [ $worker -lt $worker_num ]; do
for node in $cluster; do
jvmopt="\"\$JAVA_OPTS $MASTER_CONFIG -Dgearpump.hostname=$node\""
ssh root@$node "cd ${gearpumpDir};\\
export JAVA_OPTS=${jvmopt};\\
nohup bin/worker > worker${worker}.log &"
done
let worker=$worker+1
done
}
function stopAll(){
for node in $masters; do
ssh root@$node "source /etc/profile; jps -Vv | grep -i 'gearpump' | awk '{print \$1}' | xargs kill"
done
for node in $cluster; do
ssh root@$node "source /etc/profile; jps -Vv | grep -i 'gearpump'| awk '{print \$1}' | xargs kill"
ssh root@$node "source /etc/profile; jps | grep -i 'ActorSystem'| awk '{print \$1}' | xargs kill -9"
done
ssh root@$ui "source /etc/profile; jps -Vv | grep -i 'gearpump'| awk '{print \$1}' | xargs kill"
}
function stopAS(){
for node in $cluster; do
ssh root@$node "source /etc/profile; jps | grep -i 'ActorSystem'| awk '{print \$1}' | xargs kill -9"
done
}
function initConfig(){
index=0
for master in $masters; do
MASTER_CONFIG="$MASTER_CONFIG -Dgearpump.cluster.masters.${index}=$master:3000"
let index=$index+1
done
}
case $COMMAND in
--help|-help|-h)
print_usage
exit
;;
deploy)
initConfig
deployTar
startMaster
sleep 2
startWorker
startUI
exit
;;
start)
initConfig
startMaster
sleep 2
startWorker
startUI
exit
;;
stop)
stopAll
exit
;;
esac
@Renkai
Copy link

Renkai commented Dec 17, 2015

You can try pssh and pscp to make life easier.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment