gnu: Add debian-archive-keyring.
[jackhill/guix/guix.git] / gnu / services / monitoring.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2018 Sou Bunnbu <iyzsong@member.fsf.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 the GNU General Public License
17 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
18
19 (define-module (gnu services monitoring)
20 #:use-module (gnu services)
21 #:use-module (gnu services shepherd)
22 #:use-module (gnu packages admin)
23 #:use-module (gnu packages monitoring)
24 #:use-module (gnu system shadow)
25 #:use-module (guix gexp)
26 #:use-module (guix records)
27 #:use-module (ice-9 match)
28 #:export (darkstat-configuration
29 darkstat-service-type))
30
31 \f
32 ;;;
33 ;;; darkstat
34 ;;;
35
36 (define-record-type* <darkstat-configuration>
37 darkstat-configuration make-darkstat-configuration darkstat-configuration?
38 (package darkstat-configuration-package
39 (default darkstat))
40 (interface darkstat-configuration-interface)
41 (port darkstat-configuration-port
42 (default "667"))
43 (bind-address darkstat-configuration-bind-address
44 (default "127.0.0.1"))
45 (base darkstat-configuration-base
46 (default "/")))
47
48 (define %darkstat-accounts
49 (list (user-account
50 (name "darkstat")
51 (group "darkstat")
52 (system? #t)
53 (comment "darkstat daemon user")
54 (home-directory "/var/lib/darkstat")
55 (shell (file-append shadow "/sbin/nologin")))
56 (user-group
57 (name "darkstat")
58 (system? #t))))
59
60 (define darkstat-shepherd-service
61 (match-lambda
62 (($ <darkstat-configuration>
63 package interface port bind-address base)
64 (shepherd-service
65 (documentation "Network statistics gatherer.")
66 (provision '(darkstat))
67 (requirement '(networking))
68 (start #~(make-forkexec-constructor
69 (list #$(file-append package "/sbin/darkstat")
70 "-i" #$interface
71 "-p" #$port
72 "-b" #$bind-address
73 "--base" #$base
74 "--syslog" "--no-daemon"
75 "--chroot" "/var/lib/darkstat"
76 "--user" "darkstat"
77 "--import" "darkstat.db"
78 "--export" "darkstat.db")))
79 (stop #~(make-kill-destructor))))))
80
81 (define darkstat-service-type
82 (service-type
83 (name 'darkstat)
84 (description
85 "Run @command{darkstat} to serve network traffic statictics reports over
86 HTTP.")
87 (extensions
88 (list (service-extension account-service-type
89 (const %darkstat-accounts))
90 (service-extension shepherd-root-service-type
91 (compose list darkstat-shepherd-service))))))