2 # ============LICENSE_START=======================================================
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
11 # http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
23 # init script for a Java application
26 #Arguments for application
27 SERVER=http://localhost:8070/pap/
29 LOGPATH="/var/lib/servers/pap/logs/catalina.out"
30 PARSERLOGPATH="$POLICY_HOME/logs/parserlog.log"
31 JDBC_URL="jdbc:h2:tcp://localhost:9092/log"
33 JDBC_DRIVER="org.h2.Driver"
35 SERVICE="LogParser.jar"
37 # Check the application status
39 # This function checks if the application is running
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})
48 # In any another case, return 0
52 # Starts the application
55 # At first checks if the application is already started calling the check_status
59 # $? is a special variable that hold the "exit status of the most recently executed
60 # foreground pipeline"
63 if [ $pid -ne 0 ] ; then
64 echo "The application is already started"
68 # If the application isn't running, starts it
69 echo -n "Starting application: "
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 &
76 # Stops the application
79 # Like as the start function, checks the application status
84 if [ $pid -eq 0 ] ; then
85 echo "Application is already stopped"
89 # Kills the application process
90 echo -n "Stopping application: "
95 # Show the application status
98 # The check_status function, again...
101 # If the PID was returned means the application is running
102 if [ $? -ne 0 ] ; then
103 echo "Application is started"
105 echo "Application is stopped"
110 # Main logic, a simple case to call functions
126 echo "Usage: $0 {start|stop|restart|reload|status}"