@@ -6,16 +6,28 @@ import logging
66import sys
77import time
88
9- from cassandra .tools import get_instances
10- from cassandra .tools .config import LOG_LEVEL
9+ from cassandra .tools import get_instances
10+ from cassandra .tools .config import LOG_LEVEL
11+ from cassandra .tools .tcpircbot import IrcBot
1112
1213logging .basicConfig (level = LOG_LEVEL , format = "%(asctime)s %(levelname)-8s %(message)s" )
1314
1415
15- def main (attempts , retry , delay , post_shutdown ):
16+ def logmsgbot_message (instance , issue = None ):
17+ return "Restarting {0.service_name} {1}" .format (instance , "({})" .format (issue ) if issue else "" )
18+
19+ def main ():
20+ args = parse_args ()
21+ bot = IrcBot (args .tcpircbot_host , args .tcpircbot_port , 1.0 )
1622 for instance in get_instances ():
17- instance .restart (attempts = attempts , retry = retry , post_shutdown = post_shutdown )
18- time .sleep (delay )
23+ if args .logmsgbot :
24+ bot .log (logmsgbot_message (instance , args .phabricator_issue ))
25+ instance .restart (
26+ attempts = args .attempts ,
27+ retry = args .retry ,
28+ post_shutdown = args .execute_post_shutdown
29+ )
30+ time .sleep (args .delay )
1931
2032def parse_args ():
2133 parser = argparse .ArgumentParser (description = "Cassandra instance restarter" )
@@ -26,11 +38,22 @@ def parse_args():
2638 parser .add_argument ("--execute-post-shutdown" , metavar = "CMD" , type = str ,
2739 help = "Command to execute after Cassandra has been shutdown, and before it "
2840 "is started back up." )
29- parser .add_argument ("-d" , "--delay" , metavar = "DELAY" , type = int ,
41+ parser .add_argument ("-d" , "--delay" , metavar = "DELAY" , type = float , default = 0.0 ,
3042 help = "Delay between instance restarts (defaults to no delay)." )
43+ parser .add_argument ("--logmsgbot" , action = "store_true" ,
44+ help = "Log restarts to SAL (via logmsgbot and #wikimedia-operations)." )
45+ parser .add_argument ("--tcpircbot-host" , default = "neon.wikimedia.org" , metavar = "HOST" ,
46+ help = "tcpircbot hostname. Only valid when --logmsgbot is used. "
47+ "Default: neon.wikimedia.org" )
48+ parser .add_argument ("--tcpircbot-port" , metavar = "PORT" , type = int , default = 9200 ,
49+ help = "tcpircbot port number. Only valid when --logmsgbot is used. "
50+ "Default: 9200" )
51+ parser .add_argument ("--phabricator-issue" , metavar = "ISSUE" ,
52+ help = "Phabricator issue to associate these restarts with. This currently "
53+ "only makes sense in combination with --logmsgbot where it is included in "
54+ "the formatted log message." )
3155 return parser .parse_args (sys .argv [1 :])
3256
3357
3458if __name__ == "__main__" :
35- args = parse_args ()
36- main (args .attempts , args .retry , args .delay , args .execute_post_shutdown )
59+ main ()
0 commit comments