@@ -44,27 +44,36 @@ def __get(key):
4444 """
4545 Restart this Cassandra instance.
4646 """
47- def restart (self , retries = 10 , delay = 6 ):
47+ def restart (self , retries = 10 , delay = 6 , post_shutdown = None ):
4848 self .__log_debug ("Restarting instance... (retries=%s, delay=%s)" , retries , delay )
4949 self .__log_info ("Disabling client ports..." )
5050 self .nodetool .run ("disablebinary" )
5151 self .nodetool .run ("disablethrift" )
5252 self .__log_info ("Draining..." )
5353 self .nodetool .run ("drain" )
5454
55- # Restart Cassandra
56- self .__log_info ("Restarting service %s" , self .service_name )
57- (retcode , stdout , stderr ) = call ("systemctl" , "restart" , self .service_name )
58- if retcode != 0 :
59- self .__log_error ("systemctl returned exit code %s" , retcode )
55+ def exec_command (* args ):
56+ (retcode , stdout , stderr ) = call (* args )
6057 stdout = stdout .rstrip ()
6158 stderr = stderr .rstrip ()
6259 if stdout :
6360 for line in stdout .splitlines ():
64- self .__log_error (line )
61+ self .__log_info (line )
6562 if stderr :
6663 for line in stderr .splitlines ():
6764 self .__log_error (line )
65+ if retcode != 0 :
66+ self .__log_error ("%s returned exit code %s" , args [0 ], retcode )
67+ raise RuntimeError ("{} returned exit code {}" .format (args [0 ], retcode ))
68+
69+ # Restart Cassandra
70+ self .__log_info ("Stopping service %s" , self .service_name )
71+ exec_command ("systemctl" , "stop" , self .service_name )
72+ if post_shutdown :
73+ self .__log_info ("Executing post-shutdown command: %s" , post_shutdown )
74+ exec_command (* (post_shutdown .strip ().split ()))
75+ self .__log_info ("Starting service %s" , self .service_name )
76+ exec_command ("systemctl" , "start" , self .service_name )
6877
6978 # Wait for Cassandra to come back up before continuing
7079 listening = False
0 commit comments