2014-08-29 5 views
12

Nach der Bereitstellung einiger Apache Kafka-Instanzen auf Remote-Knoten habe ich ein Problem mit dem Skript kafka-server-stop.sh im Kafka-Archiv beobachtet.kafka-server-stop.sh funktioniert nicht, wenn Kafka vom Python-Skript gestartet wurde

standardmäßig enthält:

#!/bin/sh 
# Licensed to the Apache Software Foundation (ASF) under one or more 
# contributor license agreements. See the NOTICE file distributed with 
# this work for additional information regarding copyright ownership. 
# The ASF licenses this file to You under the Apache License, Version 2.0 
# (the "License"); you may not use this file except in compliance with 
# the License. You may obtain a copy of the License at 
# 
# http://www.apache.org/licenses/LICENSE-2.0 
# 
# Unless required by applicable law or agreed to in writing, software 
# distributed under the License is distributed on an "AS IS" BASIS, 
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
# See the License for the specific language governing permissions and 
# limitations under the License. 
ps ax | grep -i 'kafka\.Kafka' | grep java | grep -v grep | awk '{print $1}' | xargs kill -SIGTERM 

und dieses Skript funktioniert gut, wenn ich Apache kafka als nicht Hintergrundprozess ausführen, zum Beispiel:

/var/lib/kafka/bin/kafka-server-start.sh /var/lib/kafka/config/server.properties 

auch funktioniert es, wenn ich es als Hintergrund ausführen Prozess:

/var/lib/kafka/bin/kafka-server-start.sh /var/lib/kafka/config/server.properties & 

aber auf meinen entfernten Knoten führe ich es aus (mit der Verwendung von Ans ible) mit diesem Python-Skript:

#!/usr/bin/env python 
import argparse 
import os 
import subprocess 

KAFKA_PATH = "/var/lib/kafka/" 

def execute_command_pipe_output(command_to_call): 
    return subprocess.Popen(command_to_call, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) 

def execute_command_no_output(command_to_call): 
    with open(os.devnull, "w") as null_file: 
    return subprocess.Popen(command_to_call, stdout=null_file, stderr=subprocess.STDOUT) 

def start_kafka(args): 
    command_to_call = ["nohup"] 
    command_to_call += [KAFKA_PATH + "bin/zookeeper-server-start.sh"] 
    command_to_call += [KAFKA_PATH + "config/zookeeper.properties"] 

    proc = execute_command_no_output(command_to_call) 

    command_to_call = ["nohup"] 
    command_to_call += [KAFKA_PATH + "bin/kafka-server-start.sh"] 
    command_to_call += [KAFKA_PATH + "config/server.properties"] 

    proc = execute_command_no_output(command_to_call) 

def stop_kafka(args): 
    command_to_call = [KAFKA_PATH + "bin/kafka-server-stop.sh"] 

    proc = execute_command_pipe_output(command_to_call) 
    for line in iter(proc.stdout.readline, b''): 
    print line, 

    command_to_call = [KAFKA_PATH + "bin/zookeeper-server-stop.sh"] 

    proc = execute_command_pipe_output(command_to_call) 
    for line in iter(proc.stdout.readline, b''): 
    print line, 


if __name__ == "__main__": 
    parser = argparse.ArgumentParser(description="Starting Zookeeper and Kafka instances") 
    parser.add_argument('action', choices=['start', 'stop'], help="action to take") 

    args = parser.parse_args() 

    if args.action == 'start': 
    start_kafka(args) 
    elif args.action == 'stop': 
    stop_kafka(args) 
    else: 
    parser.print_help() 

nach

manage-kafka.py start 
manage-kafka.py stop 

Zookeeper Ausführung ist shutdown (wie es sein sollte), aber Kafka läuft noch.

Was ist interessanter, als ich (von Hand) aufrufen

nohup /var/lib/kafka/bin/kafka-server-stop.sh 

oder

nohup /var/lib/kafka/bin/kafka-server-stop.sh & 

kafka-server-stop.sh Abschaltungen richtig Kafka-Instanz. Ich vermute, dass dieses Problem durch eine Linux/Python-Sache verursacht wird.

+0

Nur aus Neugier: Warum Python verwenden? Warum nicht Upstart verwenden und einen Python-Aufruf wie "service kafka-broker start/stop" machen? – RickyA

+0

Es wurde als erste Lösung erstellt und ich bin nur interessiert, warum ich beschriebenes Verhalten beobachte. Ich werde dies zum Supervisor für das Management verschieben, da wir es bereits für verschiedene Anwendungen verwenden. – Andna

+0

Haben Sie eine Antwort darauf gefunden? – neoeahit

Antwort

0

Kafka muss den Shutdown-Vorgang beenden, bevor die Tierpfleger shutsdown.

So starten Sie die Tierpfleger, dann werden die Broker den Shutdown-Prozess wiederholen.

Ich hatte einen ähnlichen Fall. Das Problem war, dass meine Konfiguration nicht darauf wartete, dass die Kafka-Broker heruntergefahren wurden.

Hoffe, das hilft jemandem. Ich brauchte eine Weile, um herauszufinden ...

Verwandte Themen