Advertisement
Muertochongo

azkaban-web-init-script

Aug 14th, 2015
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.37 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. # Init file for Azkaban Web Server
  4. #
  5. # chkconfig: 2345 60 25
  6. # description: Azkaban Web Server
  7.  
  8. # Source function library.
  9. #. /etc/init.d/functions
  10.  
  11. if [ -z "$AZKBN_HOME" ]; then
  12.   AZKBN_HOME=/opt/azkaban-web-2.5.0/
  13. fi
  14. export AZKBN_HOME
  15.  
  16. if [ -z "$AZKBN_PIDFILE" ]; then
  17.   AZKBN_PIDFILE="$AZKBN_HOME/currentpid"
  18. fi
  19. export AZKBN_PIDFILE
  20.  
  21. if [ -z "$SHUTDOWN_WAIT" ]; then
  22.   SHUTDOWN_WAIT=10
  23. fi
  24.  
  25.  
  26. CMD_PREFIX=''
  27.  
  28. # Option to utilize daemon
  29. if [ ! -z "$AZKBN_USER" ]; then
  30.   if [ -r /etc/rc.d/init.d/functions ]; then
  31.     CMD_PREFIX="daemon --user $AZKBN_USER"
  32.   else
  33.     CMD_PREFIX="su - $AZKBN_USER -c"
  34.   fi
  35. fi
  36.  
  37. PROG='Azkaban Web Server'
  38. AZKBN_USER=etladmin
  39. AGENT="$AZKBN_HOME/bin/start-exec.sh"
  40.  
  41. start()
  42. {
  43.   echo -n "Starting $PROG: "
  44.   if [ -f $AZKBN_PIDFILE ]; then
  45.     read ppid < $AZKBN_PIDFILE
  46.     if [ `ps --pid $ppid 2> /dev/null | grep -c $ppid 2> /dev/null` -eq '1' ]; then
  47.       echo -n "$PROG is already running"
  48.       failure
  49.       echo
  50.       return 1
  51.     else
  52.       rm -f $AZKBN_PIDFILE
  53.     fi
  54.   fi
  55.  
  56.  
  57.   mkdir -p $(dirname $AZKBN_PIDFILE)
  58.   chown $AZKBN_USER $(dirname $AZKBN_PIDFILE) || true
  59.  
  60.   if [ ! -z "$AZKBN_USER" ]; then
  61.      cd /opt/azkaban-web-2.5.0 && bin/start-web.sh  &
  62.      echo $! > $AZKBN_PIDFILE
  63.   fi
  64.  
  65.  # success
  66.   echo
  67.   return 0
  68.  
  69. }
  70.  
  71. stop()
  72. {
  73.   echo -n $"Stopping $PROG: "
  74.   count=0;
  75.  
  76.   if [ -f $AZKBN_PIDFILE ]; then
  77.     read kpid < $AZKBN_PIDFILE
  78.     let kwait=$SHUTDOWN_WAIT
  79.  
  80.     # Try issuing SIGTERM
  81.  
  82.     kill -15 $kpid
  83.     until [ `ps --pid $kpid 2> /dev/null | grep -c $kpid 2> /dev/null` -eq '0' ] || [ $count -gt $kwait ]
  84.     do
  85.       sleep 1
  86.       let count=$count+1;
  87.     done
  88.  
  89.     if [ $count -gt $kwait ]; then
  90.       kill -9 $kpid
  91.     fi
  92.   fi
  93.   rm -f $AZKBN_PIDFILE
  94. #  success
  95.   echo
  96. }
  97.  
  98. status()
  99. {
  100.   if [ -f $AZKBN_PIDFILE ]; then
  101.     read ppid < $AZKBN_PIDFILE
  102.     if [ `ps --pid $ppid 2> /dev/null | grep -c $ppid 2> /dev/null` -eq 1 ]; then
  103.       echo "$PROG is running (pid $ppid)"
  104.       return 0
  105.     else
  106.       echo "$PROG dead but pid file exists"
  107.       return 1
  108.     fi
  109.   fi
  110.   echo "$PROG is not running"
  111.   return 3
  112. }
  113.  
  114. case "$1" in
  115.   start)
  116.       start
  117.       ;;
  118.   stop)
  119.       stop
  120.       ;;
  121.   restart)
  122.       stop
  123.       start
  124.       ;;
  125.   status)
  126.       status
  127.       ;;
  128.   *)
  129.   echo "Usage: $0 start|stop|restart|status"
  130.   exit 1
  131.   ;;
  132. esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement