-
Notifications
You must be signed in to change notification settings - Fork 5
/
deploy-moosehead.sh
executable file
·85 lines (67 loc) · 1.96 KB
/
deploy-moosehead.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/bin/bash
BASEDIR=$(cd -P -- "$(dirname -- "$0")" && pwd -P)
# resolve symlinks
while [ -h "$BASEDIR/$0" ]; do
DIR=$(dirname -- "$BASEDIR/$0")
SYM=$(readlink $BASEDIR/$0)
BASEDIR=$(cd $DIR && cd $(dirname -- "$SYM") && pwd)
done
cd ${BASEDIR}
# --------------------------------------
set -e
yellow() { echo -e "\033[33m$1\033[0m"; }
green() { echo -e "\033[32m$1\033[0m"; }
red() { echo -e "\033[31m$1\033[0m"; }
bold() { echo -e "\033[1;37m$1\033[0m"; }
_fancymessage() {
echo ""
green "\033[32m--> $1 \033[0m"
}
info() { bold "$1"; }
ask() { _fancymessage "$1"; }
fail() { red "$1"; exit 1; }
# read -i funker ikke på OSX - derav mer kronglete løsning :(
_readWithDefault() {
local default=$1
read answer
if [ "$answer" = "" ]; then
answer="$default"
fi
echo $answer
}
info "BYGGER"
mvn clean install
yellow ""
yellow " deployer moosehead"
yellow ""
DEFAULT_JAR=`find . -name *jar-with-dependencies.jar`
DEFAULT_WAR=`find . -name *.war`
DEFAULT_VERSION=`date +%Y%m%d%H%M%S`-SNAPSHOT
ask "Hvor ligger jar-filen? [$DEFAULT_JAR]"
JAR=$(_readWithDefault $DEFAULT_JAR)
ask "Hvilken versjon? [$DEFAULT_VERSION]"
VERSION=$(_readWithDefault $DEFAULT_VERSION)
ask "Til test eller prod? [test]"
ENV=$(_readWithDefault "test")
if [ ! -f $JAR ]; then
fail "Fant ikke $JAR :("
fi
if [ $ENV != "test" -a $ENV != "prod" ]; then
fail "Miljø må være enten 'test' eller 'prod'"
fi
if [ $ENV == "prod" ]; then
HOST="javazone.no"
BASE="/home/javabin/web/moosehead"
elif [ $ENV == "test" ]; then
HOST="test.javazone.no"
BASE="/home/javabin/web/moosehead"
else
fail "Det du sa gav null mening!"
fi
info "Deployer til $EVN på $HOST:$BASE med versjon $VERSION med jar $JAR og war $WAR"
ssh javabin@$HOST "mkdir -p $BASE/$VERSION"
info "Laster opp jar"
scp $JAR javabin@$HOST:$BASE/$VERSION/moosehead.jar
ssh javabin@$HOST "ln -s -f $VERSION -T $BASE/current"
ssh javabin@$HOST "$BASE/moosehead.sh stop"
ssh javabin@$HOST "$BASE/moosehead.sh start"