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)')
35 help='log level output (default: INFO), support INFO or DEBUG')
37 return parser.parse_args()
43 pr = subprocess.Popen(
44 args=['timeout', '30', 'ceph',
46 'crash', 'post', '-i', '-'],
47 stdin=subprocess.PIPE,
48 stderr=subprocess.PIPE,
50 f = open(os.path.join(path, 'meta'), 'rb')
51 stderr = pr.communicate(input=f.read())
54 if rc != 0 or stderr != "":
55 log.warning('post %s as %s failed: %s' % (path, n, stderr))
61 def scrape_path(path):
62 for p in os.listdir(path):
63 crashpath = os.path.join(path, p)
64 metapath = os.path.join(crashpath, 'meta')
65 donepath = os.path.join(crashpath, 'done')
66 if os.path.isfile(metapath):
67 if not os.path.isfile(donepath):
68 # hang out just for a bit; either we interrupted the dump
69 # or the daemon crashed before finishing it
71 if not os.path.isfile(donepath):
73 # ok, we can process this one
74 rc = post_crash(crashpath)
76 os.rename(crashpath, os.path.join(path, 'posted/', p))
78 "posted %s and renamed %s -> %s " %
79 (metapath, p, os.path.join('posted/', p))
83 print('*** Interrupted with signal %d ***' % signum)
88 # exit code 0 on SIGINT, SIGTERM
89 signal.signal(signal.SIGINT, handler)
90 signal.signal(signal.SIGTERM, handler)
93 if args.log_level == 'DEBUG':
94 log.setLevel(logging.DEBUG)
96 postdir = os.path.join(args.path, 'posted')
98 auth_names = [args.name]
100 while not os.path.isdir(postdir):
101 log.error("directory %s does not exist; please create" % postdir)
104 log.info("monitoring path %s, delay %ds" % (args.path, args.delay * 60.0))
106 scrape_path(args.path)
109 time.sleep(args.delay * 60)
112 if __name__ == "__main__":