-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathboot.sh
executable file
·134 lines (119 loc) · 3.74 KB
/
boot.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/bin/bash
# Read configuration
THIS_DIR=$(pwd)
THIS_FILE_NAME="$THIS_DIR"/$(basename "$0")
APP_CONFIG="${THIS_FILE_NAME%.*}.conf"
test -e "$APP_CONFIG" || { echo "$APP_CONFIG not existing";
if [ "$1" = "stop" ]; then exit 0;
else exit 6; fi; }
test -r "$APP_CONFIG" || { echo "$APP_CONFIG not readable. Perhaps you forgot 'sudo'?";
if [ "$1" = "stop" ]; then exit 0;
else exit 6; fi; }
[[ -r "${APP_CONFIG}" ]] && source "${APP_CONFIG}"
if [ "x$APP_NAME" = "x" ]; then
APP_NAME=$(basename "${APP_CONFIG%.*}")
fi
if [ "x$JARFILE" = "x" ]; then
JARFILE=$(basename "${APP_CONFIG%.*}.jar")
fi
LIBRARY_DIR="$THIS_DIR/lib"
LIBRARY_CONFIG="$LIBRARY_DIR"/$(basename "${JARFILE%.*}.conf")
APP_SERVICE_LINK="/etc/init.d/$APP_NAME"
GIT_SOURCES_NAME="git-sources";
# ANSI Colors
echoRed() { echo $'\e[0;31m'"$1"$'\e[0m'; }
echoGreen() { echo $'\e[0;32m'"$1"$'\e[0m'; }
echoYellow() { echo $'\e[0;33m'"$1"$'\e[0m'; }
# Check installed app
isInstalled() { sudo test -r "$APP_SERVICE_LINK" || { echoRed "$APP_NAME not installed"; return 5; } }
# Git Clone
gitClone() {
test -n "$GIT_URL" || { echoRed "You must have to set GIT_URL"; exit 0; }
type -p git > /dev/null 2>&1 || { echoRed "You must have to install GIT"; exit 0; }
GIT_BRANCH="master";
if [[ ! -e "$GIT_SOURCES_NAME" ]]; then
git clone "$GIT_URL" "$GIT_SOURCES_NAME";
echoGreen "Clone from $GIT_URL"
else
cd ./"$GIT_SOURCES_NAME";
git pull origin "$GIT_BRANCH";
cd ..;
echoGreen "Pull from $GIT_URL"
fi
}
gradleBuild() {
cd "./$GIT_SOURCES_NAME";
chmod 755 ./gradlew;
./gradlew clean bootjar;
cd ..;
test -r "$GIT_SOURCES_NAME/build/libs/$JARFILE" || { echoRed "Failed to build '$JARFILE'"; exit 0; }
}
copyLibrary() {
test -r "$LIBRARY_DIR" || { mkdir -p "$LIBRARY_DIR" &> /dev/null }
sudo cp "./$GIT_SOURCES_NAME/build/libs/$JARFILE" "$LIBRARY_DIR/"
}
createService() {
sudo ln -s "$LIBRARY_DIR/$JARFILE" "$APP_SERVICE_LINK"
sudo ln -s "$APP_CONFIG" "$LIBRARY_CONFIG"
sudo chown root:root "$LIBRARY_DIR/$JARFILE"
sudo chown -h root:root "$LIBRARY_CONFIG"
sudo chmod 500 "$LIBRARY_DIR/$JARFILE"
sudo chmod 400 "$LIBRARY_CONFIG"
}
case "$1" in
install)
sudo test -r "$APP_SERVICE_LINK" && { echoGreen "Already installed '$APP_SERVICE_LINK'"; exit 0; }
gitClone;
gradleBuild;
copyLibrary;
createService;
echoGreen "Installed $APP_NAME"
;;
uninstall)
sudo test -r "$APP_SERVICE_LINK" || { echoYellow "$APP_NAME is not installed"; exit 0; }
sudo rm -rf "$APP_SERVICE_LINK";
sudo rm -rf "./$GIT_SOURCES_NAME";
sudo unlink "$LIBRARY_CONFIG"
sudo rm -rf "$LIBRARY_DIR"
echoGreen "Uninstalled $APP_NAME"
;;
deploy)
isInstalled || { exit $?; }
gitClone;
gradleBuild;
copyLibrary;
echoGreen "Deployed $APP_NAME"
;;
start)
isInstalled || { exit $?; }
sudo service "$APP_NAME" start
;;
stop)
isInstalled || { exit $?; }
sudo service "$APP_NAME" stop
;;
force-stop)
isInstalled || { exit $?; }
sudo service "$APP_NAME" force-stop
;;
restart)
isInstalled || { exit $?; }
sudo service "$APP_NAME" restart
;;
force-reload)
isInstalled || { exit $?; }
sudo service "$APP_NAME" force-reload
;;
status)
isInstalled || { exit $?; }
sudo service "$APP_NAME" status
;;
run)
isInstalled || { exit $?; }
sudo service "$APP_NAME" run
;;
*)
echo $"Usage: $0 {deploy|start|stop|force-stop|restart|force-reload|status|run}"
exit 1
esac
exit 0