aboutsummaryrefslogtreecommitdiffstats
path: root/packages/base/src/files/install/servers/common/logparser/init.d/logparserd
blob: 37221b9c3a4b00b86e329284b4f541f2aecbb4ad (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
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
#!/bin/bash
#
# init script for a Java application
#

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 start, does not change monitor status (immutable)
function um_start() {
	JMX_JAVA_OPTS="-Dcom.sun.management.jmxremote"
	JMX_JAVA_OPTS="${JMX_JAVA_OPTS} -Dcom.sun.management.jmxremote.port=${LOGPARSER_JMX_PORT}"
	JMX_JAVA_OPTS="${JMX_JAVA_OPTS} -Dcom.sun.management.jmxremote.ssl=false" 
	JMX_JAVA_OPTS="${JMX_JAVA_OPTS} -Dcom.sun.management.jmxremote.authenticate=false"
	JVM_JAVA_OPTS="-Xms${LOGPARSER_X_MS_MB}M -Xmx${LOGPARSER_X_MX_MB}M"

	JAVA_OPTS="${JAVA_OPTS} ${JMX_JAVA_OPTS} ${JVM_JAVA_OPTS}"
	
	# Redirects default and error output to a log file
	cd ${POLICY_HOME}/servers/${COMPONENT}/bin
	nohup $JAVA_HOME/bin/java -jar ${JAVA_OPTS} ${SERVICE} ${SERVER} ${LOGTYPE} >> ${POLICY_HOME}/servers/${COMPONENT}/logs/stdout 2>&1 &
RETVAL=$?
	RETVAL=$?	
}

# Starts the application
function start() {
	um_start
	if [[ ${RETVAL} != 0 ]]; then
		update_monitor ${COMPONENT} off
	else
		update_monitor ${COMPONENT} on
	fi
}

# unmonitored stop, does not change monitor status (immutable)
function um_stop() {
	# Kills the application process
	pkill -u ${POLICY_USER} -f "${SERVICE} ${SERVER} ${LOGTYPE}" -TERM
	RETVAL=$?
	if [[ ${RETVAL} != 0 ]]; then
		sleep 2
		pkill -u ${POLICY_USER} -f "${SERVICE} ${SERVER} ${LOGTYPE}" -KILL
		RETVAL=$?
    fi	
}

# Stops the application
function stop() {
	um_stop
    update_monitor ${COMPONENT} off	
}

# Show the application status
function status() {
	# check status
	pid=$(pgrep -f -u ${POLICY_USER} "${SERVICE} ${SERVER} ${LOGTYPE}" 2> /dev/null)
	RETVAL=$?
	
	# If the PID was returned means the application is running
	if [ ${RETVAL} -eq 0 ] ; then
		echo "running with pid ${pid}"
	else
		echo "stopped"
	fi
}

# Main logic, a simple case to call functions

# determine if this is a paplp or pdplp component
COMPONENT=$(basename $0)

CONF_FILE="${POLICY_HOME}/servers/${COMPONENT}/bin/parserlog.properties"
SERVICE="${POLICY_HOME}/servers/${COMPONENT}/bin/logparser.jar"

# read properties
shopt -s extglob
configfile="dos_or_unix" # set the actual path name of your (DOS or Unix) config file
while IFS='= ' read lhs rhs
do
    if [[ ! $lhs =~ ^\ *# && -n $lhs ]]; then
        rhs="${rhs%%\#*}"    # Del in line right comments
       	 rhs="${rhs%%*( )}"   # Del trailing spaces
        rhs="${rhs%\"*}"     # Del opening string quotes 
       	 rhs="${rhs#\"*}"     # Del closing string quotes
       	 if [[ $lhs != *"."* ]]; then
       	 	declare $lhs="$rhs"
       	 fi
   fi
done < "${CONF_FILE}"
if [ $? -ne 0 ]; then
	echo "error: cannot source configuration ${CONF_FILE}"
	exit 1
fi

case "$1" in
    status)
        status
        ;;
	restart)
		stop
        sleep 2
        start
        ;;
	start)
        start
        ;;
	umstart)
        um_start
        ;;            
	stop)
		stop
        ;;    
	umstop)
        um_stop
        ;;            
    *)
        echo "Usage: $0 {start|stop|umstart|umstop|restart|status}"
        RETVAL=1
        ;;
esac

exit ${RETVAL}