From 96f3eb9dbeccafc3b7ad1fc90ea2d4f0ef31ac65 Mon Sep 17 00:00:00 2001 From: Greg Farnum Date: Thu, 28 May 2015 15:54:15 -0700 Subject: [PATCH] ceph: support arbitrarily-named daemons in logrotate And make it more configurable in terms of sizes. Signed-off-by: Greg Farnum --- tasks/ceph.py | 57 ++++++++++++++++++++++++++++---------------- tasks/logrotate.conf | 10 ++++---- 2 files changed, 43 insertions(+), 24 deletions(-) diff --git a/tasks/ceph.py b/tasks/ceph.py index 8396567210f7a..3b9a35335364e 100644 --- a/tasks/ceph.py +++ b/tasks/ceph.py @@ -94,35 +94,52 @@ def ceph_log(ctx, config): self.stopping = True self.thread.get() - def write_rotate_conf(ctx): + def write_rotate_conf(ctx, daemons): testdir = teuthology.get_testdir(ctx) rotate_conf_path = os.path.join(os.path.dirname(__file__), 'logrotate.conf') - conf = file(rotate_conf_path, 'rb').read() # does this leak an fd or anything? - for remote in ctx.cluster.remotes.iterkeys(): - teuthology.write_file(remote=remote, - path='{tdir}/logrotate.mds.conf'.format(tdir=testdir), - data=conf - ) - remote.run( - args=[ - 'sudo', - 'mv', - '{tdir}/logrotate.mds.conf'.format(tdir=testdir), - '/etc/logrotate.d/ceph-test.conf' - ] - ) + with file(rotate_conf_path, 'rb') as f: + conf = "" + for daemon,size in daemons.iteritems(): + log.info('writing logrotate stanza for {daemon}'.format(daemon=daemon)) + conf += f.read().format(daemon_type=daemon,max_size=size) + f.seek(0, 0) + + for remote in ctx.cluster.remotes.iterkeys(): + teuthology.write_file(remote=remote, + path='{tdir}/logrotate.ceph-test.conf'.format(tdir=testdir), + data=StringIO(conf) + ) + remote.run( + args=[ + 'sudo', + 'mv', + '{tdir}/logrotate.ceph-test.conf'.format(tdir=testdir), + '/etc/logrotate.d/ceph-test.conf', + run.Raw('&&'), + 'sudo', + 'chmod', + '0644', + '/etc/logrotate.d/ceph-test.conf', + run.Raw('&&'), + 'sudo', + 'chown', + 'root.root', + '/etc/logrotate.d/ceph-test.conf' + ] + ) - if ctx.config.get('mds-log-rotate'): - log.info('Setting up mds logrotate') - write_rotate_conf(ctx) + if ctx.config.get('log-rotate'): + daemons = ctx.config.get('log-rotate') + log.info('Setting up log rotation with ' + str(daemons)) + write_rotate_conf(ctx, daemons) logrotater = Rotater() logrotater.begin() try: yield finally: - if ctx.config.get('mds-log-rotate'): - log.info('Shutting down mds logrotate') + if ctx.config.get('log-rotate'): + log.info('Shutting down logrotate') logrotater.end() ctx.cluster.run( args=['sudo', 'rm', '/etc/logrotate.d/ceph-test.conf' diff --git a/tasks/logrotate.conf b/tasks/logrotate.conf index eeb99afdfafd5..b0cb8012fefd4 100644 --- a/tasks/logrotate.conf +++ b/tasks/logrotate.conf @@ -1,11 +1,13 @@ -/var/log/ceph/*mds*.log { +/var/log/ceph/*{daemon_type}*.log {{ rotate 100 - size 1M + size {max_size} compress sharedscripts postrotate - killall ceph-mds -1 || true + killall {daemon_type} -1 || true endscript missingok notifempty -} \ No newline at end of file + su root root +}} + -- 2.39.5