Advertisement
josephxsxn

kafka-broker-initd

Dec 12th, 2018
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.74 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. # Licensed to the Apache Software Foundation (ASF) under one or more
  4. # contributor license agreements.  See the NOTICE file distributed with
  5. # this work for additional information regarding copyright ownership.
  6. # The ASF licenses this file to You under the Apache License, Version 2.0
  7. # (the "License"); you may not use this file except in compliance with
  8. # the License.  You may obtain a copy of the License at
  9. #
  10. #     http://www.apache.org/licenses/LICENSE-2.0
  11. #
  12. # Unless required by applicable law or agreed to in writing, software
  13. # distributed under the License is distributed on an "AS IS" BASIS,
  14. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. # See the License for the specific language governing permissions and
  16. # limitations under the License.
  17. #
  18. # Starts a Kafka Broker
  19. #
  20. # chkconfig: 35 85 15
  21. # description: Kafka Broker
  22. #
  23. ### BEGIN INIT INFO
  24. # Provides:          kafka
  25. # Required-Start:    $local_fs $remote_fs $network $syslog zookeeper
  26. # Required-Stop:     $local_fs $remote_fs $network $syslog zookeeper
  27. # Default-Start:     2 3 4 5
  28. # Default-Stop:      0 1 6
  29. # Short-Description: Startup script for Kafka broker
  30. # Description:       Kafka is a high-throughput distributed messaging system.
  31. ### END INIT INFO
  32.  
  33. DAEMON_PATH=/usr/local/kafka/prod/bin
  34. DAEMON_NAME=kafka
  35.  
  36. PIDFILE=/var/run/kafka-broker.pid
  37. PATH=$PATH:$DAEMON_PATH
  38. PROPERTIES_FILE=/usr/local/kafka/prod/config/server.properties
  39. START_SCRIPT=kafka-server-start.sh
  40. STOP_SCRIPT=kafka-server-stop.sh
  41. NAME="Kafka Broker"
  42.  
  43. LOG_FILE=/var/log/kafka/kafka-server.out
  44.  
  45. case "$1" in
  46. start)
  47.   echo "Starting $DAEMON_NAME";
  48.   PID=`$DAEMON_PATH/$START_SCRIPT $PROPERTIES_FILE > /dev/null  2>&1 & echo $!`
  49.  
  50.   if [ -z $PID ]; then
  51.       printf "%s\n" "$NAME failed to start"
  52.   else
  53.       echo $PID > $PIDFILE
  54.       printf "%s\n" "$NAME started"
  55.   fi
  56. ;;
  57. status)
  58.         if [ -f $PIDFILE ]; then
  59.             PID=`cat $PIDFILE`
  60.             if [ -z "`ps axf | grep ${PID} | grep -v grep`" ]; then
  61.                 printf "%s\n" "$NAME process dead but pidfile exists"
  62.             else
  63.                 echo "$NAME running"
  64.             fi
  65.         else
  66.             printf "%s\n" "$NAME service not running"
  67.         fi
  68. ;;
  69. stop)
  70.         printf "%-50s" "Stopping $NAME"
  71.             PID=`cat $PIDFILE`
  72.             cd $DAEMON_PATH
  73.         if [ -f $PIDFILE ]; then
  74.             $DAEMON_PATH/$STOP_SCRIPT 2>/dev/null
  75.             kill -HUP $PID
  76.             printf "%s\n" "$NAME stopped"
  77.             rm -f $PIDFILE
  78.         else
  79.             printf "%s\n" "$NAME pidfile not found"
  80.         fi
  81. ;;
  82.  
  83. restart)
  84.     $0 stop
  85.     sleep 2
  86.     $0 start
  87. ;;
  88.  
  89. *)
  90.         echo "Usage: $0 {status|start|stop|restart}"
  91.         exit 1
  92. esac
  93.  
  94. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement