2020-05-28 05:31:31 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								#!/bin/bash
  
						 
					
						
							
								
									
										
										
										
											2011-10-08 03:51:28 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# 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  
						 
					
						
							
								
									
										
										
										
											2017-12-16 06:48:30 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								#  
						 
					
						
							
								
									
										
										
										
											2011-10-08 03:51:28 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								#    http://www.apache.org/licenses/LICENSE-2.0  
						 
					
						
							
								
									
										
										
										
											2017-12-16 06:48:30 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								#  
						 
					
						
							
								
									
										
										
										
											2011-10-08 03:51:28 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# 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.  
						 
					
						
							
								
									
										
										
										
											2017-12-16 06:48:30 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								SIGNAL = ${ SIGNAL :- TERM }  
						 
					
						
							
								
									
										
										
										
											2020-02-20 22:19:50 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-12-12 16:20:43 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								INPUT_PROCESS_ROLE = $( echo  " $@ "  |  grep -o -- '--process-role=[^ ]*'  |  cut -d'='  -f2)  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								INPUT_NID = $( echo  " $@ "  |  grep -o -- '--node-id=[^ ]*'  |  cut -d'='  -f2)  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								if  [  -n " $INPUT_NID "  ]  &&  [  -n " $INPUT_PROCESS_ROLE "  ] ;  then  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  echo  "When both node-id and process-role are provided, the value for node-id will take precedence" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								fi  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-09-02 23:46:24 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								OSNAME = $( uname -s)  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								if  [ [  " $OSNAME "  = =  "OS/390"  ] ] ;  then  
						 
					
						
							
								
									
										
										
										
											2020-02-20 22:19:50 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    if  [  -z $JOBNAME  ] ;  then 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        JOBNAME = "KAFKSTRT" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    fi 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    PIDS = $( ps -A -o pid,jobname,comm |  grep -i $JOBNAME  |  grep java |  grep -v grep |  awk '{print $1}' ) 
							 
						 
					
						
							
								
									
										
										
										
											2020-09-02 23:46:24 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								elif  [ [  " $OSNAME "  = =  "OS400"  ] ] ;  then  
						 
					
						
							
								
									
										
										
										
											2021-01-22 02:18:48 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    PIDS = $( ps -Af |  grep -i 'kafka\.Kafka'  |  grep java |  grep -v grep |  awk '{print $2}' ) 
							 
						 
					
						
							
								
									
										
										
										
											2020-02-20 22:19:50 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								else  
						 
					
						
							
								
									
										
										
										
											2023-12-12 16:20:43 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    PIDS = $( ps ax |  grep ' kafka\.Kafka '  |  grep java |  grep -v grep |  awk '{print $1}' |  xargs) 
							 
						 
					
						
							
								
									
										
										
										
											2020-02-20 22:19:50 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								fi  
						 
					
						
							
								
									
										
										
										
											2016-03-04 09:41:47 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								if  [  -z " $PIDS "  ] ;  then  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  echo  "No kafka server to stop" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  exit  1 
							 
						 
					
						
							
								
									
										
										
										
											2017-12-16 06:48:30 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								else  
						 
					
						
							
								
									
										
										
										
											2023-12-12 16:20:43 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  if  [  -z " $INPUT_PROCESS_ROLE "  ]  &&  [  -z " $INPUT_NID "  ] ;  then 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    kill  -s $SIGNAL  $PIDS 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  else 
							 
						 
					
						
							
								
									
										
										
										
											2023-12-14 23:32:16 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    RelativePathToConfig = $( ps ax |  grep ' kafka\.Kafka '  |  grep java |  grep -v grep |  sed 's/--override property=[^ ]*//g'  |  awk 'NF>1{print $NF}'  |  xargs) 
							 
						 
					
						
							
								
									
										
										
										
											2023-12-12 16:20:43 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    IFS = ' '  read  -ra PIDSArray <<<  " $PIDS " 
							 
						 
					
						
							
								
									
										
										
										
											2023-12-14 23:32:16 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    IFS = ' '  read  -ra RelativePathArray <<<  " $RelativePathToConfig " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    for  ( ( i  =  0;  i < ${# RelativePathArray [@] } ;  i++) ) ;  do 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        AbsolutePathToConfig = $( readlink -f " ${ RelativePathArray [i] } " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  [  -z " $AbsolutePathToConfig "  ]  ;  then 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								          echo  "Can not find the configuration file in the current directory. Please make sure the kafka stop process and the start process are called in the same directory." 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								          exit  1 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        fi 
							 
						 
					
						
							
								
									
										
										
										
											2023-12-12 16:20:43 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        if  [  -n " $INPUT_NID "  ]  ;  then 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            keyword = "node.id=" 
							 
						 
					
						
							
								
									
										
										
										
											2023-12-14 23:32:16 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            NID = $( sed -n " / $keyword / { s/ $keyword //p; q; } "  " $AbsolutePathToConfig " ) 
							 
						 
					
						
							
								
									
										
										
										
											2023-12-12 16:20:43 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        elif  [  -n " $INPUT_PROCESS_ROLE "  ]  &&  [  -z " $INPUT_NID "  ] ;  then 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            keyword = "process.roles=" 
							 
						 
					
						
							
								
									
										
										
										
											2023-12-14 23:32:16 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            PROCESS_ROLE = $( sed -n " / $keyword / { s/ $keyword //p; q; } "  " $AbsolutePathToConfig " ) 
							 
						 
					
						
							
								
									
										
										
										
											2023-12-12 16:20:43 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        fi 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  [  -n " $INPUT_PROCESS_ROLE "  ]  &&  [  " $PROCESS_ROLE "  = =  " $INPUT_PROCESS_ROLE "  ]  ||  [  -n " $INPUT_NID "  ]  &&  [  " $NID "  = =  " $INPUT_NID "  ] ;  then 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								          kill  -s $SIGNAL  ${ PIDSArray [i] } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        fi 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    done 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  fi 
							 
						 
					
						
							
								
									
										
										
										
											2016-03-04 09:41:47 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								fi