Added a deploy script.

This commit is contained in:
Chris Kleeschulte 2017-10-13 16:29:51 -04:00
parent 2f2f4f0809
commit 70f2518409
No known key found for this signature in database
GPG Key ID: 33195D27EF6BDB7F
2 changed files with 73 additions and 0 deletions

2
.gitignore vendored
View File

@ -18,3 +18,5 @@ report
build
tests.js
scripts/servers.*

71
scripts/deploy.sh Normal file
View File

@ -0,0 +1,71 @@
#!/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"
reset="\033[0m"
ssh="ssh -l${user} -p"
function execCmd() {
echo -e ${green}$cmd${reset}
echo "-------------------------------------------------"
if [ "${process}" = true ]; then
eval "${sshCmd}\"${cmd}\""
fi
}
function deploy () {
# start a subshell to monitor the logs
( eval "${sshCmd}\"${logCmd}\"" ) &
child=$!
# 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
}
while IFS='' read -r server || [[ -n "$server" ]]; do
echo "deploying to: $server"
IFS=':' read -ra url <<< "${server}"
port="${url[1]}"
host="${url[0]}"
logType="${url[2]}"
if [ -z "${port}" ]; then
port=22
fi
if [ -z "${logType}" ]; then
logCmd="sudo journalctl -f"
else
logCmd="sudo tail -f /var/log/upstart/bitcored*"
fi
sshCmd="${ssh}${port} ${host} "
deploy
done < "$1"
wait "${child}"