all: Move the multi-configuration file reading routine to a common helper
Based on Emil's (xexaxo) feedback, we now have a common.sh file that contains the implementation of the routine to read all config files for kdump/pstore, and we use Makefile to join the files, having the same implemention in all users. Signed-off-by: Guilherme G. Piccoli <gpiccoli@igalia.com>
This commit is contained in:
11
Makefile
11
Makefile
@ -10,7 +10,16 @@ sysctldir := $(shell pkg-config --define-variable=prefix=$(prefix) --variable=sy
|
|||||||
dracutmodulesdir := $(shell pkg-config --define-variable=prefix=$(prefix) --variable=dracutmodulesdir dracut 2>/dev/null \
|
dracutmodulesdir := $(shell pkg-config --define-variable=prefix=$(prefix) --variable=dracutmodulesdir dracut 2>/dev/null \
|
||||||
|| echo $(libdir)/dracut/modules.d/)
|
|| echo $(libdir)/dracut/modules.d/)
|
||||||
|
|
||||||
all:
|
kdump-load.sh: kdump-load.header common.sh kdump-load.sh.in
|
||||||
|
cat $^ > $@
|
||||||
|
|
||||||
|
module-setup.sh: module-setup.header common.sh module-setup.sh.in
|
||||||
|
cat $^ > $@
|
||||||
|
|
||||||
|
save-dumps.sh: save-dumps.header common.sh save-dumps.sh.in
|
||||||
|
cat $^ > $@
|
||||||
|
|
||||||
|
all: kdump-load.sh module-setup.sh save-dumps.sh
|
||||||
|
|
||||||
install: all
|
install: all
|
||||||
install -D -m0644 kdump-init.service $(DESTDIR)$(systemdunitsdir)/kdump-init.service
|
install -D -m0644 kdump-init.service $(DESTDIR)$(systemdunitsdir)/kdump-init.service
|
||||||
|
|||||||
21
common.sh
Normal file
21
common.sh
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
|
||||||
|
# This function has the purpose of loading the necessary external
|
||||||
|
# variables, in the form of one (or more) configuration file(s). If the
|
||||||
|
# procedure fails, we must abort - otherwise it'll fail in a later stage.
|
||||||
|
load_kdump_config() {
|
||||||
|
HAVE_CFG_FILES=0
|
||||||
|
shopt -s nullglob
|
||||||
|
for cfg in "/usr/share/kdump.d"/*; do
|
||||||
|
if [ -f "$cfg" ]; then
|
||||||
|
. "$cfg"
|
||||||
|
HAVE_CFG_FILES=1
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
shopt -u nullglob
|
||||||
|
|
||||||
|
if [ ${HAVE_CFG_FILES} -eq 0 ]; then
|
||||||
|
logger "kdump: no config files in /usr/share/kdump.d/ - aborting."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
14
kdump-load.header
Normal file
14
kdump-load.header
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
set -uo pipefail
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: LGPL-2.1+
|
||||||
|
#
|
||||||
|
# Copyright (c) 2021 Valve.
|
||||||
|
# Maintainer: Guilherme G. Piccoli <gpiccoli@igalia.com>
|
||||||
|
#
|
||||||
|
# Script that loads the panic kdump (from within a systemd service) and/or
|
||||||
|
# configures the Pstore-RAM mechanism. If the proper parameters are passed
|
||||||
|
# also, either it creates the minimal kdump initramfs for the running kernel
|
||||||
|
# or removes all the previously created ones. Since it runs on boot time,
|
||||||
|
# extra care is required to avoid boot hangs.
|
||||||
|
#
|
||||||
@ -1,18 +1,3 @@
|
|||||||
#!/bin/bash
|
|
||||||
set -uo pipefail
|
|
||||||
#
|
|
||||||
# SPDX-License-Identifier: LGPL-2.1+
|
|
||||||
#
|
|
||||||
# Copyright (c) 2021 Valve.
|
|
||||||
# Maintainer: Guilherme G. Piccoli <gpiccoli@igalia.com>
|
|
||||||
#
|
|
||||||
# Script that loads the panic kdump (from within a systemd service) and/or
|
|
||||||
# configures the Pstore-RAM mechanism. If the proper parameters are passed
|
|
||||||
# also, either it creates the minimal kdump initramfs for the running kernel
|
|
||||||
# or removes all the previously created ones. Since it runs on boot time,
|
|
||||||
# extra care is required to avoid boot hangs.
|
|
||||||
#
|
|
||||||
|
|
||||||
# This function has 2 purposes: if 'kdump' is passed as argument and we don't
|
# This function has 2 purposes: if 'kdump' is passed as argument and we don't
|
||||||
# have crashkernel memory reserved, we edit grub config file and recreate
|
# have crashkernel memory reserved, we edit grub config file and recreate
|
||||||
# grub.cfg, so next boot has it reserved; in this case, we also bail-out,
|
# grub.cfg, so next boot has it reserved; in this case, we also bail-out,
|
||||||
@ -86,21 +71,7 @@ cleanup_unused_initrd() {
|
|||||||
rm -f "${INSTALLED_KERNELS}"
|
rm -f "${INSTALLED_KERNELS}"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Load the necessary external variables, otherwise it'll fail later.
|
load_kdump_config
|
||||||
HAVE_CFG_FILES=0
|
|
||||||
shopt -s nullglob
|
|
||||||
for cfg in "/usr/share/kdump.d"/*; do
|
|
||||||
if [ -f "$cfg" ]; then
|
|
||||||
. "$cfg"
|
|
||||||
HAVE_CFG_FILES=1
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
shopt -u nullglob
|
|
||||||
|
|
||||||
if [ ${HAVE_CFG_FILES} -eq 0 ]; then
|
|
||||||
logger "kdump: no config files in /usr/share/kdump.d/ - aborting."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Find the proper mount point expected for kdump collection:
|
# Find the proper mount point expected for kdump collection:
|
||||||
DEVN_MOUNTED="$(findmnt "${MOUNT_DEVNODE}" -fno TARGET)"
|
DEVN_MOUNTED="$(findmnt "${MOUNT_DEVNODE}" -fno TARGET)"
|
||||||
10
module-setup.header
Normal file
10
module-setup.header
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: LGPL-2.1+
|
||||||
|
#
|
||||||
|
# Copyright (c) 2021 Valve.
|
||||||
|
# Maintainer: Guilherme G. Piccoli <gpiccoli@igalia.com>
|
||||||
|
#
|
||||||
|
# Kdump-initrd module construction/inclusion script for
|
||||||
|
# Dracut-based initramfs.
|
||||||
|
#
|
||||||
@ -1,14 +1,3 @@
|
|||||||
#!/bin/bash
|
|
||||||
#
|
|
||||||
# SPDX-License-Identifier: LGPL-2.1+
|
|
||||||
#
|
|
||||||
# Copyright (c) 2021 Valve.
|
|
||||||
# Maintainer: Guilherme G. Piccoli <gpiccoli@igalia.com>
|
|
||||||
#
|
|
||||||
# Kdump-initrd module construction/inclusion script for
|
|
||||||
# Dracut-based initramfs.
|
|
||||||
#
|
|
||||||
|
|
||||||
# Only include kdump if it is explicitly asked in the argument list
|
# Only include kdump if it is explicitly asked in the argument list
|
||||||
check() {
|
check() {
|
||||||
return 255
|
return 255
|
||||||
@ -25,21 +14,7 @@ install() {
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Load the necessary external variables, otherwise it'll fail later.
|
load_kdump_config
|
||||||
HAVE_CFG_FILES=0
|
|
||||||
shopt -s nullglob
|
|
||||||
for cfg in "/usr/share/kdump.d"/*; do
|
|
||||||
if [ -f "$cfg" ]; then
|
|
||||||
. "$cfg"
|
|
||||||
HAVE_CFG_FILES=1
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
shopt -u nullglob
|
|
||||||
|
|
||||||
if [ ${HAVE_CFG_FILES} -eq 0 ]; then
|
|
||||||
logger "kdump: no config files in /usr/share/kdump.d/ - aborting."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# First clear all unnecessary firmwares/drivers added by drm in order
|
# First clear all unnecessary firmwares/drivers added by drm in order
|
||||||
# to reduce the size of the minimal initramfs being created. This
|
# to reduce the size of the minimal initramfs being created. This
|
||||||
11
save-dumps.header
Normal file
11
save-dumps.header
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
set -uo pipefail
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: LGPL-2.1+
|
||||||
|
#
|
||||||
|
# Copyright (c) 2021 Valve.
|
||||||
|
# Maintainer: Guilherme G. Piccoli <gpiccoli@igalia.com>
|
||||||
|
#
|
||||||
|
# This is the kdump/pstore log collector; this script prepares the
|
||||||
|
# collected data and save it in the local disk, in the next successful boot.
|
||||||
|
#
|
||||||
@ -1,30 +1,4 @@
|
|||||||
#!/bin/bash
|
load_kdump_config
|
||||||
set -uo pipefail
|
|
||||||
#
|
|
||||||
# SPDX-License-Identifier: LGPL-2.1+
|
|
||||||
#
|
|
||||||
# Copyright (c) 2021 Valve.
|
|
||||||
# Maintainer: Guilherme G. Piccoli <gpiccoli@igalia.com>
|
|
||||||
#
|
|
||||||
# This is the kdump/pstore log collector; this script prepares the
|
|
||||||
# collected data and save it in the local disk, in the next successful boot.
|
|
||||||
#
|
|
||||||
|
|
||||||
# Load the necessary external variables, otherwise it'll fail later.
|
|
||||||
HAVE_CFG_FILES=0
|
|
||||||
shopt -s nullglob
|
|
||||||
for cfg in "/usr/share/kdump.d"/*; do
|
|
||||||
if [ -f "$cfg" ]; then
|
|
||||||
. "$cfg"
|
|
||||||
HAVE_CFG_FILES=1
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
shopt -u nullglob
|
|
||||||
|
|
||||||
if [ ${HAVE_CFG_FILES} -eq 0 ]; then
|
|
||||||
logger "kdump: no config files in /usr/share/kdump.d/ - aborting."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
MAIN_FOLDER="$(cat "${MNT_TMP}")"
|
MAIN_FOLDER="$(cat "${MNT_TMP}")"
|
||||||
rm -f "${MNT_TMP}"
|
rm -f "${MNT_TMP}"
|
||||||
Reference in New Issue
Block a user