aboutsummaryrefslogtreecommitdiffstats
path: root/packages/base/src/files/install/servers/common/tomcat/init.d/tomcatd
blob: 114f8a77edfae047a79fac0fab2e392060cbb376 (plain)
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
#!/bin/bash

function update_monitor() {
	COMPONENT=$1
	STATUS=$2
	if [[ -f ${POLICY_HOME}/etc/monitor/monitor.cfg ]]; then
		/bin/sed -i.bak \
			-e "s/^${COMPONENT}=.*/${COMPONENT}=${STATUS}/g" \
			${POLICY_HOME}/etc/monitor/monitor.cfg	
	fi
}

# unmonitored stop, does not change monitor status (immutable)
function um_stop() {
	cd ${TOMCAT_BASE}/bin/
	${TOMCAT_BASE}/bin/catalina.sh stop -force
	
	# make sure ..
	pid=$(pgrep -f -u ${POLICY_USER} "${TOMCAT_RUNNING}" 2> /dev/null)
	RETVAL=$?
	if [[ ${RETVAL} == 0 ]]; then
		pkill -u ${POLICY_USER} -f "${TOMCAT_RUNNING}" -KILL
		RETVAL=$?
	fi
}

function stop() {
	um_stop
	update_monitor ${{COMPONENT_TYPE}} off
}

# unmonitored start, does not change monitor status (immutable)
function um_start() {
	cd ${TOMCAT_BASE}/bin/
	${TOMCAT_BASE}/bin/catalina.sh start
	RETVAL=$?
}

function start() {
	um_start
	if [[ ${RETVAL} != 0 ]]; then
		update_monitor ${{COMPONENT_TYPE}} off
	else
		update_monitor ${{COMPONENT_TYPE}} on
	fi
}

TOMCAT_BASE=${POLICY_HOME}/servers/${{COMPONENT_TYPE}}
TOMCAT_RUNNING="^$JAVA_HOME/bin/java .* -Dcatalina.base=${TOMCAT_BASE} .* start$"

PWD_ENTER=${PWD}
RETVAL=0

. ${POLICY_HOME}/etc/profile.d/env.sh

case "$1" in
    status)
        pid=$(pgrep -f -u ${POLICY_USER} "${TOMCAT_RUNNING}" 2> /dev/null)
        RETVAL=$?
        if [ $RETVAL -eq 0 ]; then
                echo "running with pid ${pid}"
        else
                echo "stopped"
        fi
        ;;
	restart)
	    stop
        sleep 2
        start
        ;;
	start)
        start
        ;;
	umstart)
        um_start
        ;;        
	stop)
        stop
        ;;  
	umstop)
        um_stop
        ;;               
    *)
        cd ${TOMCAT_BASE}/bin/
        ${TOMCAT_BASE}/bin/catalina.sh "$@"
        RETVAL=$?
        ;;
esac

cd ${PWD_ENTER}
exit ${RETVAL}