@@ -789,6 +789,9 @@ def get_launch_bin(self):
789
789
def add_custom_launch_arguments (self , args ):
790
790
pass
791
791
792
+ def __log_dir (self ):
793
+ return '-Dcassandra.logdir=%s' % os .path .join (self .get_path (), 'logs' )
794
+
792
795
def start (self ,
793
796
join_ring = True ,
794
797
no_wait = False ,
@@ -876,7 +879,7 @@ def start(self,
876
879
877
880
args = args + ['-p' , pidfile , '-Dcassandra.join_ring=%s' % str (join_ring )]
878
881
879
- args .append ('-Dcassandra.logdir=%s' % os . path . join ( self .get_path (), 'logs' ))
882
+ args .append (self .__log_dir ( ))
880
883
if replace_token is not None :
881
884
args .append ('-Dcassandra.replace_token=%s' % str (replace_token ))
882
885
if replace_address is not None :
@@ -982,6 +985,26 @@ def _wait_for_running(self, process, timeout_s):
982
985
self ._update_pid (process )
983
986
return self .is_running ()
984
987
988
+ def __unix_kill_process_matching (self , pattern , sig = signal .SIGTERM ):
989
+ matcher = re .compile (pattern )
990
+ for proc in psutil .process_iter (['pid' , 'cmdline' ]):
991
+ try :
992
+ pid = proc .info ['pid' ]
993
+ cmdline = " " .join (proc .info ['cmdline' ]) if proc .info ['cmdline' ] else ""
994
+ logger .info (f"{ cmdline } " )
995
+ if matcher .search (cmdline ):
996
+ try :
997
+ os .kill (int (pid ), sig )
998
+ except ProcessLookupError :
999
+ logger .info (f"Process { pid } not found" )
1000
+ except PermissionError :
1001
+ logger .info (f"Did not have permissions to kill { pid } " )
1002
+ except (psutil .NoSuchProcess , psutil .AccessDenied , psutil .ZombieProcess ):
1003
+ pass
1004
+
1005
+ def __unix_kill (self , sig ):
1006
+ self .__unix_kill_process_matching (".*{}.*{}.*" .format (self .__log_dir (), "org.apache.cassandra.service.CassandraDaemon" ), sig )
1007
+
985
1008
def stop (self , wait = True , wait_other_notice = False , signal_event = signal .SIGTERM , ** kwargs ):
986
1009
"""
987
1010
Stop the node.
@@ -995,6 +1018,7 @@ def stop(self, wait=True, wait_other_notice=False, signal_event=signal.SIGTERM,
995
1018
+ gently: Let Cassandra clean up and shut down properly; unless
996
1019
false perform a 'kill -9' which shuts down faster.
997
1020
"""
1021
+ gently = 'gently' in kwargs and kwargs ['gently' ] is True
998
1022
if self .is_running ():
999
1023
if wait_other_notice :
1000
1024
marks = [(node , node .mark_log ()) for node in list (self .cluster .nodes .values ()) if node .is_live () and node is not self ]
@@ -1021,7 +1045,7 @@ def stop(self, wait=True, wait_other_notice=False, signal_event=signal.SIGTERM,
1021
1045
common .warning ("Failed to terminate node: {0} with pid: {1}" .format (self .name , self .pid ))
1022
1046
else :
1023
1047
# Determine if the signal event should be updated to keep API compatibility
1024
- if ' gently' in kwargs and kwargs [ 'gently' ] is False :
1048
+ if gently is False :
1025
1049
signal_event = signal .SIGKILL
1026
1050
1027
1051
os .kill (self .pid , signal_event )
@@ -1046,6 +1070,9 @@ def stop(self, wait=True, wait_other_notice=False, signal_event=signal.SIGTERM,
1046
1070
else :
1047
1071
return True
1048
1072
else :
1073
+ # Make sure it is actually stopped even if the PID wasn't found for some reason
1074
+ if not common .is_win ():
1075
+ self .__unix_kill (signal if gently else signal .SIGKILL )
1049
1076
return False
1050
1077
1051
1078
def wait_for_compactions (self , timeout = 120 ):
0 commit comments