blob: 79ea8a3b31c4d08bc9ea0af0fcfcac26bb3a52d5 [file] [log] [blame]
Pamela Dragosh91d04c62017-02-14 19:41:00 -05001###
2# ============LICENSE_START=======================================================
3# LogParser
4# ================================================================================
5# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6# ================================================================================
7# Licensed under the Apache License, Version 2.0 (the "License");
8# you may not use this file except in compliance with the License.
9# You may obtain a copy of the License at
10#
11# http://www.apache.org/licenses/LICENSE-2.0
12#
13# Unless required by applicable law or agreed to in writing, software
14# distributed under the License is distributed on an "AS IS" BASIS,
15# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16# See the License for the specific language governing permissions and
17# limitations under the License.
18# ============LICENSE_END=========================================================
19###
20
21#!/bin/sh
22#
23# init script for a Java application
24#
25
26#Arguments for application
27SERVER=http://localhost:8070/pap/
28LOGTYPE=PAP
29LOGPATH="/var/lib/servers/pap/logs/catalina.out"
30PARSERLOGPATH="$POLICY_HOME/logs/parserlog.log"
31JDBC_URL="jdbc:h2:tcp://localhost:9092/log"
32JDBC_USER="sa"
33JDBC_DRIVER="org.h2.Driver"
34JDBC_PASSWORD=""
35SERVICE="LogParser.jar"
36
37# Check the application status
38#
39# This function checks if the application is running
40check_status() {
41
42 # Running pgrep with some arguments to check if the PID exists
43 if pgrep -f "$SERVICE $SERVER $LOGTYPE" ; then
44 RESULT=$(pgrep -f ${SERVICE})
45 return $RESULT
46 fi
47 return 0
48 # In any another case, return 0
49
50}
51
52# Starts the application
53start() {
54
55 # At first checks if the application is already started calling the check_status
56 # function
57 check_status
58
59 # $? is a special variable that hold the "exit status of the most recently executed
60 # foreground pipeline"
61 pid=$?
62
63 if [ $pid -ne 0 ] ; then
64 echo "The application is already started"
65 exit 1
66 fi
67
68 # If the application isn't running, starts it
69 echo -n "Starting application: "
70
71 # Redirects default and error output to a log file
72 java -jar LogParser.jar $SERVER $LOGTYPE $LOGPATH $PARSERLOGPATH $JDBC_URL $JDBC_USER $JDBC_DRIVER $JDBC_PASSWORD>> $POLICY_HOME/logs/parserlog.log 2>&1 &
73 echo "OK"
74}
75
76# Stops the application
77stop() {
78
79 # Like as the start function, checks the application status
80 check_status
81
82 pid=$?
83
84 if [ $pid -eq 0 ] ; then
85 echo "Application is already stopped"
86 exit 1
87 fi
88
89 # Kills the application process
90 echo -n "Stopping application: "
91 kill -9 $pid &
92 echo "OK"
93}
94
95# Show the application status
96status() {
97
98 # The check_status function, again...
99 check_status
100
101 # If the PID was returned means the application is running
102 if [ $? -ne 0 ] ; then
103 echo "Application is started"
104 else
105 echo "Application is stopped"
106 fi
107
108}
109
110# Main logic, a simple case to call functions
111case "$1" in
112 start)
113 start
114 ;;
115 stop)
116 stop
117 ;;
118 status)
119 status
120 ;;
121 restart|reload)
122 stop
123 start
124 ;;
125 *)
126 echo "Usage: $0 {start|stop|restart|reload|status}"
127 exit 1
128esac
129
130exit 0