2017-10-13 13:29:51 -07:00
|
|
|
#!/bin/bash
|
|
|
|
set -e
|
|
|
|
|
|
|
|
############# variables ################
|
|
|
|
|
|
|
|
user=`whoami`
|
|
|
|
process=false
|
|
|
|
|
|
|
|
########################################
|
|
|
|
|
|
|
|
# deploys latest bitcore to application servers over ssh
|
|
|
|
|
|
|
|
if [ -z "${1}" ]; then
|
|
|
|
echo 'no server file given, exiting.'
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
green="\033[38;5;40m"
|
|
|
|
magenta="\033[38;5;200m"
|
2017-10-16 14:44:08 -07:00
|
|
|
lightGreen="\033[38;5;112m"
|
|
|
|
white="\033[38;5;231m"
|
|
|
|
mustard="\033[38;5;214m"
|
|
|
|
grey="\033[38;5;7m"
|
2017-10-13 13:29:51 -07:00
|
|
|
reset="\033[0m"
|
2017-10-16 14:44:08 -07:00
|
|
|
ssh="ssh -tt -l${user} -p"
|
|
|
|
|
|
|
|
|
2017-10-13 13:29:51 -07:00
|
|
|
|
|
|
|
function execCmd() {
|
|
|
|
echo -e ${green}$cmd${reset}
|
|
|
|
echo "-------------------------------------------------"
|
|
|
|
if [ "${process}" = true ]; then
|
|
|
|
eval "${sshCmd}\"${cmd}\""
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function deploy () {
|
|
|
|
|
|
|
|
# stop the server
|
|
|
|
cmd="sudo service bitcored stop"
|
|
|
|
execCmd
|
|
|
|
|
|
|
|
# run npm install -g bitcore@beta
|
|
|
|
cmd="sudo su - bitcore -c 'npm install -g bitcore@beta'"
|
|
|
|
execCmd
|
|
|
|
|
|
|
|
# start server
|
|
|
|
cmd="sudo service bitcored start"
|
|
|
|
execCmd
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-16 14:44:08 -07:00
|
|
|
function monitor () {
|
|
|
|
|
|
|
|
eval "${sshCmd}\"${logCmd}\"" &
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function closeout () {
|
|
|
|
|
|
|
|
PGID=$(ps -o pgid= $$ | grep -o [0-9]*)
|
|
|
|
kill -- -$PGID
|
|
|
|
exit 0
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
trap "closeout" SIGINT SIGTERM
|
2017-10-13 13:29:51 -07:00
|
|
|
|
|
|
|
while IFS='' read -r server || [[ -n "$server" ]]; do
|
2017-10-16 14:44:08 -07:00
|
|
|
if [[ "${server}" =~ ^\s*# ]]; then
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
2017-10-13 13:29:51 -07:00
|
|
|
echo "deploying to: $server"
|
2017-10-16 14:44:08 -07:00
|
|
|
|
2017-10-13 13:29:51 -07:00
|
|
|
IFS=':' read -ra url <<< "${server}"
|
2017-10-16 14:44:08 -07:00
|
|
|
|
2017-10-13 13:29:51 -07:00
|
|
|
port="${url[1]}"
|
|
|
|
host="${url[0]}"
|
|
|
|
logType="${url[2]}"
|
2017-10-16 14:44:08 -07:00
|
|
|
|
2017-10-13 13:29:51 -07:00
|
|
|
if [ -z "${port}" ]; then
|
|
|
|
port=22
|
|
|
|
fi
|
2017-10-16 14:44:08 -07:00
|
|
|
|
2017-10-13 13:29:51 -07:00
|
|
|
if [ -z "${logType}" ]; then
|
|
|
|
logCmd="sudo journalctl -f"
|
|
|
|
else
|
2017-10-16 14:44:08 -07:00
|
|
|
logCmd="sudo tail -f /var/log/upstart/bitcored_testnet_new.log"
|
2017-10-13 13:29:51 -07:00
|
|
|
fi
|
2017-10-16 14:44:08 -07:00
|
|
|
|
2017-10-13 13:29:51 -07:00
|
|
|
sshCmd="${ssh}${port} ${host} "
|
2017-10-16 14:44:08 -07:00
|
|
|
|
|
|
|
monitor
|
2017-10-13 13:29:51 -07:00
|
|
|
deploy
|
2017-10-16 14:44:08 -07:00
|
|
|
|
|
|
|
sleep 10
|
2017-10-13 13:29:51 -07:00
|
|
|
done < "$1"
|
|
|
|
|
2017-10-16 14:44:08 -07:00
|
|
|
sleep 240
|
|
|
|
closeout
|