-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver
executable file
·112 lines (82 loc) · 2.1 KB
/
server
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
#!/usr/bin/env zsh
tomcat="tomcat10"
CATALINAS="${CATALINA_HOME:-/usr/share/$tomcat}"
port=`sudo awk -F'[=" ]+' '/Connector port="(.*)" protocol="HTTP\/1.1"/{print $4}' "$CATALINAS/conf/server.xml"`
deploy() {
project=`grep -P "rootProject.name = '.*'" ./settings.gradle | awk '{print $3}' | awk -F"'" '{print $2}'`
echo "Building project: '$project'"
./gradlew build
if ! [ $? -eq 0 ]; then
exit 1
fi
echo
sudo cp -rf "build/libs/$project.war" "$CATALINAS/webapps"
if ! [ $? -eq 0 ]; then
echo "Could not link $projec.war to $CATALINAS"
exit 1
fi
echo "Linking $project.war done\n"
}
ports=`sudo lsof -i -P -n`
search="grep"
flags="-i"
if ! [ -x "$(command -v rg)" ]; then
search="rg"
flags="-q"
fi
start() {
if echo "$ports" | $search $flags "\*:$port" > /dev/null; then
echo "Server already running on port $port"
exit 1
fi
echo "Starting tomcat server"
sudo /usr/share/$tomcat/bin/startup.sh @> /dev/null
if ! [ $? -eq 0 ]; then
echo "Something went wrong"
exit 1
fi
}
stop() {
if ! echo "$ports" | $search $flags "\*:$port" > /dev/null; then
echo "Server is not running"
exit 1
fi
echo "Shutting down tomcat server"
sudo /usr/share/$tomcat/bin/shutdown.sh @> /dev/null
if ! [ $? -eq 0 ]; then
echo "Something went wrong"
exit 1
fi
}
restart() {
if echo "$ports" | $search $flags "\*:$port" > /dev/null; then
# If Java is running on port $port, stop Tomcat
sudo /usr/share/$tomcat/bin/shutdown.sh @> /dev/null
if ! [ $? -eq 0 ]; then
echo "Something went wrong"
exit 1
fi
fi
# If Java is not running on port $port, start Tomcat
sudo /usr/share/$tomcat/bin/startup.sh @> /dev/null
if ! [ $? -eq 0 ]; then
echo "Something went wrong"
exit 1
fi
}
case "$1" in
push | update | restart | reload)
deploy
echo "Restarting tomcat server"
restart
;;
init | start)
start
;;
stop | shutdown)
stop
;;
*) echo "Nothing was done, bad selection '$1'";;
esac
[ "$project" = "ROOT" ] && project=""
echo "Server running on: http://localhost:$port/$project"