[Kimchi-devel] [PATCH v3][Wok] Rotate wok logs

Ramon Medeiros ramonn at linux.vnet.ibm.com
Sat Jan 23 16:42:59 UTC 2016


Use logrotate to compress and keep 10 logs of 10MB

Signed-off-by: Ramon Medeiros <ramonn at linux.vnet.ibm.com>
---
Changes:

v3:
Set log size to 10MB
Use WatchedFileHandler to avoid issues with python logging and logrotate

v2:
Add logrotate as dependency
Fix typo in Copyright 

 Makefile.am                |  2 ++
 contrib/DEBIAN/control.in  |  1 +
 contrib/Makefile.am        |  1 +
 contrib/wok.spec.fedora.in |  2 ++
 contrib/wok.spec.suse.in   |  2 ++
 contrib/wokd.logrotate     | 28 ++++++++++++++++++++++++++++
 src/wok/server.py          |  6 ++----
 7 files changed, 38 insertions(+), 4 deletions(-)
 create mode 100644 contrib/wokd.logrotate

diff --git a/Makefile.am b/Makefile.am
index 278bda1..6d4c574 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -140,6 +140,8 @@ install-data-local:
 	mkdir -p $(DESTDIR)/etc/wok/
 	$(INSTALL_DATA) src/dhparams.pem $(DESTDIR)/etc/wok/dhparams.pem
 	touch $(DESTDIR)/etc/nginx/conf.d/wok.conf
+	mkdir -p $(DESTDIR)/etc/logrotate.d/
+	$(INSTALL_DATA) $(top_srcdir)/contrib/wokd.logrotate $(DESTDIR)/etc/logrotate.d/wokd
 
 uninstall-local:
 	@if test -f $(systemdsystemunitdir)/wokd.service; then \
diff --git a/contrib/DEBIAN/control.in b/contrib/DEBIAN/control.in
index 1f39ad8..e585080 100644
--- a/contrib/DEBIAN/control.in
+++ b/contrib/DEBIAN/control.in
@@ -14,6 +14,7 @@ Depends: python-cherrypy3 (>= 3.2.0),
          python-ldap,
          python-psutil (>= 0.6.0),
          fonts-font-awesome,
+         logrotate,
          texlive-fonts-extra
 Build-Depends: xsltproc,
                gettext,
diff --git a/contrib/Makefile.am b/contrib/Makefile.am
index ed4a006..2939bc9 100644
--- a/contrib/Makefile.am
+++ b/contrib/Makefile.am
@@ -29,6 +29,7 @@ EXTRA_DIST = \
 	wokd-upstart.conf.debian \
 	wokd-upstart.conf.fedora \
 	make-deb.sh.in \
+	wokd.logrotate \
 	$(NULL)
 
 make-deb.sh: make-deb.sh.in $(top_builddir)/config.status
diff --git a/contrib/wok.spec.fedora.in b/contrib/wok.spec.fedora.in
index 34b3ac3..5501a20 100644
--- a/contrib/wok.spec.fedora.in
+++ b/contrib/wok.spec.fedora.in
@@ -19,6 +19,7 @@ Requires:	python-ldap
 Requires:	python-psutil >= 0.6.0
 Requires:	fontawesome-fonts
 Requires:	open-sans-fonts
+Requires:   logrotate
 BuildRequires:	gettext-devel
 BuildRequires:	libxslt
 BuildRequires:	openssl
@@ -116,6 +117,7 @@ rm -rf $RPM_BUILD_ROOT
 %{_sysconfdir}/nginx/conf.d/wok.conf.in
 %{_sysconfdir}/wok/wok.conf
 %{_sysconfdir}/wok/
+%{_sysconfdir}/logrotate.d/wokd
 %{_mandir}/man8/wokd.8.gz
 
 %if 0%{?with_systemd}
diff --git a/contrib/wok.spec.suse.in b/contrib/wok.spec.suse.in
index 7fa660b..9e6b7f2 100644
--- a/contrib/wok.spec.suse.in
+++ b/contrib/wok.spec.suse.in
@@ -20,6 +20,7 @@ Requires:	nginx
 Requires:	python-psutil >= 0.6.0
 Requires:	fontawesome-fonts
 Requires:	google-opensans-fonts
+Requires:   logrotate
 BuildRequires:	gettext-tools
 BuildRequires:	libxslt-tools
 BuildRequires:	openssl
@@ -94,6 +95,7 @@ rm -rf $RPM_BUILD_ROOT
 %{_sysconfdir}/wok/
 %{_sysconfdir}/nginx/conf.d/wok.conf.in
 %{_sysconfdir}/nginx/conf.d/wok.conf
+%{_sysconfdir}/logrotate.d/wokd
 %{_var}/lib/wok/
 %{_localstatedir}/log/wok/*
 %{_localstatedir}/log/wok/
diff --git a/contrib/wokd.logrotate b/contrib/wokd.logrotate
new file mode 100644
index 0000000..ded906f
--- /dev/null
+++ b/contrib/wokd.logrotate
@@ -0,0 +1,28 @@
+#
+# Project Wok
+#
+# Copyright IBM Corp, 2016
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+
+/var/log/wok/*log {
+    daily
+    nomail
+    maxsize 10M
+    rotate 10
+    nomissingok
+    compress
+}
+
diff --git a/src/wok/server.py b/src/wok/server.py
index 4fd380c..31e3c82 100644
--- a/src/wok/server.py
+++ b/src/wok/server.py
@@ -100,8 +100,7 @@ class Server(object):
             cherrypy.log.screen = True
 
         # Create handler to rotate access log file
-        h = logging.handlers.RotatingFileHandler(options.access_log, 'a',
-                                                 10000000, 1000)
+        h = logging.handlers.WatchedFileHandler(options.access_log, 'a', delay=1)
         h.setLevel(logLevel)
         h.setFormatter(cherrypy._cplogging.logfmt)
 
@@ -109,8 +108,7 @@ class Server(object):
         cherrypy.log.access_log.addHandler(h)
 
         # Create handler to rotate error log file
-        h = logging.handlers.RotatingFileHandler(options.error_log, 'a',
-                                                 10000000, 1000)
+        h = logging.handlers.WatchedFileHandler(options.error_log, 'a', delay=1)
         h.setLevel(logLevel)
         h.setFormatter(cherrypy._cplogging.logfmt)
 
-- 
2.1.0




More information about the Kimchi-devel mailing list