all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
blob 9078d52ce6cbadb84a24fecc2890da3946f1d13d 3592 bytes (raw)
name: etc/guix-health.sh 	 # note: path name is non-authoritative(*)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
 
#!/bin/sh
# GNU Guix --- Functional package management for GNU
# Copyright © 2023 sharlatan <sharlatanus@gmail.com>

# 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 <http://www.gnu.org/licenses/>.

# 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 "$@"

debug log:

solving 9078d52ce6 ...
found 9078d52ce6 in https://yhetil.org/guix/cf698536c6393032274c6d8539f366acaa036e98.1697156963.git.sharlatanus@gmail.com/ ||
	https://yhetil.org/guix/CAO+9K5rJ93Gy2DrD0w6OftqyHmyUd8+hrHGU2ZZJiUT0MBZTEA@mail.gmail.com/

applying [1/1] https://yhetil.org/guix/cf698536c6393032274c6d8539f366acaa036e98.1697156963.git.sharlatanus@gmail.com/
diff --git a/etc/guix-health.sh b/etc/guix-health.sh
new file mode 100755
index 0000000000..9078d52ce6

Checking patch etc/guix-health.sh...
Applied patch etc/guix-health.sh cleanly.

skipping https://yhetil.org/guix/CAO+9K5rJ93Gy2DrD0w6OftqyHmyUd8+hrHGU2ZZJiUT0MBZTEA@mail.gmail.com/ for 9078d52ce6
index at:
100755 9078d52ce6cbadb84a24fecc2890da3946f1d13d	etc/guix-health.sh

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.