daily pastebin goal
52%
SHARE
TWEET

Untitled

a guest Mar 24th, 2019 48 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2.  
  3. BASE_DIR=/app
  4. START_COMMAND="java -jar $BASE_DIR/app.jar"
  5. PID_FILE=$BASE_DIR/app.pid
  6. LOG_DIR=$BASE_DIR/logs
  7.  
  8. start() {
  9.   PID=`$START_COMMAND > $LOG_DIR/init.log 2>$LOG_DIR/init.error.log & echo $!`
  10. }
  11.  
  12. case "$1" in
  13. start)
  14.     if [ -f $PID_FILE ]; then
  15.         PID=`cat $PID_FILE`
  16.         if [ -z "`ps axf | grep ${PID} | grep -v grep`" ]; then
  17.             start
  18.         else
  19.             echo "Already running [$PID]"
  20.             exit 0
  21.         fi
  22.     else
  23.         start
  24.     fi
  25.  
  26.     if [ -z $PID ]; then
  27.         echo "Failed starting"
  28.         exit 1
  29.     else
  30.         echo $PID > $PID_FILE
  31.         echo "Started [$PID]"
  32.         exit 0
  33.     fi
  34. ;;
  35. status)
  36.     if [ -f $PID_FILE ]; then
  37.         PID=`cat $PID_FILE`
  38.         if [ -z "`ps axf | grep ${PID} | grep -v grep`" ]; then
  39.             echo "Not running (process dead but PID file exists)"
  40.             exit 1
  41.         else
  42.             echo "Running [$PID]"
  43.             exit 0
  44.         fi
  45.     else
  46.         echo "Not running"
  47.         exit 0
  48.     fi
  49. ;;
  50. stop)
  51.     if [ -f $PID_FILE ]; then
  52.         PID=`cat $PID_FILE`
  53.         if [ -z "`ps axf | grep ${PID} | grep -v grep`" ]; then
  54.             echo "Not running (process dead but PID file exists)"
  55.             rm -f $PID_FILE
  56.             exit 1
  57.         else
  58.             PID=`cat $PID_FILE`
  59.             kill -term $PID
  60.             echo "Stopped [$PID]"
  61.             rm -f $PID_FILE
  62.             exit 0
  63.         fi
  64.     else
  65.         echo "Not running (PID not found)"
  66.         exit 0
  67.     fi
  68. ;;
  69. restart)
  70.     $0 stop
  71.     $0 start
  72. ;;
  73. *)
  74.     echo "Usage: $0 {status|start|stop|restart}"
  75.     exit 0
  76. esac
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top