all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [PATCH] gnu: rottlog: rotate messages daily.
@ 2016-08-11 10:52 Jan Nieuwenhuizen
  2016-09-07  9:52 ` Ludovic Courtès
  0 siblings, 1 reply; 13+ messages in thread
From: Jan Nieuwenhuizen @ 2016-08-11 10:52 UTC (permalink / raw)
  To: guix-devel

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

Hi!

Using the attached patch and the configuration below, rottlog
actually rotates /var/log/messages daily.

Greetings,
Jan

--8<---------------cut here---------------start------------->8---

(use-package-modules admin)
(use-service-modules mcron)

(define rottlog-job
  #~(job '(next-hour '(5))
         (lambda ()
           (system (string-append  #$rottlog "/sbin/rottlog")))))

(define updatedb-job
  ;; Run 'updatedb' at 3AM every day.  Here we write the
  ;; job's action as a Scheme procedure.
  #~(job '(next-hour '(3))
         (lambda ()
           (execl (string-append #$findutils "/bin/updatedb")
                  "updatedb"
                  "--prunepaths=/tmp /var/tmp /gnu/store"))))

...

(operating-system
     ...
    (services
      ...

      (mcron-service (list rottlog-job
                           updatedb-job))
     ...
))
--8<---------------cut here---------------end--------------->8---


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-gnu-rottlog-rotate-messages-daily.patch --]
[-- Type: text/x-patch, Size: 2002 bytes --]

From c7fc570327faeb50503494b370a2f5ab21d4049b Mon Sep 17 00:00:00 2001
From: Jan Nieuwenhuizen <janneke@gnu.org>
Date: Sat, 18 Jun 2016 22:37:48 +0200
Subject: [PATCH] gnu: rottlog: rotate messages daily.

* gnu/packages/admin.scm (rottlog): Set packdir in etc/rc; fixes rotating.
Rename weekly to daily; rotates /var/log/messages daily.
---
 gnu/packages/admin.scm | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/gnu/packages/admin.scm b/gnu/packages/admin.scm
index eada796..f8ba6ef 100644
--- a/gnu/packages/admin.scm
+++ b/gnu/packages/admin.scm
@@ -731,11 +731,21 @@ over ssh connections.")
                                               (assoc-ref %outputs "out")
                                               "/etc")
                                "--localstatedir=/var")
-       #:phases (alist-cons-after
-                 'install 'install-info
-                 (lambda _
-                   (zero? (system* "make" "install-info")))
-                 %standard-phases)))
+       #:phases (modify-phases %standard-phases
+                  (add-after 'build 'set-packdir
+                    (lambda _
+                      (substitute* "rc/rc"
+                        (("packdir=\"\"")
+                         "packdir=\"/var/log\""))))
+                  (add-after 'install 'install-daily
+                    (lambda* (#:key outputs #:allow-other-keys)
+                      (let ((out (assoc-ref outputs "out")))
+                        (zero? (system* "mv"
+                                        (string-append out "/etc/weekly")
+                                        (string-append out "/etc/daily"))))))
+                  (add-after 'install 'install-info
+                    (lambda _
+                      (zero? (system* "make" "install-info")))))))
     (native-inputs `(("texinfo" ,texinfo)
                      ("util-linux" ,util-linux))) ; for 'cal'
     (home-page "http://www.gnu.org/software/rottlog/")
-- 
2.9.2


[-- 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  

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PATCH] gnu: rottlog: rotate messages daily.
  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
  0 siblings, 1 reply; 13+ messages in thread
From: Ludovic Courtès @ 2016-09-07  9:52 UTC (permalink / raw)
  To: Jan Nieuwenhuizen; +Cc: guix-devel

Hi!

Jan Nieuwenhuizen <janneke@gnu.org> skribis:

> Using the attached patch and the configuration below, rottlog
> actually rotates /var/log/messages daily.

Woohoo!

> From c7fc570327faeb50503494b370a2f5ab21d4049b Mon Sep 17 00:00:00 2001
> From: Jan Nieuwenhuizen <janneke@gnu.org>
> Date: Sat, 18 Jun 2016 22:37:48 +0200
> Subject: [PATCH] gnu: rottlog: rotate messages daily.
>
> * gnu/packages/admin.scm (rottlog): Set packdir in etc/rc; fixes rotating.
> Rename weekly to daily; rotates /var/log/messages daily.

I split it in several patches and pushed part of this.

‘rottlog’ was looking for config files in OUT/etc, which made it
impossible for people to configure it.  So in commit
268ad34e0eadf8a015798b5c5587aad65b9f3a61 I changed it to look for
configuration files in /etc/rottlog.

Consequently, running “rottlog” alone won’t work; one has to provide
/etc/rottlog/{rc,daily} first.  We should have a GuixSD service that
does that.

Thoughts?

Thanks,
Ludo’.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH] gnu: rottlog: rotate messages daily.
  2016-09-07  9:52 ` Ludovic Courtès
@ 2016-09-07 12:32   ` Jan Nieuwenhuizen
  2016-09-09  5:26     ` Jan Nieuwenhuizen
  0 siblings, 1 reply; 13+ messages in thread
From: Jan Nieuwenhuizen @ 2016-09-07 12:32 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: guix-devel

Ludovic Courtès writes:

>> Using the attached patch and the configuration below, rottlog
>> actually rotates /var/log/messages daily.
>
> Woohoo!

:-)

Yeah, made me quite happy too.

>> * gnu/packages/admin.scm (rottlog): Set packdir in etc/rc; fixes rotating.
>> Rename weekly to daily; rotates /var/log/messages daily.
>
> I split it in several patches and pushed part of this.

Great, thanks.

> ‘rottlog’ was looking for config files in OUT/etc, which made it
> impossible for people to configure it.  So in commit
> 268ad34e0eadf8a015798b5c5587aad65b9f3a61 I changed it to look for
> configuration files in /etc/rottlog.
>
> Consequently, running “rottlog” alone won’t work; one has to provide
> /etc/rottlog/{rc,daily} first.  We should have a GuixSD service that
> does that.

Ah, yes configuration was the bit I was wondering about.  A service
that initializes/writes these sounds like a good idea!

Greetings,
Jan

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

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH] gnu: rottlog: rotate messages daily.
  2016-09-07 12:32   ` Jan Nieuwenhuizen
@ 2016-09-09  5:26     ` Jan Nieuwenhuizen
  2016-09-11 13:30       ` Ludovic Courtès
  0 siblings, 1 reply; 13+ messages in thread
From: Jan Nieuwenhuizen @ 2016-09-09  5:26 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: guix-devel

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

Jan Nieuwenhuizen writes:

Hi!

>> ‘rottlog’ was looking for config files in OUT/etc, which made it
>> impossible for people to configure it.  So in commit
>> 268ad34e0eadf8a015798b5c5587aad65b9f3a61 I changed it to look for
>> configuration files in /etc/rottlog.
>>
>> Consequently, running “rottlog” alone won’t work; one has to provide
>> /etc/rottlog/{rc,daily} first.  We should have a GuixSD service that
>> does that.
>
> Ah, yes configuration was the bit I was wondering about.  A service
> that initializes/writes these sounds like a good idea!

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.

Greetings,
Jan


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

From cf93c7b59d0dc71ff23b4f9d435106d3844a9b9a 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 | 106 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 107 insertions(+)
 create mode 100644 gnu/services/admin.scm

diff --git a/gnu/local.mk b/gnu/local.mk
index cd29ae0..3fed7fc 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..097e8a6
--- /dev/null
+++ b/gnu/services/admin.scm
@@ -0,0 +1,106 @@
+;;; 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 the 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 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
+;;; 
+;;;   (define rottlog-job
+;;;     #~(job '(next-hour '(5))
+;;;            (lambda ()
+;;;              (system (string-append  #$rottlog "/sbin/rottlog")))))
+;;;
+;;;  Add to operating-system services
+;;;
+;;;     (mcron-service (list rottlog-job))
+;;;     (rottlog-service)
+;;;
+;;; Code:
+
+(define-record-type* <rottlog-configuration>
+  rottlog-configuration make-rottlog-configuration
+  rottlog-configuration?
+  (period rottlog-period)
+  (initialize? rottlog-initialize?))
+
+(define (rottlog-initialization period)
+  "Return the gexp to initialize the ROTTLOG service for PERIOD."
+  #~(begin
+      (use-modules (ice-9 rdelim))
+      (let* ((dir "/etc/rottlog")
+             (period-config (format #f "~a/~a" dir '#$period))
+             (rc-config (string-append dir "/rc")))
+
+        (mkdir-p dir)
+
+        ;; TODO: substitutions
+        (unless (file-exists? rc-config)
+          (format #t "creating rottlog config '~a'...~%" rc-config)
+          (let* ((file (open-file rc-config "w"))
+                 (template (string-append #$rottlog "/etc/rc"))
+                 (config (with-input-from-file template read-string)))
+            (display config file)
+            (close file)))
+
+        ;; TODO: list of periods?
+        (if (not (memq '#$period '(hourly daily weekly)))
+            (format (current-error-port) "cowardly refusing to create rottlog config for unknown period: '~a'~%" '#$period)
+            (unless (file-exists? period-config)
+              (format #t "creating rottlog config'~a'...~%" period-config)
+              (let* ((file (open-file period-config "w")))
+                (format file "/var/log/messages {
+	sharedscripts
+	postrotate
+		~a/bin/kill -HUP $(~a/bin/cat /var/run/syslog.pid) 2> /dev/null
+	endscript
+	nocompress
+}
+" #$coreutils #$coreutils)
+                (close file)))))))
+
+(define (rottlog-activation config)
+  "Return the activation gexp for CONFIG."
+  #~(begin
+      #$(if (rottlog-initialize? config)
+            (rottlog-initialization (rottlog-period config))
+            #t)))
+
+(define rottlog-service-type
+  (service-type (name 'rottlog)
+                (extensions
+                 (list (service-extension activation-service-type
+                                          rottlog-activation)))))
+
+(define* (rottlog-service #:key (period 'daily) (initialize? #t))
+  (service rottlog-service-type
+           (rottlog-configuration (period period)
+                                  (initialize? initialize?))))
+;;; admin.scm ends here
-- 
2.9.3


[-- 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  

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PATCH] gnu: rottlog: rotate messages daily.
  2016-09-09  5:26     ` Jan Nieuwenhuizen
@ 2016-09-11 13:30       ` Ludovic Courtès
  2016-09-12 21:35         ` Jan Nieuwenhuizen
  0 siblings, 1 reply; 13+ messages in thread
From: Ludovic Courtès @ 2016-09-11 13:30 UTC (permalink / raw)
  To: Jan Nieuwenhuizen; +Cc: guix-devel

Hello!

Jan Nieuwenhuizen <janneke@gnu.org> skribis:

>>> ‘rottlog’ was looking for config files in OUT/etc, which made it
>>> impossible for people to configure it.  So in commit
>>> 268ad34e0eadf8a015798b5c5587aad65b9f3a61 I changed it to look for
>>> configuration files in /etc/rottlog.
>>>
>>> Consequently, running “rottlog” alone won’t work; one has to provide
>>> /etc/rottlog/{rc,daily} first.  We should have a GuixSD service that
>>> does that.
>>
>> Ah, yes configuration was the bit I was wondering about.  A service
>> that initializes/writes these sounds like a good idea!
>
> 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.

> From cf93c7b59d0dc71ff23b4f9d435106d3844a9b9a 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.

[...]

> +;;;  Add to operating-system services
> +;;;
> +;;;     (mcron-service (list rottlog-job))
> +;;;     (rottlog-service)

It’s possible to make it so that users only need to write:

  (mcron-service) (rottlog-service)

(See below.)

> +(define-record-type* <rottlog-configuration>
> +  rottlog-configuration make-rottlog-configuration
> +  rottlog-configuration?
> +  (period rottlog-period)
> +  (initialize? rottlog-initialize?))

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

> +(define (rottlog-initialization period)
> +  "Return the gexp to initialize the ROTTLOG service for PERIOD."
> +  #~(begin
> +      (use-modules (ice-9 rdelim))
> +      (let* ((dir "/etc/rottlog")
> +             (period-config (format #f "~a/~a" dir '#$period))
> +             (rc-config (string-append dir "/rc")))
> +
> +        (mkdir-p dir)
> +
> +        ;; TODO: substitutions
> +        (unless (file-exists? rc-config)
> +          (format #t "creating rottlog config '~a'...~%" rc-config)
> +          (let* ((file (open-file rc-config "w"))
> +                 (template (string-append #$rottlog "/etc/rc"))
> +                 (config (with-input-from-file template read-string)))
> +            (display config file)
> +            (close file)))
> +
> +        ;; TODO: list of periods?
> +        (if (not (memq '#$period '(hourly daily weekly)))
> +            (format (current-error-port) "cowardly refusing to create rottlog config for unknown period: '~a'~%" '#$period)
> +            (unless (file-exists? period-config)
> +              (format #t "creating rottlog config'~a'...~%" period-config)
> +              (let* ((file (open-file period-config "w")))
> +                (format file "/var/log/messages {
> +	sharedscripts
> +	postrotate
> +		~a/bin/kill -HUP $(~a/bin/cat /var/run/syslog.pid) 2> /dev/null
> +	endscript
> +	nocompress
> +}
> +" #$coreutils #$coreutils)
> +                (close file)))))))
> +
> +(define (rottlog-activation config)
> +  "Return the activation gexp for CONFIG."
> +  #~(begin
> +      #$(if (rottlog-initialize? config)
> +            (rottlog-initialization (rottlog-period config))
> +            #t)))

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

> +(define rottlog-service-type
> +  (service-type (name 'rottlog)
> +                (extensions
> +                 (list (service-extension activation-service-type
> +                                          rottlog-activation)))))

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

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

That way users would have all the latitude to configure the behavior of
rottlog.

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.

WDYT?

Thank you!

Ludo’.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH] gnu: rottlog: rotate messages daily.
  2016-09-11 13:30       ` Ludovic Courtès
@ 2016-09-12 21:35         ` Jan Nieuwenhuizen
  2016-09-13 21:41           ` Ludovic Courtès
  0 siblings, 1 reply; 13+ messages in thread
From: Jan Nieuwenhuizen @ 2016-09-12 21:35 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: guix-devel

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

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


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

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


[-- 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  

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PATCH] gnu: rottlog: rotate messages daily.
  2016-09-12 21:35         ` Jan Nieuwenhuizen
@ 2016-09-13 21:41           ` Ludovic Courtès
  2016-09-14 18:30             ` Jan Nieuwenhuizen
  0 siblings, 1 reply; 13+ messages in thread
From: Ludovic Courtès @ 2016-09-13 21:41 UTC (permalink / raw)
  To: Jan Nieuwenhuizen; +Cc: guix-devel

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

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH] gnu: rottlog: rotate messages daily.
  2016-09-13 21:41           ` Ludovic Courtès
@ 2016-09-14 18:30             ` Jan Nieuwenhuizen
  2016-09-20  5:15               ` Ludovic Courtès
  0 siblings, 1 reply; 13+ messages in thread
From: Jan Nieuwenhuizen @ 2016-09-14 18:30 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: guix-devel

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

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


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-gnu-update-rottlog-install-guix-specific-etc-weekly.patch --]
[-- Type: text/x-patch, Size: 1797 bytes --]

From e8e489db62337c6e8ef03e745a56938566e078c8 Mon Sep 17 00:00:00 2001
From: Jan Nieuwenhuizen <janneke@gnu.org>
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


[-- Attachment #3: 0002-gnu-services-add-rottlog.patch --]
[-- Type: text/x-patch, Size: 7899 bytes --]

From 59213cce5d6d4e41f9b6f321e3fef056cccc7c22 Mon Sep 17 00:00:00 2001
From: Jan Nieuwenhuizen <janneke@gnu.org>
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 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,70 @@ 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)
+                   (rottlog-service) 
+                   %base-services)))
+@end lisp
+
+@deffn {Scheme Procedure} rottlog-service [@var{config}]
+Return an rottlog service running @var{rottlog} that rotates log files according
+to configuration @var{config}.
+
+This is a shorthand for:
+@example
+(service rottlog-service-type
+         (rottlog-configuration (rottlog rottlog)
+                                (rc-file rc-file)
+                                (periodic-rotations periodic-rotationsn)
+                                (jobs jobs))
+@end example
+@end deffn
+
+@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" ,(file-append rottlog "/etc/weekly")))
+An alist of rottlog configuration file specifications.
+
+@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..b3a7906
--- /dev/null
+++ b/gnu/services/admin.scm
@@ -0,0 +1,78 @@
+;;; 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            ; 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


[-- Attachment #4: Type: text/plain, Size: 156 bytes --]



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

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PATCH] gnu: rottlog: rotate messages daily.
  2016-09-14 18:30             ` Jan Nieuwenhuizen
@ 2016-09-20  5:15               ` Ludovic Courtès
  2016-09-20 20:47                 ` Jan Nieuwenhuizen
  0 siblings, 1 reply; 13+ messages in thread
From: Ludovic Courtès @ 2016-09-20  5:15 UTC (permalink / raw)
  To: Jan Nieuwenhuizen; +Cc: guix-devel

Hello Jan!

Jan Nieuwenhuizen <janneke@gnu.org> skribis:

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

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

>>> +(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?

Yes.  Instead, you have to write:

  (services (cons* (service rottlog-service-type
                            (rottlog-configuration …))
                   …))

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

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

> From e8e489db62337c6e8ef03e745a56938566e078c8 Mon Sep 17 00:00:00 2001
> From: Jan Nieuwenhuizen <janneke@gnu.org>
> 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}.

As discussed above, I think this is the wrong place for this.

> From 59213cce5d6d4e41f9b6f321e3fef056cccc7c22 Mon Sep 17 00:00:00 2001
> From: Jan Nieuwenhuizen <janneke@gnu.org>
> 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.

[...]

> +  (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 …
    …")))

  (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?

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

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

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.

TIA!

Ludo’.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH] gnu: rottlog: rotate messages daily.
  2016-09-20  5:15               ` Ludovic Courtès
@ 2016-09-20 20:47                 ` Jan Nieuwenhuizen
  2016-09-21 15:32                   ` Ludovic Courtès
  0 siblings, 1 reply; 13+ messages in thread
From: Jan Nieuwenhuizen @ 2016-09-20 20:47 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: guix-devel

[-- 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  

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PATCH] gnu: rottlog: rotate messages daily.
  2016-09-20 20:47                 ` Jan Nieuwenhuizen
@ 2016-09-21 15:32                   ` Ludovic Courtès
  2016-09-22 20:51                     ` Jan Nieuwenhuizen
  0 siblings, 1 reply; 13+ messages in thread
From: Ludovic Courtès @ 2016-09-21 15:32 UTC (permalink / raw)
  To: Jan Nieuwenhuizen; +Cc: guix-devel

Hello!

Jan Nieuwenhuizen <janneke@gnu.org> skribis:

> Ludovic Courtès writes:

[...]

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

The ‘rottlog-configuration’ is actually a macro.  So at every call site
where a default value is used, the default value code is duplicated,
leading to code bloat if that default value is a big expression.

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

Probably worth exporting and documenting, so people can ‘cons’ on it.

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

[...]

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

Good point…

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

I think we cannot use ‘plain-file’ here because of the computed ‘kill’
file name.  So instead, this would be something along the lines of
(moving ‘string-append’ from the host side to the build side):

  (define (syslog-rotation-config file)
    #~(string-append #$file " {\n" …
                     #$coreutils "/bin/kill -HUP …"
                     "}\n"))

and:

  (define %default-rotations
    `(("weekly" ,(computed-file "rottlog.weekly"
                                #~(call-with-output-file #$output
                                    (lambda (port)
                                      (display #$(syslog-rotation-file …)
                                               port)))))))
HTH!

Thanks again for taking the time and coping with half-baked advice!
;-)

Ludo’.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH] gnu: rottlog: rotate messages daily.
  2016-09-21 15:32                   ` Ludovic Courtès
@ 2016-09-22 20:51                     ` Jan Nieuwenhuizen
  2016-10-02 22:39                       ` Ludovic Courtès
  0 siblings, 1 reply; 13+ messages in thread
From: Jan Nieuwenhuizen @ 2016-09-22 20:51 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: guix-devel

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

Ludovic Courtès writes:

Hi!

> The ‘rottlog-configuration’ is actually a macro.  So at every call site
> where a default value is used, the default value code is duplicated,
> leading to code bloat if that default value is a big expression.

Ah, ok.

>> I'm not sure if we should export the %default-rotations or if we should
>> describe their contents in the manual.
>
> Probably worth exporting and documenting, so people can ‘cons’ on it.

Ok.

>> +(define (syslog-rotation-config file)
>> + (let ((coreutils
>> "/gnu/store/56x9fvx59i300wav3c193h84cp80bslr-coreutils-8.25")) ;;
>> FIXME
>
> Good point…

Hmm... :-)

> I think we cannot use ‘plain-file’ here because of the computed ‘kill’
> file name.  So instead, this would be something along the lines of
> (moving ‘string-append’ from the host side to the build side):
>
>   (define (syslog-rotation-config file)
>     #~(string-append #$file " {\n" …
>                      #$coreutils "/bin/kill -HUP …"
>                      "}\n"))
>
> and:
>
>   (define %default-rotations
>     `(("weekly" ,(computed-file "rottlog.weekly"
>                                 #~(call-with-output-file #$output
>                                     (lambda (port)
>                                       (display #$(syslog-rotation-file …)
>                                                port)))))))
> HTH!

Yes, that helps a lot.  Attached a working version...I still feel like
fighting a bit with #~ and '#$...IWBN to get rid of `(apply append '#$(map',
usually append-map works for that, but the gexp boundary seems a bit too
tricksy for me here.

> Thanks again for taking the time and coping with half-baked advice!

Rotating my logs for quite some time already here, and learning quite
a bit about guix and scheme in the process too ;-)

Thanks!
Greetings,
Jan


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

From f4b03963d6ba6a232fca4ed749695423547d0ad5 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          |  65 +++++++++++++++++++++++++-
 gnu/local.mk           |   1 +
 gnu/services/admin.scm | 122 +++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 187 insertions(+), 1 deletion(-)
 create mode 100644 gnu/services/admin.scm

diff --git a/doc/guix.texi b/doc/guix.texi
index d5ece55..3db3d28 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,66 @@ 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
+
+@defvr {Scheme Variable} %default-rotatations
+Specifies weekly rotation of @var{%rotated-files} and
+@code{"/var/log/shepherd.log"}.
+@end defvr
+
+@defvr {Scheme Variable} %rotated-files
+The list of syslog-controlled files to be rotated (default:
+'("/var/log/messages" "/var/log/secure"))
+@end defvr
+
 @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..36ee997
--- /dev/null
+++ b/gnu/services/admin.scm
@@ -0,0 +1,122 @@
+;;; 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)
+  #:use-module (srfi srfi-1)
+  #:export (%default-rotations
+            %rotated-files
+            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 (syslog-rotation-config file)
+  #~(#$file " {
+	sharedscripts
+	postrotate
+	" #$coreutils "/bin/kill -HUP $(cat /var/run/syslog.pid) 2> /dev/null
+	endscript
+	nocompress
+}
+"))
+
+(define (simple-rotation-config file)
+  (string-append file " {
+	sharedscripts
+	postrotate
+	endscript
+	nocompress
+}
+"))
+
+(define %default-rotations
+  `(("weekly"
+     ,(computed-file "rottlog.weekly"
+                     #~(call-with-output-file #$output
+                         (lambda (port)
+                           (display
+                            (string-join
+                             (apply append '#$(map syslog-rotation-config
+                                                   %rotated-files))
+                             "")
+                            port)
+                           (display #$(simple-rotation-config
+                                       "/var/log/shepherd.log")
+                                    port)))))))
+
+(define (default-jobs rottlog)
+  (list #~(job
+           '(next-hour '(0))
+           (lambda ()
+             (system* (strinng-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.9.3


[-- 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  

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PATCH] gnu: rottlog: rotate messages daily.
  2016-09-22 20:51                     ` Jan Nieuwenhuizen
@ 2016-10-02 22:39                       ` Ludovic Courtès
  0 siblings, 0 replies; 13+ messages in thread
From: Ludovic Courtès @ 2016-10-02 22:39 UTC (permalink / raw)
  To: Jan Nieuwenhuizen; +Cc: guix-devel

Jan Nieuwenhuizen <janneke@gnu.org> skribis:

> From f4b03963d6ba6a232fca4ed749695423547d0ad5 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.

I’ve pushed it as 92c03a871559590f7f3b0640e3a6cfd83c8044e6 with minor
changes: typos in the doc and code, an additional introduction sentence
in the doc, removal of the “nocompress” option in the default rotations.

Thanks!

Ludo’.

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2016-10-02 22:40 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2016-09-21 15:32                   ` Ludovic Courtès
2016-09-22 20:51                     ` Jan Nieuwenhuizen
2016-10-02 22:39                       ` Ludovic Courtès

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.