Initial OpenECOMP policy/engine commit
[policy/engine.git] / packages / base / src / files / install / servers / common / tomcat / init.d / tomcatd
1 #!/bin/bash
2
3 function update_monitor() {
4         COMPONENT=$1
5         STATUS=$2
6         if [[ -f ${POLICY_HOME}/etc/monitor/monitor.cfg ]]; then
7                 /bin/sed -i.bak \
8                         -e "s/^${COMPONENT}=.*/${COMPONENT}=${STATUS}/g" \
9                         ${POLICY_HOME}/etc/monitor/monitor.cfg  
10         fi
11 }
12
13 # unmonitored stop, does not change monitor status (immutable)
14 function um_stop() {
15         cd ${TOMCAT_BASE}/bin/
16         ${TOMCAT_BASE}/bin/catalina.sh stop -force
17         
18         # make sure ..
19         pid=$(pgrep -f -u ${POLICY_USER} "${TOMCAT_RUNNING}" 2> /dev/null)
20         RETVAL=$?
21         if [[ ${RETVAL} == 0 ]]; then
22                 pkill -u ${POLICY_USER} -f "${TOMCAT_RUNNING}" -KILL
23                 RETVAL=$?
24         fi
25 }
26
27 function stop() {
28         um_stop
29         update_monitor ${{COMPONENT_TYPE}} off
30 }
31
32 # unmonitored start, does not change monitor status (immutable)
33 function um_start() {
34         cd ${TOMCAT_BASE}/bin/
35         ${TOMCAT_BASE}/bin/catalina.sh start
36         RETVAL=$?
37 }
38
39 function start() {
40         um_start
41         if [[ ${RETVAL} != 0 ]]; then
42                 update_monitor ${{COMPONENT_TYPE}} off
43         else
44                 update_monitor ${{COMPONENT_TYPE}} on
45         fi
46 }
47
48 TOMCAT_BASE=${POLICY_HOME}/servers/${{COMPONENT_TYPE}}
49 TOMCAT_RUNNING="^$JAVA_HOME/bin/java .* -Dcatalina.base=${TOMCAT_BASE} .* start$"
50
51 PWD_ENTER=${PWD}
52 RETVAL=0
53
54 . ${POLICY_HOME}/etc/profile.d/env.sh
55
56 case "$1" in
57     status)
58         pid=$(pgrep -f -u ${POLICY_USER} "${TOMCAT_RUNNING}" 2> /dev/null)
59         RETVAL=$?
60         if [ $RETVAL -eq 0 ]; then
61                 echo "running with pid ${pid}"
62         else
63                 echo "stopped"
64         fi
65         ;;
66         restart)
67             stop
68         sleep 2
69         start
70         ;;
71         start)
72         start
73         ;;
74         umstart)
75         um_start
76         ;;        
77         stop)
78         stop
79         ;;  
80         umstop)
81         um_stop
82         ;;               
83     *)
84         cd ${TOMCAT_BASE}/bin/
85         ${TOMCAT_BASE}/bin/catalina.sh "$@"
86         RETVAL=$?
87         ;;
88 esac
89
90 cd ${PWD_ENTER}
91 exit ${RETVAL}