3 # vim: ts=4 sw=4 smarttab expandtab
14 logging.basicConfig(level=logging.INFO)
15 log = logging.getLogger('ceph-crash')
17 auth_names = ['client.crash.%s' % socket.gethostname(),
22 parser = argparse.ArgumentParser()
24 '-p', '--path', default='/var/lib/ceph/crash',
25 help='base path to monitor for crash dumps')
27 '-d', '--delay', default=10.0, type=float,
28 help='minutes to delay between scans (0 to exit after one)',
32 help='ceph name to authenticate as (default: try client.crash, client.admin)')
33 return parser.parse_args()
39 pr = subprocess.Popen(
40 args=['timeout', '30', 'ceph',
42 'crash', 'post', '-i', '-'],
43 stdin=subprocess.PIPE,
44 stdout=subprocess.PIPE,
45 stderr=subprocess.PIPE,
47 f = open(os.path.join(path, 'meta'), 'rb')
48 stdout, stderr = pr.communicate(input=f.read())
52 log.warning('post %s as %s failed: %s' % (path, n, stderr))
58 def scrape_path(path):
59 for p in os.listdir(path):
60 crashpath = os.path.join(path, p)
61 metapath = os.path.join(crashpath, 'meta')
62 donepath = os.path.join(crashpath, 'done')
63 if os.path.isfile(metapath):
64 if not os.path.isfile(donepath):
65 # hang out just for a bit; either we interrupted the dump
66 # or the daemon crashed before finishing it
68 if not os.path.isfile(donepath):
70 # ok, we can process this one
71 rc = post_crash(crashpath)
73 os.rename(crashpath, os.path.join(path, 'posted/', p))
75 "posted %s and renamed %s -> %s " %
76 (metapath, p, os.path.join('posted/', p))
79 def handler(signum, frame):
80 print('*** Interrupted with signal %d ***' % signum)
84 # exit code 0 on SIGINT, SIGTERM
85 signal.signal(signal.SIGINT, handler)
86 signal.signal(signal.SIGTERM, handler)
89 postdir = os.path.join(args.path, 'posted')
91 auth_names = [args.name]
93 while not os.path.isdir(postdir):
94 log.error("directory %s does not exist; please create" % postdir)
97 log.info("monitoring path %s, delay %ds" % (args.path, args.delay * 60.0))
99 scrape_path(args.path)
102 time.sleep(args.delay * 60)
105 if __name__ == "__main__":