Skip to content

Instantly share code, notes, and snippets.

@ChinaXing
Created May 30, 2013 03:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ChinaXing/5675601 to your computer and use it in GitHub Desktop.
Save ChinaXing/5675601 to your computer and use it in GitHub Desktop.
Declare relative-Array in bash 4.0
#!/bin/env bash
declare -A COLORS=( ["RED"]=31 ["YELLOW"]=33 )
COLOR_DEFAULT=YELLOW
function c_echo
{
cb="\e[0;${COLORS[${2:-$COLOR_DEFAULT}]};1m"
ce="\e[0m"
echo -e "${cb}$1${ce}"
}
function abort
{
c_echo " Error, abort ! " RED
exit 1
}
HOSTS=$(/home/admin/bin/ngethost pesystemhost@all)
c_echo "hosts : " RED
for h in $HOSTS; do
echo -e "\t$h"
done
c_echo " ------ :) BEGIN to deploy ----- " RED
for h in $HOSTS; do
echo $h
c_echo "1. update code "
ssh -t $h 'cd /home/admin/PeSystem && sudo -u admin git pull '
c_echo "2. restart webserver "
if [ $(curl -s -L -u user:123 \
"http://$h:9001/index.html?processname=mojolicious&action=restart" \
| grep -c "Process mojolicious restarted") -gt 0 ]
then
echo -e "\t Succeed !"
else
echo -e "\t Failure !"
abort
fi
c_echo "3. test webserver "
sleep 1
if [ $(curl -s http://$h:9999/ | grep -c "Taobao PE System") -gt 0 ]
then
echo -e "\t Succeed !"
else
echo -e "\t Failure !"
abort
fi
c_echo "4. Done"
done
c_echo " ------ :) Finished ------- " RED
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment