tests: Add 'openssh-service-type' test.
[jackhill/guix/guix.git] / gnu / services / admin.scm
CommitLineData
92c03a87
JN
1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2016 Jan Nieuwenhuizen <janneke@gnu.org>
3;;;
4;;; This file is part of GNU Guix.
5;;;
6;;; GNU Guix is free software; you can redistribute it and/or modify it
7;;; under the terms of the GNU General Public License as published by
8;;; the Free Software Foundation; either version 3 of the License, or (at
9;;; your option) any later version.
10;;;
11;;; GNU Guix is distributed in the hope that it will be useful, but
12;;; WITHOUT ANY WARRANTY; without even the implied warranty of
13;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14;;; GNU General Public License for more details.
15;;;
16;;; You should have received a copy of thye GNU General Public License
17;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
18
19(define-module (gnu services admin)
20 #:use-module (gnu packages admin)
21 #:use-module (gnu packages base)
22 #:use-module (gnu services)
23 #:use-module (gnu services mcron)
24 #:use-module (gnu services shepherd)
25 #:use-module (guix gexp)
26 #:use-module (guix packages)
27 #:use-module (guix records)
28 #:use-module (srfi srfi-1)
29 #:export (%default-rotations
30 %rotated-files
31 rottlog-configuration
32 rottlog-configuration?
33 rottlog-service
34 rottlog-service-type))
35
36;;; Commentary:
37;;;
38;;; This module implements configuration of rottlog by writing
39;;; /etc/rottlog/{rc,hourly|daily|weekly}. Example usage
40;;;
41;;; (mcron-service)
42;;; (service rottlog-service-type (rottlog-configuration))
43;;;
44;;; Code:
45
46(define %rotated-files
47 '("/var/log/messages" "/var/log/secure"))
48
49(define (syslog-rotation-config file)
50 #~(#$file " {
51 sharedscripts
52 postrotate
53 " #$coreutils "/bin/kill -HUP $(cat /var/run/syslog.pid) 2> /dev/null
54 endscript
55}
56"))
57
58(define (simple-rotation-config file)
59 (string-append file " {
60 sharedscripts
61 postrotate
62 endscript
63}
64"))
65
66(define %default-rotations
67 `(("weekly"
68 ,(computed-file "rottlog.weekly"
69 #~(call-with-output-file #$output
70 (lambda (port)
71 (display
72 (string-join
73 (apply append '#$(map syslog-rotation-config
74 %rotated-files))
75 "")
76 port)
77 (display #$(simple-rotation-config
78 "/var/log/shepherd.log")
79 port)))))))
80
81(define (default-jobs rottlog)
82 (list #~(job '(next-hour '(0)) ;midnight
83 (lambda ()
84 (system* #$(file-append rottlog "/sbin/rottlog"))))
85 #~(job '(next-hour '(12)) ;noon
86 (lambda ()
87 (system* #$(file-append rottlog "/sbin/rottlog"))))))
88
89(define-record-type* <rottlog-configuration>
90 rottlog-configuration make-rottlog-configuration
91 rottlog-configuration?
92 (rottlog rottlog-rottlog ;package
93 (default rottlog))
94 (rc-file rottlog-rc-file ;file-like
95 (default (file-append rottlog "/etc/rc")))
96 (periodic-rotations rottlog-periodic-rotations ;list of (name file) tuples
97 (default %default-rotations))
98 (jobs rottlog-jobs ;list of <mcron-job>
99 (default #f)))
100
101(define (rottlog-etc config)
102 `(("rottlog" ,(file-union "rottlog"
103 (cons `("rc" ,(rottlog-rc-file config))
104 (rottlog-periodic-rotations config))))))
105
106(define (rottlog-jobs-or-default config)
107 (or (rottlog-jobs config)
108 (default-jobs (rottlog-rottlog config))))
109
110(define rottlog-service-type
111 (service-type
112 (name 'rottlog)
113 (extensions (list (service-extension etc-service-type rottlog-etc)
114 (service-extension mcron-service-type
115 rottlog-jobs-or-default)))))
116
117;;; admin.scm ends here