From patchwork Thu Oct 19 01:28:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Sharlatan Hellseher X-Patchwork-Id: 54989 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 13F0F27BBE2; Wed, 18 Oct 2023 23:32:34 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI, SPF_HELO_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 69EF327BBE9 for ; Wed, 18 Oct 2023 23:32:32 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qtF3l-0003l6-Gj; Wed, 18 Oct 2023 18:30:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qtF3k-0003kH-3Z for guix-patches@gnu.org; Wed, 18 Oct 2023 18:30:36 -0400 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qtF3j-00033P-QC for guix-patches@gnu.org; Wed, 18 Oct 2023 18:30:35 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qtF49-00027r-U5 for guix-patches@gnu.org; Wed, 18 Oct 2023 18:31:01 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#66619] [PATCH 1/1] etc: Add guix-health.sh Resent-From: Sharlatan Hellseher Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Wed, 18 Oct 2023 22:31:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 66619 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 66619@debbugs.gnu.org Cc: Sharlatan Hellseher Received: via spool by 66619-submit@debbugs.gnu.org id=B66619.16976682214274 (code B ref 66619); Wed, 18 Oct 2023 22:31:01 +0000 Received: (at 66619) by debbugs.gnu.org; 18 Oct 2023 22:30:21 +0000 Received: from localhost ([127.0.0.1]:34905 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qtF3U-00015c-GT for submit@debbugs.gnu.org; Wed, 18 Oct 2023 18:30:20 -0400 Received: from mail-wm1-x32a.google.com ([2a00:1450:4864:20::32a]:54732) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qtF3R-0000ft-Vm for 66619@debbugs.gnu.org; Wed, 18 Oct 2023 18:30:18 -0400 Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-40651a726acso64130265e9.1 for <66619@debbugs.gnu.org>; Wed, 18 Oct 2023 15:29:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697668186; x=1698272986; darn=debbugs.gnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Y6GJ2zshgR7Om795YPT8gklAVP2AhhlHGcHYJf7+vgE=; b=crN+NV9ZzaEprXGFgQuBdl/Vna0UYjFggRbmx8WgKXBOUu7mDrhSQYDgAHLkJm+yYh v15eEt9SP4Jm3tSVlj09QVH/wnL9qZWF5RdVSBkX7wIONDTJgrTPRzf891iMwDJTXNL+ Hl0c/g4A62xWaJojCUCEmkp9Ko1b9GFAW2V3sn64ZoSSvBKurjlfkmeOoIIibY/1/nph Te20ebVQFjJnHnIhUmOuJE3bakpONohK7QOmkEKg6mn+Hv74T45boL1xMF4MvUVqq1sl hKzyfSqsXiZCPng6plhd8q3z0r905YoFF0lzmmtRc8r52u0+ViPZ8dDCV3XEU2Mirq2F rrYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697668186; x=1698272986; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Y6GJ2zshgR7Om795YPT8gklAVP2AhhlHGcHYJf7+vgE=; b=i9LJ6X9putLiz+OSAtJfF+SgiVmWjYv1RxEDbJerAX4iGGlAU/UU6neBP/0g40+cl6 HBiESVYmWZEqUqzdzlTFWIeBzjK4lQsg7mOsW72JXkIGqwRnllcSc5eAmQ8DJVqf1UfL RKoBI/7kA61rmELbBwS8P0pXK1zLun4+8Xs+EHtKAqiv3Gx6ZVh8QhoDXxg7uhBCfXQm mDfBRpIkEUcj5TkXbCeuWylcDHIKDvIwecQYFiWLi3SbnVn7NDcKMyyAyfjWabAnluOG cIQ+R9iOrbu1v2ChH0qKhtKB6kO4b6vndL4MwbINBKoK9vp5kf+gKRtyakWox7eT9zkY U8cA== X-Gm-Message-State: AOJu0YxjBXRMA6WCIAEVfTcTw1ttX2GqeYsZU8uspGT/ymybkrHImLqA vPcApIRgx7ciORlOvKADprkMVH3DF0aifQ== X-Google-Smtp-Source: AGHT+IGGXdzTyVMZNaj1TYK5CCCVb1SJi/PP9LFIdTJnVUynZbeilyT5c1X+5xzweL5IAFXV1gpB4Q== X-Received: by 2002:a5d:54c1:0:b0:32d:8c7d:a135 with SMTP id x1-20020a5d54c1000000b0032d8c7da135mr246432wrv.6.1697668185523; Wed, 18 Oct 2023 15:29:45 -0700 (PDT) Received: from localhost.localdomain (cpc100856-bagu15-2-0-cust368.1-3.cable.virginm.net. [82.25.93.113]) by smtp.gmail.com with ESMTPSA id x6-20020a5d6506000000b0032d886039easm3032951wru.14.2023.10.18.15.29.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 15:29:44 -0700 (PDT) From: Sharlatan Hellseher Date: Thu, 19 Oct 2023 02:28:53 +0100 Message-ID: X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches * etc/guix-health.sh: New file. --- etc/guix-health.sh | 145 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 145 insertions(+) create mode 100755 etc/guix-health.sh diff --git a/etc/guix-health.sh b/etc/guix-health.sh new file mode 100755 index 0000000000..9078d52ce6 --- /dev/null +++ b/etc/guix-health.sh @@ -0,0 +1,145 @@ +#!/bin/sh +# GNU Guix --- Functional package management for GNU +# Copyright © 2023 sharlatan + +# 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 . + +# We require Bash but for portability we'd rather not use /bin/bash or +# /usr/bin/env in the shebang, hence this hack. + +## Commentary: +# +# General purpose check script which may be used as report during diagnostics of +# issues with running system in general and Guix in particularly. + +## Code: + +if [ "x$BASH_VERSION" = "x" ] +then + exec bash "$0" "$@" +fi + +set -eo pipefail + +[ "$UID" -eq 0 ] || { echo "This script must be run as root."; exit 1; } + +REQUIRE=( + "herd" + "stat" + "grep" + "cat" +) + +PAS=$'[ \033[32;1mPASS\033[0m ] ' +ERR=$'[ \033[31;1mFAIL\033[0m ] ' +WAR=$'[ \033[33;1mWARN\033[0m ] ' +INF="[ INFO ] " + +DEBUG=0 + +# Map of all vital predictable files required to diagnose health condition of +# the guix-daemon. +declare -A GUIX_FILE +GUIX_FILE=( + [socket]="/var/guix/daemon-socket/socket" + [configuration]="/run/current-system/configuration.scm" +) + +# ------------------------------------------------------------------------------ +#+UTILITIES + +_err() +{ # All errors go to stderr. + printf "[%s]: %s\n" "$(date +%s.%3N)" "$1" +} + +_msg() +{ # Default message to stdout. + printf "[%s]: %s\n" "$(date +%s.%3N)" "$1" +} + +_debug() +{ + if [ "${DEBUG}" = '1' ]; then + printf "[%s]: %s\n" "$(date +%s.%3N)" "$1" + fi +} + +die() +{ + _err "${ERR}$*" + exit 1 +} + +chck_require() +{ # Check that every required command is available. + declare -a warn + local c + + _debug "--- [ ${FUNCNAME[0]} ] ---" + + for c in "$@"; do + command -v "$c" &>/dev/null || warn+=("$c") + done + + [ "${#warn}" -ne 0 ] && die "Missing commands: ${warn[*]}." + + _msg "${PAS}verification of required commands completed" +} + +# ------------------------------------------------------------------------------ +#+CHECKS :: Collection of grouped check to validate Guix system health. + +chck_daemon() +{ # Basic assumptions and check list to show what's going on with guix-daemon, + # some of the checks can't be performed if daemon is not running (e.g guix + # system shepherd-graph) + + local guix_daemon_status + + _debug "--- [ ${FUNCNAME[0]} ] ---" + + guix_daemon_status="$(herd status | grep guix-daemon | cut -d' ' -f2)" + + if [ "$(stat --format=%F ${GUIX_FILE[socket]})" == 'socket' ] + then + _msg "${PAS}Guix socket file is present in ${GUIX_FILE[socket]}" + fi + + if [ "$guix_daemon_status" == "+" ] + then + _msg "${PAS}guix-daemon is running" + elif [ "$guix_daemon_status" == "-" ] + then + _msg "${WAR}guix-daemon is stopped" + fi + + if grep guix-daemon "${GUIX_FILE[configuration]}" &>/dev/null + then + _msg "${PAS}guix-daemon is listed in current system config" + else + _msg "${WAR}guix-daemon is not listed in current system config" + fi +} + +main() +{ + chck_require + chck_daemon + # XXX: Add more, event more! +} + +main "$@"