Pamela Dragosh | 91d04c6 | 2017-02-14 19:41:00 -0500 | [diff] [blame] | 1 | ### |
| 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 |
| 27 | SERVER=http://localhost:8070/pap/ |
| 28 | LOGTYPE=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" |
| 32 | JDBC_USER="sa" |
| 33 | JDBC_DRIVER="org.h2.Driver" |
| 34 | JDBC_PASSWORD="" |
| 35 | SERVICE="LogParser.jar" |
| 36 | |
| 37 | # Check the application status |
| 38 | # |
| 39 | # This function checks if the application is running |
| 40 | check_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 |
| 53 | start() { |
| 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 |
| 77 | stop() { |
| 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 |
| 96 | status() { |
| 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 |
| 111 | case "$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 |
| 128 | esac |
| 129 | |
| 130 | exit 0 |