Subject: bug#47905: closed (Re: [bug#47905] gnu: Add rasdaemon.)

From: [email-masked] (GNU bug Tracking System)
Date: Sat, 24 Apr 2021 16:35:02 +0000

Your bug report

#47905: gnu: Add rasdaemon.

which was filed against the guix-patches package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
47905: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=47905
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: [bug#47905] gnu: Add rasdaemon.
From: Leo Famulari <[email-masked]>
To: [email-masked]
Cc: [email-masked]
Date: Sat, 24 Apr 2021 12:33:56 -0400
List-Id: <debbugs-submit.debbugs.gnu.org>

On Thu, Apr 22, 2021 at 07:01:20PM +0900, [email-masked] wrote:
> Fixed!  Thanks for holding my hand on this.  That above link cleared up a lot
> of lingering questions I had.

You're welcome! My goal is help contributors keep learning until they
are sending patches that pass code review on the first try, and they
feel confident to start reviewing patches, too. Based on this submission,
I think you are more than knowledgeable enough to review some patches :)

> Let me know what you think.

> From d31cb88e5c34cc0b650ff181ebb6a0d85d045f9d Mon Sep 17 00:00:00 2001
> From: "B. Wilson" <[email-masked]>
> Date: Tue, 20 Apr 2021 11:49:26 +0900
> Subject: [PATCH] gnu: Add rasdaemon.
> To: [email-masked]
> 
> * gnu/packages/linux.scm (rasdaemon): New variable.
> * gnu/services/linux.scm (rasdaemon-configuration)
>   (rasdaemon-configuration?, rasdaemon-configuration-record?)
>   (rasdaemon-service-type): New variables.
> * doc/guix.texi (Linux Services): Document it.

It's good! I pushed as 2c93df3d11bf8ceeb5c203416a2533cf32275e1a after
splitting it into two commits: one for the package, and one for the
service and its documentation.

By the way, you might ask upstream about fixing the issues in their
build scripts — the ones you fixed in the 'munge-autotools' phase. I
think most distros will need to do similar fixes.

Subject: gnu: Add rasdaemon.
From: [email-masked]
To: [email-masked]
Date: Tue, 20 Apr 2021 13:24:37 +0900
List-Id: <debbugs-submit.debbugs.gnu.org>

This is my first patch to gnu/services (and by inclusion doc/guix.texi), so
please scrutinize with abandon!

I did all the standard sanity checks for the package definition (guix lint,
etc/indent-code.el, guix build --check); however, I wasn't sure about the
service, so the sanity checks were limited to testing in a vm.

Cheers!

From 1d4e60a9578d3572bf1caff11d0b17e4bc8f1ea9 Mon Sep 17 00:00:00 2001
From: "B. Wilson" <[email-masked]>
Date: Tue, 20 Apr 2021 11:49:26 +0900
Subject: [PATCH] gnu: Add rasdaemon.
To: [email-masked]

* gnu/packages/linux.scm (rasdaemon): New variable.
* gnu/services/linux.scm (rasdaemon-configuration)
  (rasdaemon-configuration?, rasdaemon-configuration-record?)
  (rasdaemon-service-type): New variables.
* doc/guix.texi (Linux Services): Document it.
---
 doc/guix.texi          | 29 +++++++++++++++++++++++++
 gnu/packages/linux.scm | 45 ++++++++++++++++++++++++++++++++++++++
 gnu/services/linux.scm | 49 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 123 insertions(+)

diff --git a/doc/guix.texi b/doc/guix.texi
index 58bcfbdbb5..73479b8fcf 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -88,6 +88,7 @@ Copyright @copyright{} 2020 John Soo@*
 Copyright @copyright{} 2020 Jonathan Brielmaier@*
 Copyright @copyright{} 2020 Edgar Vincent@*
 Copyright @copyright{} 2021 Maxime Devos@*
+Copyright @copyright{} 2021 B. Wilson@*
 
 Permission is granted to copy, distribute and/or modify this document
 under the terms of the GNU Free Documentation License, Version 1.3 or
@@ -31457,6 +31458,34 @@ parameters, can be done as follow:
 @end lisp
 @end deffn
 
+@cindex rasdaemon
+@cindex Platform Reliability, Availability and Serviceability daemon
+@subsubheading Rasdaemon Service
+
+The Rasdaemon service provides a monitor for Platform Reliability,
+Availability, and Serviceability (RAS) events in the Linux kernel.
+
+@defvr {Scheme Variable} rasdaemon-service-type
+Service type for the @command{rasdaemon} service.  It accepts a
+@code{rasdaemon-configuration} object.  Instantiating like
+
+@lisp
+(service rasdaemon-service-type)
+@end lisp
+
+will load with a default configuration.
+@end defvr
+
+@deftp {Data Type} rasdaemon-configuration
+The data type representing the configuration of @command{rasdaemon}.
+
+@table @asis
+@item @code{record?} (default: @code{#f})
+A boolean indicating whether to record the events in an SQLite database.  The
+database location is hard-coded to @file{/var/lib/rasdaemon/ras-mc_event.db}.
+@end table
+@end deftp
+
 @cindex zram
 @cindex compressed swap
 @cindex Compressed RAM-based block devices
diff --git a/gnu/packages/linux.scm b/gnu/packages/linux.scm
index 1ea9d80834..fe464bcc8e 100644
--- a/gnu/packages/linux.scm
+++ b/gnu/packages/linux.scm
@@ -53,6 +53,7 @@
 ;;; Copyright © 2020 Zhu Zihao <[email-masked]>
 ;;; Copyright © 2020 David Dashyan <[email-masked]>
 ;;; Copyright © 2020 pukkamustard <[email-masked]>
+;;; Copyright © 2021 B. Wilson <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -130,6 +131,7 @@
   #:use-module (gnu packages sdl)
   #:use-module (gnu packages serialization)
   #:use-module (gnu packages slang)
+  #:use-module (gnu packages sqlite)
   #:use-module (gnu packages texinfo)
   #:use-module (gnu packages tls)
   #:use-module (gnu packages valgrind)
@@ -8037,3 +8039,46 @@ kernel side implementation.")
 read-only file system optimized for resource-scarce devices.  This package
 provides user-space tools for creating EROFS file systems.")
     (license license:gpl2+)))
+
+(define-public rasdaemon
+  (package
+    (name "rasdaemon")
+    (version "0.6.6")
+    (source
+     (origin
+       (method git-fetch)
+       (uri (git-reference
+             (url "https://github.com/mchehab/rasdaemon")
+             (commit (string-append "v" version))))
+       (file-name (git-file-name name version))
+       (sha256
+        (base32 "13g39x19lfjf9izdcb0nlyfjrgpliivhv4nw3ndgyzi59l3yqc0v"))))
+    (native-inputs `(("autoconf" ,autoconf)
+                     ("automake" ,automake)
+                     ("libtool" ,libtool)))
+    (inputs `(("sqlite" ,sqlite)))
+    (arguments
+     `(#:configure-flags '("--enable-all"
+                           "--localstatedir=/var")
+       #:phases
+       (modify-phases %standard-phases
+         (add-before 'configure 'munge-autotools
+           (lambda _
+             ;; For some reason upstream forces sysconfdir=/etc.  This results
+             ;; in EPERM during the install phase.  Removing the offending
+             ;; line lets sysconfdir correctly pick up DESTDIR.
+             (substitute* "configure.ac"
+               (("^test .* sysconfdir=/etc\n$") ""))
+             ;; Upstream tries to create /var/lib/rasdaemon at install time.
+             ;; This results in EPERM on guix.  Instead, the service should
+             ;; create this at activation time.
+             (substitute* "Makefile.am"
+               (("^\\s*\\$\\(install_sh\\) -d .*@RASSTATEDIR@.*$") "")))))))
+    (build-system gnu-build-system)
+    (home-page "https://github.com/mchehab/rasdaemon")
+    (synopsis "Platform Reliability, Availability and Serviceability tools")
+    (description "The @code{rasdaemon} program is a daemon which monitors the
+platform Reliablity, Availability and Serviceability (RAS) reports from the
+Linux kernel trace events.  These trace events are logged in
+/sys/kernel/debug/tracing, reporting them via syslog/journald.")
+    (license license:gpl2+)))
diff --git a/gnu/services/linux.scm b/gnu/services/linux.scm
index 340b330030..01723efc07 100644
--- a/gnu/services/linux.scm
+++ b/gnu/services/linux.scm
@@ -3,6 +3,7 @@
 ;;; Copyright © 2020 Brice Waegeneire <[email-masked]>
 ;;; Copyright © 2020 Efraim Flashner <[email-masked]>
 ;;; Copyright © 2021 raid5atemyhomework <[email-masked]>
+;;; Copyright © 2021 B. Wilson <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -47,6 +48,11 @@
 
             kernel-module-loader-service-type
 
+            rasdaemon-configuration
+            rasdaemon-configuration?
+            rasdaemon-configuration-record?
+            rasdaemon-service-type
+
             zram-device-configuration
             zram-device-configuration?
             zram-device-configuration-size
@@ -188,6 +194,49 @@ representation."
    (extend append)
    (default-value '())))
 
+
+;;;
+;;; Reliability, Availability, and Servicability (RAS) daemon
+;;;
+
+(define-record-type* <rasdaemon-configuration>
+  rasdaemon-configuration make-rasdaemon-configuration
+  rasdaemon-configuration?
+  (record? rasdaemon-configuration-record? (default #f)))
+
+(define (rasdaemon-configuration->command-line-args config)
+  "Translate <rasdaemon-configuration> to its command line arguments
+  representation"
+  (let ((record? (rasdaemon-configuration-record? config)))
+    `(,(file-append rasdaemon "/sbin/rasdaemon")
+      "--foreground" ,@(if record? '("--record") '()))))
+
+(define (rasdaemon-activation config)
+  (let ((record? (rasdaemon-configuration-record? config))
+        (rasdaemon-dir "/var/lib/rasdaemon"))
+    (with-imported-modules '((guix build utils))
+      #~(if #$record? (mkdir-p #$rasdaemon-dir)))))
+
+(define (rasdaemon-shepherd-service config)
+  (shepherd-service
+   (documentation "Run rasdaemon")
+   (provision '(rasdaemon))
+   (start #~(make-forkexec-constructor
+             '#$(rasdaemon-configuration->command-line-args config)
+             #:log-file "/var/log/rasdaemon.log"))
+   (stop #~(make-kill-destructor))))
+
+(define rasdaemon-service-type
+  (service-type
+   (name 'rasdaemon)
+   (default-value (rasdaemon-configuration))
+   (extensions
+    (list (service-extension shepherd-root-service-type
+                             (compose list rasdaemon-shepherd-service))
+          (service-extension activation-service-type rasdaemon-activation)))
+   (compose concatenate)
+   (description "Run @command{rasdaemon}, the RAS monitor")))
+
 
 ;;;
 ;;; Kernel module loader.
-- 
2.31.1