1 |
#!/bin/bash |
2 |
# |
3 |
# This script provides systemd activation of the tomcat service |
4 |
# To create clones of this service: |
5 |
# 1) SERVICE_NAME must be defined before calling this script |
6 |
# 2) Create /etc/sysconfig/${SERVICE_NAME} from /etc/sysconfig/tomcat |
7 |
# to override tomcat defaults |
8 |
|
9 |
# SERVICE_NAME is a required value only if the service name is |
10 |
# different from 'tomcat' |
11 |
# |
12 |
export NAME="${SERVICE_NAME:-tomcat}" |
13 |
|
14 |
#I'll bet this isn't required. |
15 |
# unset ISBOOT |
16 |
|
17 |
# For SELinux we need to use 'runuser' not 'su' |
18 |
if [ -x "/sbin/runuser" ]; then |
19 |
SU="/sbin/runuser -s /bin/sh" |
20 |
else |
21 |
SU="/bin/su -s /bin/sh" |
22 |
fi |
23 |
|
24 |
# Path to the tomcat launch script |
25 |
TOMCAT_SCRIPT="/usr/sbin/tomcat" |
26 |
|
27 |
# Define the tomcat username |
28 |
TOMCAT_USER="${TOMCAT_USER:-tomcat}" |
29 |
|
30 |
# TOMCAT_LOG should be different from catalina.out. |
31 |
# Usually the below config is all that is necessary |
32 |
TOMCAT_LOG=/var/log/${NAME}/${NAME}-sysd.log |
33 |
|
34 |
# Get the tomcat config (use this for environment specific settings) |
35 |
TOMCAT_CFG="/etc/tomcat/tomcat.conf" |
36 |
if [ -r "$TOMCAT_CFG" ]; then |
37 |
. $TOMCAT_CFG |
38 |
fi |
39 |
|
40 |
# Get instance specific config file |
41 |
if [ -r "/etc/sysconfig/${NAME}" ]; then |
42 |
. /etc/sysconfig/${NAME} |
43 |
fi |
44 |
|
45 |
# See how we were called. |
46 |
function start() { |
47 |
# fix permissions on the log and pid files |
48 |
export CATALINA_PID="/var/run/${NAME}.pid" |
49 |
|
50 |
touch $TOMCAT_LOG 2>&1 |
51 |
if [ "$?" -eq "0" ]; then |
52 |
chown ${TOMCAT_USER}:${TOMCAT_USER} $TOMCAT_LOG |
53 |
fi |
54 |
|
55 |
if [ "$SECURITY_MANAGER" = "true" ]; then |
56 |
${TOMCAT_SCRIPT} start-security >> $TOMCAT_LOG 2>&1 |
57 |
else |
58 |
${TOMCAT_SCRIPT} start #>> $TOMCAT_LOG 2>&1 |
59 |
fi |
60 |
} |
61 |
|
62 |
function stop() { |
63 |
${TOMCAT_SCRIPT} stop >> $TOMCAT_LOG 2>&1 |
64 |
} |
65 |
|
66 |
# See how we were called. |
67 |
case "$1" in |
68 |
start) |
69 |
start |
70 |
;; |
71 |
stop) |
72 |
stop |
73 |
;; |
74 |
restart) |
75 |
stop |
76 |
start |
77 |
;; |
78 |
esac |
79 |
|