Last active
December 17, 2015 06:48
-
-
Save huafengw/1796edb070343f0feec7 to your computer and use it in GitHub Desktop.
Simple script for Gearpump deploy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can try pssh and pscp to make life easier.