summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile.am1
-rw-r--r--doc/guix.texi69
-rw-r--r--gnu/services/linux.scm125
-rw-r--r--tests/services/linux.scm57
4 files changed, 251 insertions, 1 deletions
diff --git a/Makefile.am b/Makefile.am
index 7474b7f3757..c6a2e6cf6c9 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -426,6 +426,7 @@ SCM_TESTS = \
426 tests/scripts-build.scm \ 426 tests/scripts-build.scm \
427 tests/search-paths.scm \ 427 tests/search-paths.scm \
428 tests/services.scm \ 428 tests/services.scm \
429 tests/services/linux.scm \
429 tests/sets.scm \ 430 tests/sets.scm \
430 tests/size.scm \ 431 tests/size.scm \
431 tests/snix.scm \ 432 tests/snix.scm \
diff --git a/doc/guix.texi b/doc/guix.texi
index 3141c4582f8..956c25ba9e4 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -48,7 +48,7 @@ Copyright @copyright{} 2017 humanitiesNerd@*
48Copyright @copyright{} 2017 Christopher Allan Webber@* 48Copyright @copyright{} 2017 Christopher Allan Webber@*
49Copyright @copyright{} 2017, 2018, 2019 Marius Bakke@* 49Copyright @copyright{} 2017, 2018, 2019 Marius Bakke@*
50Copyright @copyright{} 2017, 2019 Hartmut Goebel@* 50Copyright @copyright{} 2017, 2019 Hartmut Goebel@*
51Copyright @copyright{} 2017, 2019 Maxim Cournoyer@* 51Copyright @copyright{} 2017, 2019, 2020 Maxim Cournoyer@*
52Copyright @copyright{} 2017, 2018, 2019, 2020 Tobias Geerinckx-Rice@* 52Copyright @copyright{} 2017, 2018, 2019, 2020 Tobias Geerinckx-Rice@*
53Copyright @copyright{} 2017 George Clemmer@* 53Copyright @copyright{} 2017 George Clemmer@*
54Copyright @copyright{} 2017 Andy Wingo@* 54Copyright @copyright{} 2017 Andy Wingo@*
@@ -310,6 +310,7 @@ Services
310* Version Control Services:: Providing remote access to Git repositories. 310* Version Control Services:: Providing remote access to Git repositories.
311* Game Services:: Game servers. 311* Game Services:: Game servers.
312* PAM Mount Service:: Service to mount volumes when logging in. 312* PAM Mount Service:: Service to mount volumes when logging in.
313* Linux Services:: Services tied to the Linux kernel.
313* Miscellaneous Services:: Other services. 314* Miscellaneous Services:: Other services.
314 315
315Defining Services 316Defining Services
@@ -12084,6 +12085,7 @@ declaration.
12084* Game Services:: Game servers. 12085* Game Services:: Game servers.
12085* PAM Mount Service:: Service to mount volumes when logging in. 12086* PAM Mount Service:: Service to mount volumes when logging in.
12086* Guix Services:: Services relating specifically to Guix. 12087* Guix Services:: Services relating specifically to Guix.
12088* Linux Services:: Services tied to the Linux kernel.
12087* Miscellaneous Services:: Other services. 12089* Miscellaneous Services:: Other services.
12088@end menu 12090@end menu
12089 12091
@@ -25129,6 +25131,71 @@ list.
25129@end table 25131@end table
25130@end deftp 25132@end deftp
25131 25133
25134@node Linux Services
25135@subsubheading Linux Services
25136
25137@cindex oom
25138@cindex out of memory killer
25139@cindex earlyoom
25140@cindex early out of memory daemon
25141@subsection Early OOM Service
25142
25143@uref{https://github.com/rfjakob/earlyoom,Early OOM}, also known as
25144Earlyoom, is a minimalist out of memory (OOM) daemon that runs in user
25145space and provides a more responsive and configurable alternative to the
25146in-kernel OOM killer. It is useful to prevent the system from becoming
25147unresponsive when it runs out of memory.
25148
25149@deffn {Scheme Variable} earlyoom-service-type
25150The service type for running @command{earlyoom}, the Early OOM daemon.
25151Its value must be a @code{earlyoom-configuration} object, described
25152below. The service can be instantiated in its default configuration
25153with:
25154
25155@lisp
25156(service earlyoom-service-type)
25157@end lisp
25158@end deffn
25159
25160@deftp {Data Type} earlyoom-configuration
25161This is the configuration record for the @code{earlyoom-service-type}.
25162
25163@table @asis
25164@item @code{earlyoom} (default: @var{earlyoom})
25165The Earlyoom package to use.
25166
25167@item @code{minimum-available-memory} (default: @code{10})
25168The threshold for the minimum @emph{available} memory, in percentages.
25169
25170@item @code{minimum-free-swap} (default: @code{10})
25171The threshold for the minimum free swap memory, in percentages.
25172
25173@item @code{prefer-regexp} (default: @code{#f})
25174A regular expression (as a string) to match the names of the processes
25175that should be preferably killed.
25176
25177@item @code{avoid-regexp} (default: @code{#f})
25178A regular expression (as a string) to match the names of the processes
25179that should @emph{not} be killed.
25180
25181@item @code{memory-report-interval} (default: @code{0})
25182The interval in seconds at which a memory report is printed. It is
25183disabled by default.
25184
25185@item @code{ignore-positive-oom-score-adj?} (default: @code{#f})
25186A boolean indicating whether the positive adjustments set in
25187@file{/proc/*/oom_score_adj}.
25188
25189@item @code{show-debug-messages?} (default: @code{#f})
25190A boolean indicating whether debug messages should be printed. The logs
25191are saved at @file{/var/log/earlyoom.log}.
25192
25193@item @code{send-notification-command} (default: @code{#f})
25194This can be used to provide a custom command used for sending
25195notifications.
25196@end table
25197@end deftp
25198
25132 25199
25133@node Miscellaneous Services 25200@node Miscellaneous Services
25134@subsection Miscellaneous Services 25201@subsection Miscellaneous Services
diff --git a/gnu/services/linux.scm b/gnu/services/linux.scm
new file mode 100644
index 00000000000..caa0326c313
--- /dev/null
+++ b/gnu/services/linux.scm
@@ -0,0 +1,125 @@
1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2020 Maxim Cournoyer <maxim.cournoyer@gmail.com>
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 linux)
20 #:use-module (guix gexp)
21 #:use-module (guix records)
22 #:use-module (guix modules)
23 #:use-module (gnu services)
24 #:use-module (gnu services shepherd)
25 #:use-module (gnu packages linux)
26 #:use-module (srfi srfi-1)
27 #:use-module (srfi srfi-26)
28 #:use-module (ice-9 match)
29 #:export (earlyoom-configuration
30 earlyoom-configuration?
31 earlyoom-configuration-earlyoom
32 earlyoom-configuration-minimum-available-memory
33 earlyoom-configuration-minimum-free-swap
34 earlyoom-configuration-prefer-regexp
35 earlyoom-configuration-avoid-regexp
36 earlyoom-configuration-memory-report-interval
37 earlyoom-configuration-ignore-positive-oom-score-adj?
38 earlyoom-configuration-show-debug-messages?
39 earlyoom-configuration-send-notification-command
40 earlyoom-service-type))
41
42
43;;;
44;;; Early OOM daemon.
45;;;
46
47(define-record-type* <earlyoom-configuration>
48 earlyoom-configuration make-earlyoom-configuration
49 earlyoom-configuration?
50 (earlyoom earlyoom-configuration-earlyoom
51 (default earlyoom))
52 (minimum-available-memory earlyoom-configuration-minimum-available-memory
53 (default 10)) ; in percent
54 (minimum-free-swap earlyoom-configuration-minimum-free-swap
55 (default 10)) ; in percent
56 (prefer-regexp earlyoom-configuration-prefer-regexp ; <string>
57 (default #f))
58 (avoid-regexp earlyoom-configuration-avoid-regexp ; <string>
59 (default #f))
60 (memory-report-interval earlyoom-configuration-memory-report-interval
61 (default 0)) ; in seconds; 0 means disabled
62 (ignore-positive-oom-score-adj?
63 earlyoom-configuration-ignore-positive-oom-score-adj? (default #f))
64 (run-with-higher-priority? earlyoom-configuration-run-with-higher-priority?
65 (default #f))
66 (show-debug-messages? earlyoom-configuration-show-debug-messages?
67 (default #f))
68 (send-notification-command
69 earlyoom-configuration-send-notification-command ; <string>
70 (default #f)))
71
72(define (earlyoom-configuration->command-line-args config)
73 "Translate a <earlyoom-configuration> object to its command line arguments
74representation."
75 (match config
76 (($ <earlyoom-configuration> earlyoom minimum-available-memory
77 minimum-free-swap prefer-regexp avoid-regexp
78 memory-report-interval
79 ignore-positive-oom-score-adj?
80 run-with-higher-priority? show-debug-messages?
81 send-notification-command)
82 `(,(file-append earlyoom "/bin/earlyoom")
83 ,@(if minimum-available-memory
84 (list "-m" (format #f "~s" minimum-available-memory))
85 '())
86 ,@(if minimum-free-swap
87 (list "-s" (format #f "~s" minimum-free-swap))
88 '())
89 ,@(if prefer-regexp
90 (list "--prefer" prefer-regexp)
91 '())
92 ,@(if avoid-regexp
93 (list "--avoid" avoid-regexp)
94 '())
95 "-r" ,(format #f "~s" memory-report-interval)
96 ,@(if ignore-positive-oom-score-adj?
97 (list "-i")
98 '())
99 ,@(if run-with-higher-priority?
100 (list "-p")
101 '())
102 ,@(if show-debug-messages?
103 (list "-d")
104 '())
105 ,@(if send-notification-command
106 (list "-N" send-notification-command)
107 '())))))
108
109(define (earlyoom-shepherd-service config)
110 (shepherd-service
111 (documentation "Run the Early OOM daemon.")
112 (provision '(earlyoom))
113 (start #~(make-forkexec-constructor
114 '#$(earlyoom-configuration->command-line-args config)
115 #:log-file "/var/log/earlyoom.log"))
116 (stop #~(make-kill-destructor))))
117
118(define earlyoom-service-type
119 (service-type
120 (name 'earlyoom)
121 (default-value (earlyoom-configuration))
122 (extensions
123 (list (service-extension shepherd-root-service-type
124 (compose list earlyoom-shepherd-service))))
125 (description "Run @command{earlyoom}, the Early OOM daemon.")))
diff --git a/tests/services/linux.scm b/tests/services/linux.scm
new file mode 100644
index 00000000000..8ad119c49f7
--- /dev/null
+++ b/tests/services/linux.scm
@@ -0,0 +1,57 @@
1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2020 Maxim Cournoyer <maxim.cournoyer@gmail.com>
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 (tests services linux)
20 #:use-module (ice-9 match)
21 #:use-module (gnu packages linux)
22 #:use-module (gnu services linux)
23 #:use-module (guix gexp)
24 #:use-module (srfi srfi-64))
25
26;;; Tests for the (gnu services linux) module.
27
28(test-begin "linux-services")
29
30
31;;;
32;;; Early OOM daemon.
33;;;
34
35(define earlyoom-configuration->command-line-args
36 (@@ (gnu services linux) earlyoom-configuration->command-line-args))
37
38(define %earlyoom-configuration-sample
39 (earlyoom-configuration
40 (minimum-available-memory 10)
41 (minimum-free-swap 20)
42 (prefer-regexp "icecat")
43 (avoid-regexp "guix-daemon")
44 (memory-report-interval 60)
45 (ignore-positive-oom-score-adj? #f)
46 (run-with-higher-priority? #t)
47 (show-debug-messages? #f)
48 (send-notification-command "python \"/some/path/notify-all-users.py\"")))
49
50(test-equal "earlyoom-configuration->command-line-args"
51 (list (file-append earlyoom "/bin/earlyoom")
52 "-m" "10" "-s" "20" "--prefer" "icecat"
53 "--avoid" "guix-daemon" "-r" "60" "-p"
54 "-N" "python \"/some/path/notify-all-users.py\"")
55 (earlyoom-configuration->command-line-args %earlyoom-configuration-sample))
56
57(test-end "linux-services")