#!/bin/bash
sh ezdpl.sh Y 10.6.1.11 appserver/current Y
sh ezdpl.sh Y 10.6.1.12 appserver/current Y
sh ezdpl.sh Y 10.6.1.13 appserver/current Y
sh ezdpl.sh Y 10.6.1.14 appserver/current Y
sh ezdpl.sh Y 10.6.1.15 appserver/current Y
為了達到并行的目的,auto.sh腳本可以稍加修改,比如:
sh ezdpl.sh Y 10.6.1.11 appserver/current Y > /tmp/10.6.1.11.log &
sh ezdpl.sh Y 10.6.1.12 appserver/current Y > /tmp/10.6.1.12.log &
sh ezdpl.sh Y 10.6.1.13 appserver/current Y > /tmp/10.6.1.13.log &
...
#!/bin/bash
sh ezdpl.sh Y 10.6.1.11 appserver/20151012 Y > /tmp/10.6.1.11.log &
sh ezdpl.sh Y 10.6.1.12 appserver/20151012 Y > /tmp/10.6.1.12.log &
sh ezdpl.sh Y 10.6.1.13 appserver/20151012 Y > /tmp/10.6.1.13.log &
sh ezdpl.sh Y 10.6.1.14 appserver/20151012 Y > /tmp/10.6.1.14.log &
sh ezdpl.sh Y 10.6.1.15 appserver/20151012 Y > /tmp/10.6.1.15.log &
sh ezdpl.sh Y 10.6.1.11 orders/20151018 Y > /tmp/10.6.1.11.log &
sh ezdpl.sh Y 10.6.1.12 orders/20151018 Y > /tmp/10.6.1.12.log &
sh ezdpl.sh Y 10.6.1.13 orders/20151018 Y > /tmp/10.6.1.13.log &
...
sh ezdpl.sh Y 10.6.1.11 orders/20151012 Y > /tmp/10.6.1.11.log &
sh ezdpl.sh Y 10.6.1.12 orders/20151012 Y > /tmp/10.6.1.12.log &
sh ezdpl.sh Y 10.6.1.13 orders/20151012 Y > /tmp/10.6.1.13.log &
...
? 但是,依舊強烈建議在生產(chǎn)環(huán)境實施之前,要做充分的測試。
三、ezdpl.sh 版本1.1 ?
#!/bin/bash
# https://github.com/Panblack/ezdpl
# Check Parameters
#echo $1
#echo $2
#echo $3
#echoif [ -n "$1" ]; then_silent=$1if [ "$_silent" != "Y" ]; thenif [ "$_silent" != "N" ]; thenecho"The first parameter must be Y or N. Exit!"exit 1fifielseecho"silent. Usage: ./ezdpl.sh <Silent Mode Y|N> <ip address>:[port] <app/version> [reboot Y|N(N)] [username(root)]"exit 1fiif [ -n "$2" ]; then#Detailed param check will be needed._ipaddress=$(echo $2|awk -F':''{print $1}')_port=$(echo $2|awk -F':''{print $2}')if [ ${#_port} -eq 0 ]; then_port="22"fielseecho"ipaddress:port. Usage: ./ezdpl.sh <Silent Mode Y|N> <ip address>:[port] <app/version> [reboot Y|N(N)] [username(root)]"exit 1fiif [ -n "$3" ]; then_app_version=$3elseecho"app/version. Usage: ./ezdpl.sh <Silent Mode Y|N> <ip address>:[port] <app/version> [reboot Y|N(N)] [username(root)]"exit 1fi# Optional parameters
if [ -n "$4" ]; then_reboot=$4else_reboot="N"fiif [ -n "$5" ]; then_username=$5else_username="root"fi# Silent mode or not
if [ "$_silent" != "Y" ]; thenechoecho"Ezdpl does things in a raw and simple way."echo"https://github.com/Panblack/ezdpl"echoecho"Will initialize a new server, or deploy apps to a certain server, or upgrade a production server."echo"Usage: ./ezdpl.sh <Silent Mode Y|N> <ip address>:[port] <app/version> [reboot Y|N(N)] [username(root)]"echo"Manually Initialize 10.1.1.1: ./ezdpl.sh N 10.1.1.1 common/current Y"echo"Silently Deploy app_a to 10.1.1.1: ./ezdpl.sh Y 10.1.1.1:22 app_a/current Y root"echo"Silently Upgrade 10.1.1.2's app_a: ./ezdpl.sh Y 10.1.1.2:2222 app_a/20150720"echo"Manually Upgrade 10.1.1.2's conf: ./ezdpl.sh N 10.1.1.2:2222 app_a/2015-10-12"echo# Confirmationread -p "Will overwrite configuration files or apps on $_ipaddress. Enter Y to continue: "if [ "$REPLY" != "Y" ]; thenecho"Exit"exit 0fi# Confirmation againread -p "Are you sure? Enter Y to continue: "if [ "$REPLY" != "Y" ]; thenecho"Exit"exit 0fifi# Check
echo"Target Server: ${_ipaddress}..."ssh -p $_port $_username@$_ipaddress uname > /dev/nullif [ "$?" != "0" ]; thenechoecho"$_ipaddress is not reachable. "exit 1fiif [ ! -d "./$_app_version" ]; thenechoecho"There is no $_app_version configured here !"exit 1fi# Everything seems OK. Go!
# Run pre.sh on the target server
if [ -f "./$_app_version/pre.sh" ]; thenscp -P $_port ./$_app_version/pre.sh $_username@$_ipaddress:/tmp/ssh -p $_port $_username@$_ipaddress sh /tmp/pre.shecho"$_username@$_ipaddress:/tmp/pre.sh executed."fi# Start copy app/version/files/*
if [ -d ./$_app_version/files ]; thenscp -P $_port -r ./$_app_version/files/* $_username@$_ipaddress:/echo "./$_app_version/files/* copied."
fi# Run fin.sh on the target server
if [ -f "./$_app_version/fin.sh" ]; thenscp -P $_port ./$_app_version/fin.sh $_username@$_ipaddress:/tmp/ssh -p $_port $_username@$_ipaddress sh /tmp/fin.shecho "$_username@$_ipaddress:/tmp/fin.sh executed."
fi# Reboot target server.
if [ "$_reboot" = "Y" ]; thenechoecho "Target server will reboot..."echossh -p $_port $_username@$_ipaddress reboot
fi
echo "Target Server: ${_ipaddress} done!"; echo
# End of ezdpl.sh