-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathinstall_multi_version_tomcat.sh
More file actions
81 lines (66 loc) · 2.16 KB
/
install_multi_version_tomcat.sh
File metadata and controls
81 lines (66 loc) · 2.16 KB
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
#!/usr/bin/env bash
usage() {
echo Usage: $0 "
Below are the options
Options:
-v Provide version you wish to install and configure in server?(eg: bash $0 -v 8 or -v 9)
"
}
DIR="/opt/tomcat"
APP_USER="tomcat"
APP_VERSION_9="http://www-us.apache.org/dist/tomcat/tomcat-9/v9.0.27/bin/apache-tomcat-9.0.27.tar.gz"
APP_VERSION_8="http://www-us.apache.org/dist/tomcat/tomcat-8/v8.5.47/bin/apache-tomcat-8.5.47.tar.gz"
function INSTALL_TOMCAT() {
APP_VER=$1
yum install java curl wget vim -y
mkdir -p ${DIR}
useradd -s /bin/false -d ${DIR} ${APP_USER}
wget ${APP_VER} && \
tar xzvf $(basename ${APP_VER}) -C ${DIR} --strip-components=1
chown -R ${APP_USER}:${APP_USER} ${DIR}
chmod -R g+rx ${DIR}/conf
cat <<! >> /etc/systemd/system/tomcat.service
[Unit]
Description=Apache Tomcat Web Application Container
After=network.target
[Service]
Type=forking
Environment=JAVA_HOME=$(dirname $(dirname $(readlink -f $(which java))))
Environment=CATALINA_Home=/opt/tomcat
Environment=CATALINA_BASE=/opt/tomcat
Environment='CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC'
Environment='JAVA_OPTS=-Djava.awt.headless=true -Djava.security.egd=file:/dev/./urandom'
ExecStart=/opt/tomcat/bin/startup.sh
ExecStop=/opt/tomcat/bin/shutdown.sh
User=${APP_USER}
Group=${APP_USER}
UMask=0007
RestartSec=10
Restart=always
[Install]
WantedBy=multi-user.target
!
}
[ $# -eq 0 ] && usage && exit 1
while getopts "v:h" option; do
case $option in
v)
version=${OPTARG}
case $version in
8)
INSTALL_TOMCAT ${APP_VERSION_8}
[ $? -eq 0 ] && systemctl daemon-reload && \
systemctl enable ${APP_USER} && systemctl start ${APP_USER}
;;
9)
INSTALL_TOMCAT ${APP_VERSION_9}
[ $? -eq 0 ] && systemctl daemon-reload && \
systemctl enable ${APP_USER} && systemctl start ${APP_USER}
;;
esac
;;
h)
usage
;;
esac
done