kafka-server-stop.sh ne fonctionne pas lorsque Kafka a commencé à partir d'un script Python
Après le déploiement de certains Apache Kafka instances sur les nœuds distants j'ai observé problème avec kafka-server-stop.sh
script qui fait partie de Kafka archive.
Par défaut, il contient:
#!/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
et ce script fonctionne très bien si je exécuter apache kafka comme pas de processus d'arrière-plan, par exemple:
/var/lib/kafka/bin/kafka-server-start.sh /var/lib/kafka/config/server.properties
aussi il fonctionne quand je l'exécuter en tant que processus d'arrière-plan:
/var/lib/kafka/bin/kafka-server-start.sh /var/lib/kafka/config/server.properties &
mais sur mon nœuds distants j'ai l'exécuter (avec l'utilisation de l'Ansible) avec ce script python:
#!/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()
après l'exécution de
manage-kafka.py start
manage-kafka.py stop
Zookeeper est à l'arrêt (comme il devrait l'être), mais Kafka est toujours en cours d'exécution.
Ce qui est plus intéressant, quand j'invoque (à la main)
nohup /var/lib/kafka/bin/kafka-server-stop.sh
ou
nohup /var/lib/kafka/bin/kafka-server-stop.sh &
kafka-server-stop.sh
correctement les arrêts de Kafka instance. J'imagine que ce problème peut être causé par certains Linux/Python chose.
Il a été créé en tant que première solution et je suis juste intéressé pourquoi je suis en observant le comportement décrit. Je vais déménager de ce Superviseur de la gestion, car nous sommes déjà à l'utiliser pour différentes applications.
Avez-vous trouver une réponse à cela?
OriginalL'auteur Andna | 2014-08-29
Vous devez vous connecter pour publier un commentaire.
Kafka a besoin pour terminer le processus d'arrêt avant de les gardiens de zoo shutsdown.
Donc, commencer les gardiens de zoo, puis les courtiers retente le processus d'arrêt.
J'ai eu un cas similaire. Le problème était que ma config n'a pas été en attente pour le kafka courtiers à l'arrêt.
Espère que cela aide quelqu'un. Il m'a fallu un certain temps à comprendre...
OriginalL'auteur
J'ai fait face à ce problème beaucoup avant de trouver une brute visage façon de résoudre le problème.
Donc ce qui s'est passé, c'est Kafka fermé brusquement, mais le port est toujours en cours d'utilisation.
Suivez les étapes suivantes:
lsof -t -i :YOUR_PORT_NUMBER
. ##ce est pour mackill -9 process_id
OriginalL'auteur
Ma conjecture: kafka-server-stop.sh utilise le shell pipes. Donc, Popen aurait besoin
shell=True
argument.Voir https://docs.python.org/2/library/subprocess.html#subprocess.Popen
OriginalL'auteur