diff --git a/.SRCINFO b/.SRCINFO deleted file mode 100644 index 1b69106..0000000 --- a/.SRCINFO +++ /dev/null @@ -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 - diff --git a/PKGBUILD b/PKGBUILD deleted file mode 100644 index 3a55519..0000000 --- a/PKGBUILD +++ /dev/null @@ -1,27 +0,0 @@ -# Maintainer: m00n -# Contributor: artoo - -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 -} diff --git a/device-mapper.initd b/device-mapper.initd index dd4ec76..4b7b9f1 100644 --- a/device-mapper.initd +++ b/device-mapper.initd @@ -1,5 +1,5 @@ -#!/usr/bin/openrc-run -# Copyright 1999-2016 Gentoo Foundation +#!/sbin/openrc-run +# Copyright 1999-2019 Gentoo Authors # Distributed under the terms of the GNU General Public License v2 depend() { @@ -30,7 +30,7 @@ build_dmsetup_command() { # If there's just one line: if [ ${count} -eq 1 ] ; then 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: elif [ ${count} -gt 1 ] ; then @@ -46,7 +46,7 @@ build_dmsetup_command() { grep ${1} | awk NR==${c}\ \{\$1=\"\"\;\ print\ \$0\})" fi done - echo "${dmsetup_cmd} | /usr/bin/dmsetup create ${1}" + echo "${dmsetup_cmd} | /sbin/dmsetup create ${1}" fi return 0 @@ -80,7 +80,7 @@ dmvolume_exists() { [ -z "${volume}" ] && return 1 - /usr/bin/dmsetup ls 2>/dev/null | \ + /sbin/dmsetup ls 2>/dev/null | \ while read line ; do for x in ${line} ; do # the following conditonal return only breaks out @@ -106,7 +106,7 @@ dmvolume_exists() { is_empty_dm_volume() { 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" ] } @@ -120,7 +120,7 @@ start() { 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)" ] && \ einfo " Setting up device-mapper volumes:" @@ -136,7 +136,7 @@ start() { # dmsetup still adds an empty volume in some cases, # so lets remove it is_empty_dm_volume "${volume}" && \ - /usr/bin/dmsetup remove "${volume}" 2>/dev/null + /sbin/dmsetup remove "${volume}" 2>/dev/null else eend 0 fi diff --git a/dmeventd.initd b/dmeventd.initd index 7464704..bc08c0a 100644 --- a/dmeventd.initd +++ b/dmeventd.initd @@ -1,9 +1,13 @@ -#!/usr/bin/openrc-run -# Copyright 1999-2016 Gentoo Foundation +#!/sbin/openrc-run +# Copyright 1999-2019 Gentoo Authors # Distributed under the terms of the GNU General Public License v2 -PIDFILE=/run/dmeventd.pid -BIN=/usr/bin/dmeventd +command=/sbin/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() { # As of .67-r1, we call ALL lvm start/stop scripts with --sysinit, that @@ -11,15 +15,7 @@ depend() { after lvm device-mapper } -start() { - ebegin "Starting dmeventd" - start-stop-daemon --start --exec $BIN --pidfile $PIDFILE - eend $? +reload() { + # TODO: this is not supported under supervisors + ${command} -R } - -stop() { - ebegin "Stopping dmeventd" - start-stop-daemon --stop --exec $BIN --pidfile $PIDFILE - eend $? -} - diff --git a/dmtab b/dmtab new file mode 100644 index 0000000..37a0d28 --- /dev/null +++ b/dmtab @@ -0,0 +1,11 @@ +#/etc/dmraid: config file for adding device-mapper volumes at boot + +# Format: : +# 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. + diff --git a/lvm-monitoring.initd b/lvm-monitoring.initd new file mode 100644 index 0000000..914d663 --- /dev/null +++ b/lvm-monitoring.initd @@ -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 +} diff --git a/lvm.confd b/lvm.confd new file mode 100644 index 0000000..b29e170 --- /dev/null +++ b/lvm.confd @@ -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 diff --git a/lvm.initd b/lvm.initd new file mode 100644 index 0000000..3468adc --- /dev/null +++ b/lvm.initd @@ -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 diff --git a/lvmlockd.initd b/lvmlockd.initd new file mode 100644 index 0000000..8b5986f --- /dev/null +++ b/lvmlockd.initd @@ -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 +} diff --git a/lvmpolld.initd b/lvmpolld.initd new file mode 100644 index 0000000..6b26010 --- /dev/null +++ b/lvmpolld.initd @@ -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 +}