This commit is contained in:
pepe 2023-05-05 07:19:36 +00:00
parent 59022bfbd7
commit 0cf59cafc5
10 changed files with 284 additions and 70 deletions

View File

@ -1,20 +0,0 @@
pkgbase = device-mapper-openrc
pkgdesc = OpenRC device-mapper init script
pkgver = 20210106
pkgrel = 1
arch = any
license = GPL2
depends = device-mapper
depends = openrc
provides = init-device-mapper
conflicts = init-device-mapper
backup = etc/conf.d/device-mapper
source = device-mapper.confd
source = device-mapper.initd
source = dmeventd.initd
sha256sums = 57777904f12a35617e5a4193c964ebb32396452487fd02353e71e16e7b46bc22
sha256sums = 630fbe07721c2a264c1b2f0195caf658c591bdef13cb82d5605bb489f59971a4
sha256sums = b4b91555f1486754717073dae83715d1e03adfdd5e56d80be8ac9689a85bc717
pkgname = device-mapper-openrc

View File

@ -1,27 +0,0 @@
# Maintainer: m00n <lmarianski@protonmail.com>
# Contributor: artoo <artoo@artixlinux.org>
pkgname=device-mapper-openrc
pkgver=20210106
pkgrel=1
pkgdesc="OpenRC device-mapper init script"
arch=('any')
license=('GPL2')
provides=('init-device-mapper')
depends=('device-mapper' 'openrc')
conflicts=('init-device-mapper')
backup=('etc/conf.d/device-mapper')
source=("device-mapper.confd"
"device-mapper.initd"
"dmeventd.initd")
sha256sums=('57777904f12a35617e5a4193c964ebb32396452487fd02353e71e16e7b46bc22'
'630fbe07721c2a264c1b2f0195caf658c591bdef13cb82d5605bb489f59971a4'
'b4b91555f1486754717073dae83715d1e03adfdd5e56d80be8ac9689a85bc717')
package() {
install -Dm755 "${srcdir}"/device-mapper.confd "${pkgdir}"/etc/openrc/conf.d/device-mapper
for f in device-mapper dmeventd; do
install -Dm755 "${srcdir}"/"$f".initd "${pkgdir}"/etc/openrc/init.d/"$f"
done
}

View File

@ -1,5 +1,5 @@
#!/usr/bin/openrc-run #!/sbin/openrc-run
# Copyright 1999-2016 Gentoo Foundation # Copyright 1999-2019 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2 # Distributed under the terms of the GNU General Public License v2
depend() { depend() {
@ -30,7 +30,7 @@ build_dmsetup_command() {
# If there's just one line: # If there's just one line:
if [ ${count} -eq 1 ] ; then if [ ${count} -eq 1 ] ; then
echo "echo $(grep -v -e '^[[:space:]]*\(#\|$\)' /etc/dmtab | \ echo "echo $(grep -v -e '^[[:space:]]*\(#\|$\)' /etc/dmtab | \
grep ${1} | awk '{$1=""; print $0}') | /usr/bin/dmsetup create ${1}" grep ${1} | awk '{$1=""; print $0}') | /sbin/dmsetup create ${1}"
# For all cases with more lines: # For all cases with more lines:
elif [ ${count} -gt 1 ] ; then elif [ ${count} -gt 1 ] ; then
@ -46,7 +46,7 @@ build_dmsetup_command() {
grep ${1} | awk NR==${c}\ \{\$1=\"\"\;\ print\ \$0\})" grep ${1} | awk NR==${c}\ \{\$1=\"\"\;\ print\ \$0\})"
fi fi
done done
echo "${dmsetup_cmd} | /usr/bin/dmsetup create ${1}" echo "${dmsetup_cmd} | /sbin/dmsetup create ${1}"
fi fi
return 0 return 0
@ -80,7 +80,7 @@ dmvolume_exists() {
[ -z "${volume}" ] && return 1 [ -z "${volume}" ] && return 1
/usr/bin/dmsetup ls 2>/dev/null | \ /sbin/dmsetup ls 2>/dev/null | \
while read line ; do while read line ; do
for x in ${line} ; do for x in ${line} ; do
# the following conditonal return only breaks out # the following conditonal return only breaks out
@ -106,7 +106,7 @@ dmvolume_exists() {
is_empty_dm_volume() { is_empty_dm_volume() {
local table volume=$1 local table volume=$1
set -- $(/usr/bin/dmsetup table 2>/dev/null | grep -e "^${volume}:") set -- $(/sbin/dmsetup table 2>/dev/null | grep -e "^${volume}:")
[ "${volume}" = "$1" -a -z "$2" ] [ "${volume}" = "$1" -a -z "$2" ]
} }
@ -120,7 +120,7 @@ start() {
local x volume local x volume
if [ -x /usr/bin/dmsetup -a -c /dev/mapper/control -a -f /etc/dmtab ] ; then if [ -x /sbin/dmsetup -a -c /dev/mapper/control -a -f /etc/dmtab ] ; then
[ -n "$(get_new_dm_volumes)" ] && \ [ -n "$(get_new_dm_volumes)" ] && \
einfo " Setting up device-mapper volumes:" einfo " Setting up device-mapper volumes:"
@ -136,7 +136,7 @@ start() {
# dmsetup still adds an empty volume in some cases, # dmsetup still adds an empty volume in some cases,
# so lets remove it # so lets remove it
is_empty_dm_volume "${volume}" && \ is_empty_dm_volume "${volume}" && \
/usr/bin/dmsetup remove "${volume}" 2>/dev/null /sbin/dmsetup remove "${volume}" 2>/dev/null
else else
eend 0 eend 0
fi fi

View File

@ -1,9 +1,13 @@
#!/usr/bin/openrc-run #!/sbin/openrc-run
# Copyright 1999-2016 Gentoo Foundation # Copyright 1999-2019 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2 # Distributed under the terms of the GNU General Public License v2
PIDFILE=/run/dmeventd.pid command=/sbin/dmeventd
BIN=/usr/bin/dmeventd command_args_foreground='-f'
extra_started_commands=reload
pidfile=/run/dmeventd.pid
# Control idle exit behavior of daemon
export DMEVENTD_IDLE_EXIT_TIMEOUT=${DMEVENTD_IDLE_EXIT_TIMEOUT:=-1}
depend() { depend() {
# As of .67-r1, we call ALL lvm start/stop scripts with --sysinit, that # As of .67-r1, we call ALL lvm start/stop scripts with --sysinit, that
@ -11,15 +15,7 @@ depend() {
after lvm device-mapper after lvm device-mapper
} }
start() { reload() {
ebegin "Starting dmeventd" # TODO: this is not supported under supervisors
start-stop-daemon --start --exec $BIN --pidfile $PIDFILE ${command} -R
eend $?
} }
stop() {
ebegin "Stopping dmeventd"
start-stop-daemon --stop --exec $BIN --pidfile $PIDFILE
eend $?
}

11
dmtab Normal file
View File

@ -0,0 +1,11 @@
#/etc/dmraid: config file for adding device-mapper volumes at boot
# Format: <volume name>: <table>
# Example: isw0: 0 312602976 striped 2 128 /dev/sda 0 /dev/sdb 0
#
# Alternatively you can create all your volumes the first time, and just run:
#
# dmsetup table >> /etc/dmtab
#
# and verify that they are correct.

38
lvm-monitoring.initd Normal file
View File

@ -0,0 +1,38 @@
#!/sbin/openrc-run
# Copyright 1999-2019 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
# This script is based on upstream file
# LVM2.2.02.67/scripts/lvm2_monitoring_init_red_hat.in
depend() {
# As of .67-r1, we call ALL lvm start/stop scripts with --sysinit, that
# means dmeventd is NOT notified, as it cannot be safely running
need lvm dmeventd
}
VGCHANGE=/sbin/vgchange
VGS=/sbin/vgs
start() {
ret=0
# TODO do we want to separate out already active groups only?
VGSLIST=`$VGS --noheadings -o name --rows 2> /dev/null`
ebegin "Starting LVM monitoring for VGs ${VGSLIST}:"
$VGCHANGE --monitor y --poll y ${VGSLIST}
ret=$?
eend $ret
return $ret
}
stop() {
ret=0
# TODO do we want to separate out already active groups only?
VGSLIST=`$VGS --noheadings -o name --rows 2> /dev/null`
ebegin "Stopping LVM monitoring for VGs ${VGSLIST}:"
$VGCHANGE --monitor n ${VGSLIST}
ret=$?
eend $ret
return $ret
}

9
lvm.confd Normal file
View File

@ -0,0 +1,9 @@
# If LVM is built with udev, you must ensure udev is running first!
# Otherwise it will hang
rc_need="udev"
# LVM should normally only be started after mdraid is available
# this is because LVM physical volumes are very often MD devices.
rc_after="mdraid"
# vim: ft=gentoo-conf-d

173
lvm.initd Normal file
View File

@ -0,0 +1,173 @@
#!/sbin/openrc-run
# Copyright 1999-2020 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
_get_lvm_path() {
local lvm_path=
for lvm_path in /bin/lvm /sbin/lvm ; do
[ -x "${lvm_path}" ] && break
done
echo "${lvm_path}"
}
_use_lvmetad() {
local lvm_path="$(_get_lvm_path)"
[ ! -x "${lvm_path}" ] && return 1
${lvm_path} dumpconfig global 2>/dev/null | grep -q 'use_lvmetad=1'
}
_use_lvmlockd() {
local lvm_path="$(_get_lvm_path)"
[ ! -x "${lvm_path}" ] && return 1
${lvm_path} dumpconfig global 2>/dev/null | grep -q 'use_lvmlockd=1'
}
depend() {
before checkfs fsck
after modules device-mapper
# We may want lvmetad based on the configuration. If we added lvmetad
# support while lvm2 is running then we aren't dependent on it. For the
# more common case, if its disabled in the config we aren't dependent
# on it.
config /etc/lvm/lvm.conf
local _want=
if service_started ; then
_want=$(service_get_value want)
else
if _use_lvmetad ; then
_want="${_want} lvmetad"
fi
if _use_lvmlockd ; then
_want="${_want} lvmlockd"
fi
fi
# Make sure you review /etc/conf.d/lvm as well!
# Depending on your system, it might also introduce udev & mdraid
need sysfs
if [ -n "${_want}" ] ; then
want ${_want}
fi
}
config='global { locking_dir = "/run/lock/lvm" }'
dm_in_proc() {
local retval=0
for x in devices misc ; do
grep -qs 'device-mapper' /proc/${x}
retval=$((${retval} + $?))
done
return ${retval}
}
start() {
# LVM support for /usr, /home, /opt ....
# This should be done *before* checking local
# volumes, or they never get checked.
# NOTE: Add needed modules for LVM or RAID, etc
# to /etc/modules.autoload if needed
lvm_path="$(_get_lvm_path)"
if [ -z "${lvm_path}" ] ; then
eerror "Failed to find lvm binary in /bin or /sbin!"
return 1
fi
if [ -z "${CDBOOT}" ] ; then
if [ -e /proc/modules ] && ! dm_in_proc ; then
ebegin "Trying to load dm-mod module"
modprobe dm-mod 2>/dev/null
eend $?
fi
if [ -d /proc/lvm ] || dm_in_proc ; then
local has_errors=0 verbose_command
yesno "${rc_verbose}" && verbose_command=" -v"
ebegin "Starting the Logical Volume Manager"
if _use_lvmetad ; then
# Extra PV find pass because some devices might not have been available until very recently
${lvm_path} pvscan${verbose_command} --config "${config}" --cache
[ $? -ne 0 ] && has_errors=1
fi
# Now make the nodes
${lvm_path} vgscan${verbose_command} --config "${config}" --mknodes
[ $? -ne 0 ] && has_errors=1
# Enable all VGs
${lvm_path} vgchange${verbose_command} --config "${config}" --sysinit --activate y
[ $? -ne 0 ] && has_errors=1
if _use_lvmlockd ; then
# Start lockd VGs as required
${lvm_path} vgchange${verbose_command} --config "${config}" --lock-start --lock-opt auto
[ $? -ne 0 ] && has_errors=1
fi
eend ${has_errors} "Failed to start the Logical Volume Manager"
fi
fi
}
start_post() {
local _want=
if _use_lvmetad ; then
_want="${_want} lvmetad"
fi
if _use_lvmlockd ; then
_want="${_want} lvmlockd"
fi
service_set_value want "${_want}"
}
stop() {
lvm_path="$(_get_lvm_path)"
if [ -z "${lvm_path}" ] ; then
eerror "Failed to find lvm binary in /bin or /sbin!"
return 1
fi
# Stop LVM2
if [ -f /etc/lvmtab -o -d /etc/lvm ] \
&& [ -d /proc/lvm -o "$(grep device-mapper /proc/misc 2>/dev/null)" ]
then
local VGS=$($lvm_path vgs --config "${config}" -o vg_name --noheadings --nosuffix --rows 2> /dev/null)
if [ -z "${VGS}" ] ; then
# nothing to do for us
return 0
fi
local has_errors=0 verbose_command eend_cmd="eend"
yesno "${rc_verbose}" && verbose_command=" -v"
local msg="Failed to stop Logical Volume Manager"
if [ "${RC_RUNLEVEL}" = shutdown ] ; then
# failures on shutdown are non-fatal
eend_cmd="ewend"
msg="${msg} (possibly some LVs still needed for /usr or root)"
fi
ebegin "Stopping the Logical Volume Manager"
${lvm_path} vgchange${verbose_command} --config "${config}" --sysinit --activate n
[ $? -ne 0 ] && has_errors=1
${eend_cmd} ${has_errors} "${msg}"
fi
# at this point make sure we always exit without indicating an error
return 0
}
# vim:ts=4

17
lvmlockd.initd Normal file
View File

@ -0,0 +1,17 @@
#!/sbin/openrc-run
# Copyright 1999-2019 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
pidfile="/run/lvmlockd.pid"
command="/sbin/lvmlockd"
command_args="${LVMLOCKD_OPTS:--p ${pidfile}} ${LVMLOCKD_TYPE:--g sanlock}"
start_stop_daemon_args="--pidfile ${pidfile}"
depend() {
before sanlock
}
start_pre()
{
checkpath --directory /run/lvm || return 1
}

17
lvmpolld.initd Normal file
View File

@ -0,0 +1,17 @@
#!/sbin/openrc-run
# Copyright 1999-2019 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
pidfile="/run/lvmpolld.pid"
command="/sbin/lvmpolld"
command_args="${LVMPOLLD_OPTS:=-p ${pidfile}}"
start_stop_daemon_args="--pidfile ${pidfile}"
depend() {
:
}
start_pre()
{
checkpath --directory /run/lvm || return 1
}