all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Jan Nieuwenhuizen <janneke@gnu.org>
To: "Ludovic Courtès" <ludo@gnu.org>
Cc: guix-devel@gnu.org
Subject: Re: [PATCH] gnu: rottlog: rotate messages daily.
Date: Tue, 20 Sep 2016 22:47:26 +0200	[thread overview]
Message-ID: <87eg4epach.fsf@gnu.org> (raw)
In-Reply-To: <87wpi7p2wh.fsf@gnu.org> ("Ludovic \=\?utf-8\?Q\?Court\=C3\=A8s\=22'\?\= \=\?utf-8\?Q\?s\?\= message of "Tue, 20 Sep 2016 14:15:58 +0900")

[-- Attachment #1: Type: text/plain, Size: 4186 bytes --]

Ludovic Courtès writes:

Hi Ludo,!

> The current ‘tweak-rc-weekly’ phase “fixes a bug” in etc/weekly, but I
> don’t think we should do customization in the package itself.  Instead,
> it would be more appropriate to generate/provide the configuration files
> that we need, without further modifying the package itself.  WDYT?

I was thinking it does make some sense to have the installed
...-rottlog/etc/weekly file be functional and somewhat sensible for
GuixSD.  Otoh, patching rottlog with our specific configuration feels
wrong.

So let's do it like you suggest, I think that makes just a bit more
sense.

>> 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.
>
> GuixSD runs syslogd from Inetutils, so it’s not PID 1, fortunately.  ;-)
>
> However, shepherd.log is written by PID_1, indeed, and we shouldn’t send
> SIGHUP to PID 1.  However, I don’t think anything bad will happen if
> rottlog moves shepherd.log and Shepherd doesn’t reopen this file.

Ok, so no kill then for shepherd.log.

> Yes.  Instead, you have to write:
>
>   (services (cons* (service rottlog-service-type
>                             (rottlog-configuration …))
>                    …))

Okay.

> I hope the above sheds some light on this.  WDYT of this idea?

>> * gnu/packages/admin.scm (rottlog): Install guix-specific etc/weekly
>> for rotating /var/log/{messages,secureshepherd.log}.
>
> As discussed above, I think this is the wrong place for this.

Sure, removed.

>> +  (periodic-rotations rottlog-periodic-rotations ; list of (name file) tuples
>> +                      (default `(("weekly"
>> +                                  ,(file-append rottlog "/etc/weekly")))))
>
> Here I would suggest adding somewhere:
>
>
>   (define %rotated-files
>     '("/var/log/messages" …))
>
>   (define (syslog-rotation-config file)
>     (string-append file " {
>     …
>     kill -HUP …
>     …")))

I did not get `.*/bin/kill' right.  There's a big FIXME in the patch.
My first naive attempt (string-append coreutils "/bin/kill") does not
work and I tried several #~ things but I don't really know what I'm
doing there...thats still mostly magic to me.

>   (define (simple-rotation-config file)
>     ;; Same as above, but without “kill -HUP”.
>     …)
>
>   (define %default-rotations
>     `(("weekly" . ,(plain-file "rottlog.weekly"
>                                (string-append (string-join
>                                                (map syslog-rotation-config
>                                                     '("/var/log/messages"…)))
>                                               (simple-rotation-config
>                                                "shepherd.log"))))))
>
> Does that make sense?

Yes, better.  Added something like this.

>> +  (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"))))))))
>
> Please move (list …) to a global variable, to avoid code duplication
> when the macro is expanded.

...moved to a function now...but I don't see what macro you mean (#~ ?)
and when it gets expanded and how that leads to duplication.

I'm not sure if we should export the %default-rotations or if we should
describe their contents in the manual.

> Use ‘system*’ instead of ‘system’ (the latter does “/bin/sh -c”, which
> is unnecessary here.)

Ok.

> Also, this should use the ‘rottlog’ package of <rottlog-configuration>,
> which cannot be referred to from the default value, which is a constant.
> Thus, you may have to change the default to #f, and generate the default
> value upon #f.

Ahh.  Okay, (I think!).

Greetings,
Jan


[-- Attachment #2: 0001-gnu-services-add-rottlog.patch --]
[-- Type: text/x-patch, Size: 8405 bytes --]

From ee1be88f60d70de46009069da020c1bdc4993fd8 Mon Sep 17 00:00:00 2001
From: Jan Nieuwenhuizen <janneke@gnu.org>
Date: Thu, 8 Sep 2016 01:20:43 +0200
Subject: [PATCH] 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          |  55 ++++++++++++++++++++++-
 gnu/local.mk           |   1 +
 gnu/services/admin.scm | 116 +++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 171 insertions(+), 1 deletion(-)
 create mode 100644 gnu/services/admin.scm

diff --git a/doc/guix.texi b/doc/guix.texi
index d5ece55..735e8ac 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -26,7 +26,8 @@ Copyright @copyright{} 2016 Ben Woodcroft@*
 Copyright @copyright{} 2016 Chris Marusich@*
 Copyright @copyright{} 2016 Efraim Flashner@*
 Copyright @copyright{} 2016 John Darrington@*
-Copyright @copyright{} 2016 ng0
+Copyright @copyright{} 2016 ng0@*
+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,56 @@ specifications,, mcron, GNU@tie{}mcron}).
 @end deftp
 
 
+@node Log Rotation
+@subsubsection Log Rotation
+
+@cindex rottlog
+@cindex log rotation
+The @code{(gnu services admin)} module provides an interface to
+GNU@tie{}rottlog, a log rotator @pxref{rottlog,,,GNU Rot[t]log Manual}.
+
+The example below defines an operating system that provides
+log rotation.
+
+@lisp
+(use-modules (guix) (gnu) (gnu services admin) (gnu services mcron))
+(use-package-modules base idutils)
+
+(operating-system
+  ;; @dots{}
+  (services (cons* (mcron-service)
+                   (service rottlog-service-type (rottlog-configuration)) 
+                   %base-services)))
+@end lisp
+
+@defvr {Scheme Variable} rottlog-service-type
+This is the type of the @code{rottlog} service, whose value is an
+@code{rottlog-configuration} object.
+
+This service type can define @var{mcron}-jobs (@pxref{Scheduled Job
+Execution}) to run the rottlog service.
+@end defvr
+
+@deftp {Data Type} rottlog-configuration
+Data type representing the configuration of rottlog.
+
+@table @asis
+@item @code{rottlog} (default: @var{rottlog})
+The rottlog package to use.
+
+@item @code{rc-file} (default: (file-append rottlog "/etc/rc")
+The rottlog @var{rc-file} to use.
+
+@item @code{periodic-rotations} (default: `(("weekly" %default-rotatations)))
+A list of rottlog period-name/period-config tuples.
+
+@item @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, GNU@tie{}mcron}).
+@end table
+@end 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..08c9ab7
--- /dev/null
+++ b/gnu/services/admin.scm
@@ -0,0 +1,116 @@
+;;; GNU Guix --- Functional package management for GNU
+;;; Copyright © 2016 Jan Nieuwenhuizen <janneke@gnu.org>
+;;;
+;;; 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 packages)
+  #: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)
+;;;     (service rottlog-service-typeo (rottlog-configuration))
+;;;
+;;; Code:
+
+(define %rotated-files
+  '("/var/log/messages" "/var/log/secure"))
+
+(define (rotation-config file kill)
+  (string-append file " {
+	sharedscripts
+	postrotate
+" kill
+"	endscript
+	nocompress
+}
+"))
+
+(define (syslog-rotation-config file)
+  (let ((coreutils "/gnu/store/56x9fvx59i300wav3c193h84cp80bslr-coreutils-8.25")) ;; FIXME
+    (rotation-config
+     file
+     (string-append
+      "	"
+      coreutils "/bin/kill -HUP $(cat /var/run/syslog.pid) 2> /dev/null
+"))))
+
+(define (simple-rotation-config file)
+  (rotation-config file ""))
+
+(define %default-rotations
+  `(("weekly" ,(plain-file "rottlog.weekly"
+                           (string-append (string-join
+                                           (map syslog-rotation-config
+                                                %rotated-files)
+                                           "")
+                                          (simple-rotation-config
+                                           "/var/log/shepherd.log"))))))
+
+(define (default-jobs rottlog)
+  (list #~(job
+           '(next-hour '(0))
+           (lambda ()
+             (system* (string-append #$rottlog "/sbin/rottlog"))))
+        #~(job
+           '(next-hour '(12))
+           (lambda ()
+             (system* (string-append #$rottlog "/sbin/rottlog"))))))
+
+(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 %default-rotations))
+  (jobs               rottlog-jobs               ; list of <mcron-job>
+                      (default #f)))
+
+(define (rottlog-etc config)
+  `(("rottlog" ,(file-union "rottlog"
+                            (cons `("rc" ,(rottlog-rc-file config))
+                                  (rottlog-periodic-rotations config))))))
+
+(define (rottlog-jobs-or-default config)
+  (or (rottlog-jobs config)
+      (default-jobs (rottlog-rottlog 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-or-default)))))
+
+;;; admin.scm ends here
-- 
2.10.0


[-- Attachment #3: Type: text/plain, Size: 154 bytes --]


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

  reply	other threads:[~2016-09-20 20:47 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-11 10:52 [PATCH] gnu: rottlog: rotate messages daily Jan Nieuwenhuizen
2016-09-07  9:52 ` Ludovic Courtès
2016-09-07 12:32   ` Jan Nieuwenhuizen
2016-09-09  5:26     ` Jan Nieuwenhuizen
2016-09-11 13:30       ` Ludovic Courtès
2016-09-12 21:35         ` Jan Nieuwenhuizen
2016-09-13 21:41           ` Ludovic Courtès
2016-09-14 18:30             ` Jan Nieuwenhuizen
2016-09-20  5:15               ` Ludovic Courtès
2016-09-20 20:47                 ` Jan Nieuwenhuizen [this message]
2016-09-21 15:32                   ` Ludovic Courtès
2016-09-22 20:51                     ` Jan Nieuwenhuizen
2016-10-02 22:39                       ` Ludovic Courtès

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87eg4epach.fsf@gnu.org \
    --to=janneke@gnu.org \
    --cc=guix-devel@gnu.org \
    --cc=ludo@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.