This repository has been archived by the owner on Aug 28, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
aaService.bash
executable file
·221 lines (170 loc) · 5.37 KB
/
aaService.bash
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
#!/bin/bash
#
# Copyright (c) 2016 - Present Jeong Han Lee
# Copyright (c) 2016 - Present European Spallation Source ERIC
#
# The program is free software: you can redistribute
# it and/or modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation, either version 2 of the
# License, or any newer version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along with
# this program. If not, see https://www.gnu.org/licenses/gpl-2.0.txt
#
# Author : Jeong Han Lee
# email : han.lee@esss.se
# Date :
# version : 0.9.8-rc0
#
#
ROOT_UID=0
E_NOTROOT=101
declare -gr SC_SCRIPT="$(realpath "$0")"
declare -gr SC_TOP="$(dirname "$SC_SCRIPT")"
declare -gr SC_LOGDATE="$(date +%Y%b%d-%H%M-%S%Z)"
# Enable core dumps in case the JVM fails
ulimit -c unlimited
function startTomcatAtLocation() {
if [ $# -eq 0 ]; then
printf "startTomcatAtLocation called without any arguments\n";
exit 1;
fi
local SERVICE_TOP=$1;
local SERVICE_NAME=$2;
export CATALINA_HOME=$TOMCAT_HOME
export CATALINA_BASE=${SERVICE_TOP}/${SERVICE_NAME};
echo ""
echo ">> Starting TOMCAT at ${CATALINA_BASE}"
pushd ${CATALINA_BASE}/logs
# ${CATALINA_HOME}/bin/jsvc \
# JSVC re-exec requires execution with an absolute or relative path
/bin/jsvc \
-server \
-user ${TOMCAT_USER} \
-cp ${CLASS_PATH}/apache-commons-daemon.jar:${CATALINA_HOME}/bin/bootstrap.jar:${CATALINA_HOME}/bin/tomcat-juli.jar \
${JAVA_OPTS} \
-Dcatalina.base=${CATALINA_BASE} \
-Dcatalina.home=${CATALINA_HOME} \
-cwd ${CATALINA_BASE}/logs \
-outfile ${CATALINA_BASE}/logs/${SERVICE_NAME}_catalina.out \
-errfile ${CATALINA_BASE}/logs/${SERVICE_NAME}_catalina.err \
-pidfile ${CATALINA_BASE}/pid \
org.apache.catalina.startup.Bootstrap start
popd
# make sure, ${TOMCAT_USER} can write something in ${CATALINA}/logs
chown -R ${TOMCAT_USER}.${TOMCAT_GROUP} ${CATALINA_BASE}/logs
# An user with ${TOMCAT_CROUP} can stop the service in the following
# chown ${TOMCAT_USER}.${TOMCAT_GROUP} ${CATALINA_BASE}/pid
chmod 640 ${CATALINA_BASE}/logs/${SERVICE_NAME}_catalina.out
chmod 640 ${CATALINA_BASE}/logs/${SERVICE_NAME}_catalina.err
echo ""
}
function stopTomcatAtLocation() {
if [ $# -eq 0 ]; then
printf "stopTomcatAtLocation called without any arguments\n";
exit 1;
fi
local SERVICE_TOP=$1;
local SERVICE_NAME=$2;
export CATALINA_HOME=$TOMCAT_HOME
export CATALINA_BASE=${SERVICE_TOP}/${SERVICE_NAME};
echo ""
echo "<< Stopping Tomcat at ${CATALINA_BASE}"
pushd ${CATALINA_BASE}/logs
/bin/jsvc \
-stop \
-pidfile ${CATALINA_BASE}/pid \
org.apache.catalina.startup.Bootstrap
popd
echo ""
}
# Service order is matter, don't change them
tomcat_services=("mgmt" "engine" "etl" "retrieval")
function status() {
printf "\n>>>> EPICS Env outputs\n";
printf " EPICS_BASE %s\n" "${EPICS_BASE}";
printf " LD_LIBRARY_PATH %s\n" "${LD_LIBRARY_PATH}";
printf " EPICS_CA_ADDR_LIST %s\n" "${EPICS_CA_ADDR_LIST}";
printf "\n";
systemctl is-active firewalld >/dev/null 2>&1 && printf "\n>>>> FIREWALLD IS RUNNING!!!! IS IT RIGHT?\n"
printf "\n";
printf ">>>> Status outputs \n" ;
printf " > Web url \n";
printf " http://%s:17665/mgmt/ui/index.html\n" "${_HOST_NAME}";
printf " OR\n";
printf " http://%s:17665/mgmt/ui/index.html\n" "${_HOST_IP}";
printf "\n";
printf " > Log \n";
printf " %s/mgmt/logs/mgmt_catalina.err may help you.\n" "${ARCHAPPL_TOP}";
printf " tail -f %s/mgmt/logs/mgmt_catalina.err\n" "${ARCHAPPL_TOP}";
printf "\n";
printf " > jsvc pid :If eight numbers are printed below, the jsvc processes are running\n";
/sbin/pidof jsvc.exec;
printf "\n";
}
function stroage_status() {
local all=$1
printf "\n>>>> Stroage Status at %s\n\n" "${SC_LOGDATE}";
du --total --human-readable --time --${all} ${ARCHAPPL_STORAGE_TOP};
printf "\n";
}
function stop() {
checkIfRoot;
# Stopping order is matter!
stopTomcatAtLocation "${ARCHAPPL_TOP}" "engine";
stopTomcatAtLocation "${ARCHAPPL_TOP}" "retrieval";
stopTomcatAtLocation "${ARCHAPPL_TOP}" "etl";
stopTomcatAtLocation "${ARCHAPPL_TOP}" "mgmt";
status;
}
function start() {
checkIfArchappl
checkIfRoot;
for service in ${tomcat_services[@]}; do
startTomcatAtLocation "${ARCHAPPL_TOP}" "${service}";
done
status;
}
. ${SC_TOP}/functions
. ${SC_TOP}/setEnvAA.bash
if [[ ! -d ${TOMCAT_HOME} ]]; then
echo "Unable to determine the source of the tomcat distribution"
exit 1
fi
if [[ ! -f ${ARCHAPPL_APPLIANCES} ]]; then
echo "Unable to find appliances.xml at ${ARCHAPPL_APPLIANCES}"
exit 1
fi
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
status)
status
;;
stroage)
case "$2" in
all)
stroage_status "$2"
;;
*)
stroage_status
;;
esac
;;
*)
echo "Usage: $0 {start|stop|restart|status|stroage}"
exit 2
esac