guix-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] gnu: rottlog: rotate messages daily.


From: Jan Nieuwenhuizen
Subject: Re: [PATCH] gnu: rottlog: rotate messages daily.
Date: Wed, 14 Sep 2016 20:30:06 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux)

Ludovic Courtès writes:

> I would add /var/log/{secure,shepherd.log}, but weekly is probably
> enough.

Ok.  I implemented this by changing the rottlog package that already
modifies etc/weekly.  I'm not sure if sending SIGHUP to syslog is
ok for shepherd.log or that would need to be a kill 1?  See attached.

>> * gnu/services/admin.scm: New file.
>> * gnu/local.mk (GNU_SYSTEM_MODULES): Add it.
>
> I think we’re pretty much there!

Silly me, asking if we already ad log rotation ;-)

>> +  (rc-file rottlog-rc-file)
>                              ^
> With: (default (file-append rottlog "/etc/rc")).

OK.

>> +  (periods rottlog-periods)
>
> Maybe s/periods/periodic-rotations/ ?
> Also with default rotation.

Sure, done.

>> +  (jobs rottlog-jobs))
>
> We should have a sane default here, like running it twice a day (which
> can’t hurt because “The logfiles cannot be modified multiple times per
> period”, says the manual.)

OK, great!

> It’s a good idea to mark the expected types of each field in the margin
> (until we have a type system ;-)).

Ah yes.  Done.

> You can remove it and use ‘file-union’ from (gnu services), which is
> roughly the same (it expects a list of tuples instead of a list of
> pairs.)

Ok (I hope...it works what I have, but the apparent need I found for
having "rottlog" twice confuses me).

>> +(define* (rottlog-service
>
> This can be omitted.  It’s enough to expose ‘rottlog-service-type’ and
> ‘rottlog-configuration’.

Hmm.  I removed all the defaulting here and then removed the function
alltogether, but then I cannot seem to do

  (services (cons* (mcron-service) (rottlog-service) %base-services)))

anymore.  Is that right?

I'm feeling a bit stubborn keeping this but I thought that's what we
want and my test showed me that this is needed.  So I kept a minimal of
this function.  Please just remove+enlighten me how to use it if this
can really go :-)

> The last thing that’s missing is a “Log Rotation” section in guix.texi,
> with cross-references to the rottlog manual, like “Scheduled Job
> Execution” does.  Could you look into it?

Added.

Greetings,
Jan

>From e8e489db62337c6e8ef03e745a56938566e078c8 Mon Sep 17 00:00:00 2001
From: Jan Nieuwenhuizen <address@hidden>
Date: Wed, 14 Sep 2016 19:04:38 +0200
Subject: [PATCH 1/2] gnu: update rottlog: install guix-specific etc/weekly.

* gnu/packages/admin.scm (rottlog): Install guix-specific etc/weekly
for rotating /var/log/{messages,secureshepherd.log}.
---
 gnu/packages/admin.scm | 32 ++++++++++++++++++++++++++------
 1 file changed, 26 insertions(+), 6 deletions(-)

diff --git a/gnu/packages/admin.scm b/gnu/packages/admin.scm
index 3685633..9cd51b5 100644
--- a/gnu/packages/admin.scm
+++ b/gnu/packages/admin.scm
@@ -751,12 +751,32 @@ over ssh connections.")
                       #t))
                   (add-before 'install 'tweak-rc-weekly
                     (lambda _
-                      (substitute* "rc/weekly"
-                        (("/bin/kill")
-                         (which "kill"))
-                        (("syslogd\\.pid")
-                         ;; The file is called 'syslog.pid' (no 'd').
-                         "syslog.pid"))
+                      (let ((kill (which "kill"))
+                            (weekly (open-file "rc/weekly" "w")))
+                        (format weekly "
+/var/log/messages {
+       sharedscripts
+       postrotate
+               ~a -HUP $(cat /var/run/syslog.pid) 2> /dev/null
+       endscript
+       nocompress
+}
+/var/log/secure {
+       sharedscripts
+       postrotate
+               ~a -HUP $(cat /var/run/syslog.pid) 2> /dev/null
+       endscript
+       nocompress
+}
+/var/log/shepherd.log {
+       sharedscripts
+       postrotate
+               ~a -HUP $(cat /var/run/syslog.pid) 2> /dev/null
+       endscript
+       nocompress
+}
+" kill kill kill)
+                        (close weekly))
                       #t))
                   (add-after 'install 'install-info
                     (lambda _
-- 
2.10.0

>From 59213cce5d6d4e41f9b6f321e3fef056cccc7c22 Mon Sep 17 00:00:00 2001
From: Jan Nieuwenhuizen <address@hidden>
Date: Thu, 8 Sep 2016 01:20:43 +0200
Subject: [PATCH 2/2] gnu: services: add rottlog.

* gnu/services/admin.scm: New file.
* gnu/local.mk (GNU_SYSTEM_MODULES): Add it.
* doc/guix.texi (Log Rotation): Document it.
---
 doc/guix.texi          | 69 +++++++++++++++++++++++++++++++++++++++++++-
 gnu/local.mk           |  1 +
 gnu/services/admin.scm | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 147 insertions(+), 1 deletion(-)
 create mode 100644 gnu/services/admin.scm

diff --git a/doc/guix.texi b/doc/guix.texi
index d5ece55..c3cfe9e 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -26,7 +26,8 @@ Copyright @copyright{} 2016 Ben address@hidden
 Copyright @copyright{} 2016 Chris address@hidden
 Copyright @copyright{} 2016 Efraim address@hidden
 Copyright @copyright{} 2016 John address@hidden
-Copyright @copyright{} 2016 ng0
+Copyright @copyright{} 2016 address@hidden
+Copyright @copyright{} 2016 Jan Nieuwenhuizen
 
 Permission is granted to copy, distribute and/or modify this document
 under the terms of the GNU Free Documentation License, Version 1.3 or
@@ -213,6 +214,7 @@ Services
 
 * Base Services::               Essential system services.
 * Scheduled Job Execution::     The mcron service.
+* Log Rotation::                The rottlog service.
 * Networking Services::         Network setup, SSH daemon, etc.
 * X Window::                    Graphical display.
 * Desktop Services::            D-Bus and desktop services.
@@ -7622,6 +7624,7 @@ declaration.
 @menu
 * Base Services::               Essential system services.
 * Scheduled Job Execution::     The mcron service.
+* Log Rotation::                The rottlog service.
 * Networking Services::         Network setup, SSH daemon, etc.
 * X Window::                    Graphical display.
 * Desktop Services::            D-Bus and desktop services.
@@ -8096,6 +8099,70 @@ specifications,, mcron, address@hidden).
 @end deftp
 
 
address@hidden Log Rotation
address@hidden Log Rotation
+
address@hidden rottlog
address@hidden log rotation
+The @code{(gnu services admin)} module provides an interface to
address@hidden, a log rotator @pxref{rottlog,,,GNU Rot[t]log Manual}.
+
+The example below defines an operating system that provides
+log rotation.
+
address@hidden
+(use-modules (guix) (gnu) (gnu services admin) (gnu services mcron))
+(use-package-modules base idutils)
+
+(operating-system
+  ;; @dots{}
+  (services (cons* (mcron-service)
+                   (rottlog-service) 
+                   %base-services)))
address@hidden lisp
+
address@hidden {Scheme Procedure} rottlog-service address@hidden
+Return an rottlog service running @var{rottlog} that rotates log files 
according
+to configuration @var{config}.
+
+This is a shorthand for:
address@hidden
+(service rottlog-service-type
+         (rottlog-configuration (rottlog rottlog)
+                                (rc-file rc-file)
+                                (periodic-rotations periodic-rotationsn)
+                                (jobs jobs))
address@hidden example
address@hidden deffn
+
address@hidden {Scheme Variable} rottlog-service-type
+This is the type of the @code{rottlog} service, whose value is an
address@hidden object.
+
+This service type can define @var{mcron}-jobs (@pxref{Scheduled Job
+Execution}) to run the rottlog service.
address@hidden defvr
+
address@hidden {Data Type} rottlog-configuration
+Data type representing the configuration of rottlog.
+
address@hidden @asis
address@hidden @code{rottlog} (default: @var{rottlog})
+The rottlog package to use.
+
address@hidden @code{rc-file} (default: (file-append rottlog "/etc/rc")
+The rottlog @var{rc-file} to use.
+
address@hidden @code{periodic-rotations} (default: `(("weekly" ,(file-append 
rottlog "/etc/weekly")))
+An alist of rottlog configuration file specifications.
+
address@hidden @code{jobs}
+This is a list of gexps (@pxref{G-Expressions}), where each gexp
+corresponds to an mcron job specification (@pxref{Syntax, mcron job
+specifications,, mcron, address@hidden).
address@hidden table
address@hidden deftp
+
 @node Networking Services
 @subsubsection Networking Services
 
diff --git a/gnu/local.mk b/gnu/local.mk
index 0da41f7..baa10f9 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -381,6 +381,7 @@ GNU_SYSTEM_MODULES =                                \
   %D%/packages/zip.scm                         \
                                                \
   %D%/services.scm                             \
+  %D%/services/admin.scm                       \
   %D%/services/avahi.scm                       \
   %D%/services/base.scm                                \
   %D%/services/databases.scm                   \
diff --git a/gnu/services/admin.scm b/gnu/services/admin.scm
new file mode 100644
index 0000000..b3a7906
--- /dev/null
+++ b/gnu/services/admin.scm
@@ -0,0 +1,78 @@
+;;; GNU Guix --- Functional package management for GNU
+;;; Copyright © 2016 Jan Nieuwenhuizen <address@hidden>
+;;;
+;;; This file is part of GNU Guix.
+;;;
+;;; GNU Guix is free software; you can redistribute it and/or modify it
+;;; under the terms of the GNU General Public License as published by
+;;; the Free Software Foundation; either version 3 of the License, or (at
+;;; your option) any later version.
+;;;
+;;; GNU Guix 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 General Public License for more details.
+;;;
+;;; You should have received a copy of thye GNU General Public License
+;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.
+
+(define-module (gnu services admin)
+  #:use-module (gnu packages admin)
+  #:use-module (gnu packages base)
+  #:use-module (gnu services)
+  #:use-module (gnu services mcron)
+  #:use-module (gnu services shepherd)
+  #:use-module (guix gexp)
+  #:use-module (guix records)
+  #:export (rottlog-configuration
+            rottlog-configuration?
+            rottlog-service
+            rottlog-service-type))
+
+;;; Commentary:
+;;;
+;;; This module implements configuration of rottlog by writing
+;;; /etc/rottlog/{rc,hourly|daily|weekly}.  Example usage
+;;; 
+;;;     (mcron-service)
+;;;     (rottlog-service)
+;;;
+;;; Code:
+
+(define-record-type* <rottlog-configuration>
+  rottlog-configuration make-rottlog-configuration
+  rottlog-configuration?
+  (rottlog            rottlog-rottlog            ; package
+                      (default rottlog))
+  (rc-file rottlog-rc-file                       ; file
+                      (default (file-append rottlog "/etc/rc")))
+  (periodic-rotations rottlog-periodic-rotations ; list of (name file) tuples
+                      (default `(("weekly"
+                                  ,(file-append rottlog "/etc/weekly")))))
+  (jobs rottlog-jobs                             ; list of <mcron-job>
+        (default
+          (list #~(job
+                   '(next-hour '(0))
+                   (lambda ()
+                     (system (string-append #$rottlog "/sbin/rottlog"))))
+                #~(job
+                   '(next-hour '(12))
+                   (lambda ()
+                     (system (string-append #$rottlog "/sbin/rottlog"))))))))
+
+(define (rottlog-etc config)
+  `(("rottlog" ,(file-union "rottlog"
+                            (cons `("rc" ,(rottlog-rc-file config))
+                                  (rottlog-periodic-rotations config))))))
+
+(define rottlog-service-type
+  (service-type (name 'rottlog)
+                (extensions
+                 (list
+                  (service-extension etc-service-type rottlog-etc)
+                  (service-extension mcron-service-type rottlog-jobs)))))
+
+(define* (rottlog-service #:optional (config (rottlog-configuration)))
+  (service rottlog-service-type config))
+
+;;; admin.scm ends here
-- 
2.10.0


-- 
Jan Nieuwenhuizen <address@hidden> | GNU LilyPond http://lilypond.org
Freelance IT http://JoyofSource.com | Avatar®  http://AvatarAcademy.nl  

reply via email to

[Prev in Thread] Current Thread [Next in Thread]