[Checkins] SVN: zc.zope3recipes/trunk/ Added support for creating logrotate scripts when using a deployment recipe.

Christian Zagrodnick cz at gocept.com
Fri Nov 14 09:07:58 EST 2008


Log message for revision 92925:
  Added support for creating logrotate scripts when using a deployment recipe.
  
  

Changed:
  U   zc.zope3recipes/trunk/README.txt
  U   zc.zope3recipes/trunk/zc/zope3recipes/README.txt
  U   zc.zope3recipes/trunk/zc/zope3recipes/recipes.py
  U   zc.zope3recipes/trunk/zc/zope3recipes/tests.py

-=-
Modified: zc.zope3recipes/trunk/README.txt
===================================================================
--- zc.zope3recipes/trunk/README.txt	2008-11-14 14:07:25 UTC (rev 92924)
+++ zc.zope3recipes/trunk/README.txt	2008-11-14 14:07:58 UTC (rev 92925)
@@ -23,6 +23,7 @@
 
 Added the "newest=false" option in the SetUp to prevent upgrade during tests
 
+Added support for creating logrotate scripts when using a deployment recipe.
 
 ==================
 0.7.0 (2008/02/01)

Modified: zc.zope3recipes/trunk/zc/zope3recipes/README.txt
===================================================================
--- zc.zope3recipes/trunk/zc/zope3recipes/README.txt	2008-11-14 14:07:25 UTC (rev 92924)
+++ zc.zope3recipes/trunk/zc/zope3recipes/README.txt	2008-11-14 14:07:58 UTC (rev 92925)
@@ -1504,6 +1504,10 @@
     The name of the directory where run-control scripts should be
     installed.
 
+logrotate-directory
+    The name ot the directory where logrotate configuration files should be
+    installed.
+    
 user
     The name of a user that processes should run as.
 
@@ -1516,6 +1520,7 @@
     >>> mkdir(root, 'etc')
     >>> mkdir(root, 'etc', 'myapp-run')
     >>> mkdir(root, 'etc', 'init.d')
+    >>> mkdir(root, 'etc', 'logrotate.d')
 
     >>> write('buildout.cfg',
     ... '''
@@ -1556,6 +1561,7 @@
     ... name = myapp-run
     ... etc-directory = %(root)s/etc/myapp-run
     ... rc-directory = %(root)s/etc/init.d
+    ... logrotate-directory = %(root)s/etc/logrotate.d
     ... log-directory = %(root)s/var/log/myapp-run
     ... run-directory = %(root)s/var/run/myapp-run
     ... user = zope
@@ -1602,6 +1608,12 @@
 Note that the deployment name is added as a prefix of the control
 script name.
 
+The logrotate file is in the logrotate.d directory:
+
+    >>> ls(root, 'etc', 'logrotate.d')
+    -  myapp-run-instance
+
+
 The configuration files have changed to reflect the deployment
 locations:
 
@@ -1648,6 +1660,25 @@
       </logfile>
     </eventlog>
 
+    >>> cat(root, 'etc', 'logrotate.d', 'myapp-run-instance')
+    /root/var/log/myapp-run/instance-access.log {
+      rotate 5
+      weekly
+      postrotate
+        /root/etc/init.d/myapp-run-instance reopen_transcript
+      endscript
+    }
+    <BLANKLINE>
+    <BLANKLINE>
+    /root/var/log/myapp-run/instance-z3.log {
+      rotate 5
+      weekly
+      postrotate
+        /root/etc/init.d/myapp-run-instance reopen_transcript
+      endscript
+    }
+    
+
 If we provide an alternate instance name, that will be reflected in
 the generated files:
 
@@ -1692,6 +1723,7 @@
     ... name = myapp-run
     ... etc-directory = %(root)s/etc/myapp-run
     ... rc-directory = %(root)s/etc/init.d
+    ... logrotate-directory = %(root)s/etc/logrotate.d
     ... log-directory = %(root)s/var/log/myapp-run
     ... run-directory = %(root)s/var/run/myapp-run
     ... user = zope
@@ -1749,6 +1781,7 @@
       </logfile>
     </eventlog>
 
+
 Defining multiple similar instances
 -----------------------------------
 
@@ -1804,6 +1837,7 @@
     ... name = myapp-run
     ... etc-directory = %(root)s/etc/myapp-run
     ... rc-directory = %(root)s/etc/init.d
+    ... logrotate-directory = %(root)s/etc/logrotate.d
     ... log-directory = %(root)s/var/log/myapp-run
     ... run-directory = %(root)s/var/run/myapp-run
     ... user = zope

Modified: zc.zope3recipes/trunk/zc/zope3recipes/recipes.py
===================================================================
--- zc.zope3recipes/trunk/zc/zope3recipes/recipes.py	2008-11-14 14:07:25 UTC (rev 92924)
+++ zc.zope3recipes/trunk/zc/zope3recipes/recipes.py	2008-11-14 14:07:58 UTC (rev 92925)
@@ -190,6 +190,8 @@
             options['run-directory'] = buildout[deployment]['run-directory']
             options['log-directory'] = buildout[deployment]['log-directory']
             options['etc-directory'] = buildout[deployment]['etc-directory']
+            options['logrotate-directory'] = buildout[deployment][
+                'logrotate-directory']
             options['user'] = buildout[deployment]['user']
         else:
             options['bin-directory'] = buildout['buildout']['bin-directory']
@@ -214,8 +216,11 @@
             socket_path = os.path.join(run_directory,
                                        self.name+'-zdaemon.sock')
             rc = deployment + '-' + self.name
+            logrotate_path = os.path.join(options['logrotate-directory'],
+                                          rc)
             creating = [zope_conf_path, zdaemon_conf_path,
                         os.path.join(options['bin-directory'], rc),
+                        logrotate_path,
                         ]
         else:
             zope_conf_path = os.path.join(run_directory, 'zope.conf')
@@ -307,6 +312,22 @@
             open(zope_conf_path, 'w').write(str(zope_conf))
             open(zdaemon_conf_path, 'w').write(str(zdaemon_conf))
 
+            if deployment:
+                logrotate_access_log = logrotate_template % dict(
+                    logfile=access_log_path,
+                    rc=os.path.join(options['bin-directory'], rc),
+                    conf=zdaemon_conf_path,
+                )
+                logrotate_event_log = logrotate_template % dict(
+                    logfile=event_log_path,
+                    rc=os.path.join(options['bin-directory'], rc),
+                    conf=zdaemon_conf_path,
+                )
+                open(logrotate_path, 'w').write(
+                    logrotate_access_log
+                    + '\n\n'
+                    + logrotate_event_log)
+
             if WIN:
                 zc.buildout.easy_install.scripts(
                     [(rc, 'zc.zope3recipes.winctl', 'main')],
@@ -404,7 +425,16 @@
 </eventlog>
 """
 
+logrotate_template = """%(logfile)s {
+  rotate 5
+  weekly
+  postrotate
+    %(rc)s reopen_transcript
+  endscript
+}
+"""
 
+
 ftesting_base = """
 <configure
    xmlns="http://namespaces.zope.org/zope"

Modified: zc.zope3recipes/trunk/zc/zope3recipes/tests.py
===================================================================
--- zc.zope3recipes/trunk/zc/zope3recipes/tests.py	2008-11-14 14:07:25 UTC (rev 92924)
+++ zc.zope3recipes/trunk/zc/zope3recipes/tests.py	2008-11-14 14:07:58 UTC (rev 92925)
@@ -134,6 +134,7 @@
     >>> mkdir(root, 'etc')
     >>> mkdir(root, 'etc', 'myapp-run')
     >>> mkdir(root, 'etc', 'init.d')
+    >>> mkdir(root, 'etc', 'logrotate.d')
 
     >>> write('buildout.cfg',
     ... '''
@@ -170,6 +171,7 @@
     ... [myapp-run]
     ... etc-directory = %(root)s/etc/myapp-run
     ... rc-directory = %(root)s/etc/init.d
+    ... logrotate-directory = %(root)s/etc/logrotate.d
     ... log-directory = %(root)s/var/log/myapp-run
     ... run-directory = %(root)s/var/run/myapp-run
     ... user = zope



More information about the Checkins mailing list