]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph: support arbitrarily-named daemons in logrotate
authorGreg Farnum <gfarnum@redhat.com>
Thu, 28 May 2015 22:54:15 +0000 (15:54 -0700)
committerGreg Farnum <gfarnum@redhat.com>
Tue, 9 Jun 2015 00:36:49 +0000 (17:36 -0700)
And make it more configurable in terms of sizes.

Signed-off-by: Greg Farnum <gfarnum@redhat.com>
tasks/ceph.py
tasks/logrotate.conf

index 8396567210f7a9db857cd48aa28982f5f719fa22..3b9a35335364ee3026b1dedc1f7162172b2303f6 100644 (file)
@@ -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'
index eeb99afdfafd5fda0cac3449b1ac3fb0c3930f19..b0cb8012fefd4a2d26826b340ff0e631a65164c9 100644 (file)
@@ -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
+}}
+