Patchwork gnu: rottlog: rotate messages daily.

login
register
mail settings
Submitter Jan Nieuwenhuizen
Date Sept. 12, 2016, 9:35 p.m.
Message ID <87eg4ou7h5.fsf@gnu.org>
Download mbox | patch
Permalink /patch/15547/
State New
Headers show

Comments

Jan Nieuwenhuizen - Sept. 12, 2016, 9:35 p.m.
Ludovic Courtès writes:

Hi!

>> I made an attempt at a simple version of such a service.  Its currently
>> just copying rc and writing a daily/weekly, find a working example
>> attached.
>
> Great!  Comments below.

Thanks...new patch attached!

> It’s possible to make it so that users only need to write:
>
>   (mcron-service) (rottlog-service)

Nice; done!

>> +(define-record-type* <rottlog-configuration>

> It should also have a ‘rottlog’ field, to specify the rottlog package
> being used.

Ok.

> I think it’d be best to let the user pass the files, and put them in
> /etc/rottlog by extending ‘etc-service-type’.

Ah, yes.  That's a good idea.

> Thus, this would also extend mcron-service-type and etc-service-type.

Okay.

>
>> +(define* (rottlog-service #:key (period 'daily) (initialize? #t))
>> +  (service rottlog-service-type
>> +           (rottlog-configuration (period period)
>> +                                  (initialize? initialize?))))
>
> The configuration probably contain something like an list of name/config
> pairs as well as an ‘rc’ file, along these lines:
>
>   (rottlog-configuration
>     (periods `(("weekly" . ,(file-append rottlog "/etc/weekly))
>                ("daily" . ,(plain-file "daily" "…"))))
>     (rc-file (file-append rottlog "/etc/rc")))

I think I have this too now.

> Of course we should provide default config values that take care of
> common files such as /var/log/{messages,Xorg.0.log} in a reasonable way.

Hmm, yes.  Input appreciated here!  Currently I just use the rottlog
defaults except for using daily instead of weekly rotations, only
rotating /var/log/messages.  On my box, that seems to be the only file
that really needs rotation atm.  Is that sane?

> WDYT?

Very nice, I think we're a lot closer now.

Greetings,
Jan
Ludovic Courtès - Sept. 13, 2016, 9:41 p.m.
Halo!

Jan Nieuwenhuizen <janneke@gnu.org> skribis:

> Ludovic Courtès writes:

[...]

>> The configuration probably contain something like an list of name/config
>> pairs as well as an ‘rc’ file, along these lines:
>>
>>   (rottlog-configuration
>>     (periods `(("weekly" . ,(file-append rottlog "/etc/weekly))
>>                ("daily" . ,(plain-file "daily" "…"))))
>>     (rc-file (file-append rottlog "/etc/rc")))
>
> I think I have this too now.
>
>> Of course we should provide default config values that take care of
>> common files such as /var/log/{messages,Xorg.0.log} in a reasonable way.
>
> Hmm, yes.  Input appreciated here!  Currently I just use the rottlog
> defaults except for using daily instead of weekly rotations, only
> rotating /var/log/messages.  On my box, that seems to be the only file
> that really needs rotation atm.  Is that sane?

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

> From 8b5e5245b066f13c4cef6e5371cdcb84f2d84085 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.

I think we’re pretty much there!

> +(define-record-type* <rottlog-configuration>
> +  rottlog-configuration make-rottlog-configuration
> +  rottlog-configuration?
> +  (rottlog rottlog-rottlog (default rottlog))
> +  (rc-file rottlog-rc-file)
                             ^
With: (default (file-append rottlog "/etc/rc")).

> +  (periods rottlog-periods)

Maybe s/periods/periodic-rotations/ ?
Also with default rotation.

> +  (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.)

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

> +(define (files-alist->directory files)
> +  (define builder
> +    #~(begin
> +        (use-modules (ice-9 match))
> +        (mkdir #$output)
> +
> +        (for-each (lambda (name file)
> +                    (symlink file (string-append #$output "/" name)))
> +                  '#$(map car files)
> +                  '#$(map cdr files))))
> +  
> +    (computed-file "rottlog" builder))

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.)

> +(define* (rottlog-service

This can be omitted.  It’s enough to expose ‘rottlog-service-type’ and
‘rottlog-configuration’.

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?

Thank you!

Ludo’.

Patch

From 8b5e5245b066f13c4cef6e5371cdcb84f2d84085 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.
---
 gnu/local.mk           |  1 +
 gnu/services/admin.scm | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 95 insertions(+)
 create mode 100644 gnu/services/admin.scm

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..0e76e66
--- /dev/null
+++ b/gnu/services/admin.scm
@@ -0,0 +1,94 @@ 
+;;; 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 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 (default rottlog))
+  (rc-file rottlog-rc-file)
+  (periods rottlog-periods)
+  (jobs rottlog-jobs))
+
+(define (files-alist->directory files)
+  (define builder
+    #~(begin
+        (use-modules (ice-9 match))
+        (mkdir #$output)
+
+        (for-each (lambda (name file)
+                    (symlink file (string-append #$output "/" name)))
+                  '#$(map car files)
+                  '#$(map cdr files))))
+  
+    (computed-file "rottlog" builder))
+
+(define (rottlog-etc config)
+  `(("rottlog" ,(files-alist->directory
+                 (cons `("rc" . ,(rottlog-rc-file config))
+                       (rottlog-periods 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
+          #:key
+          (rottlog rottlog)
+          (rc-file (file-append rottlog "/etc/rc"))
+          (periods `(("daily" . ,(file-append rottlog "/etc/weekly"))
+                     ;;("weekly" . ,(plain-file "weekly" "…"))
+                     ;;("weekly" . ,(file-append rottlog "/etc/weekly"))
+                     ;;
+                     ))
+          (jobs (list
+                 #~(job '(next-hour '(5))
+                        (lambda ()
+                          (system (string-append #$rottlog "/sbin/rottlog")))))))
+  
+  (service rottlog-service-type
+           (rottlog-configuration (rottlog rottlog)
+                                  (rc-file rc-file)
+                                  (periods periods)
+                                  (jobs jobs))))
+;;; admin.scm ends here
-- 
2.10.0