diff options
Diffstat (limited to '')
-rw-r--r-- | debian/mdadm.init | 100 | ||||
-rw-r--r-- | debian/mdadm.initramfs-hook | 109 |
2 files changed, 209 insertions, 0 deletions
diff --git a/debian/mdadm.init b/debian/mdadm.init new file mode 100644 index 0000000..0a9004f --- /dev/null +++ b/debian/mdadm.init @@ -0,0 +1,100 @@ +#!/bin/sh +# +# Start the MD monitor daemon for all active MD arrays if desired. +# This script is not used under systemd. +# +# Copyright © 2001-2005 Mario Jou/3en <joussen@debian.org> +# Copyright © 2005-2009 Martin F. Krafft <madduck@debian.org> +# Distributable under the terms of the GNU GPL version 2. +# +### BEGIN INIT INFO +# Provides: mdadm +# Required-Start: $local_fs $syslog +# Required-Stop: $local_fs $syslog sendsigs +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: MD monitoring daemon +# Description: mdadm provides a monitor mode, in which it will scan for +# problems with the MD devices. If a problem is found, the +# administrator is alerted via email, or a custom script is +# run. +### END INIT INFO +# +set -eu + +MDADM=/sbin/mdadm +MDMON=/sbin/mdmon +RUNDIR=/run/mdadm +PIDFILE=$RUNDIR/monitor.pid +DEBIANCONFIG=/etc/default/mdadm + +test -x "$MDADM" || exit 0 + +test -f /proc/mdstat || exit 0 + +START_DAEMON=true +test -f $DEBIANCONFIG && . $DEBIANCONFIG + +. /lib/lsb/init-functions + +is_true() +{ + case "${1:-}" in + [Yy]es|[Yy]|1|[Tt]|[Tt]rue) return 0;; + *) return 1; + esac +} + +case "${1:-}" in + start) + if [ -x /usr/bin/systemd-detect-virt ] && /usr/bin/systemd-detect-virt --quiet --container; then + log_daemon_msg "Not starting MD monitoring service in container" + log_end_msg 0 + exit 0 + fi + + if is_true $START_DAEMON; then + log_daemon_msg "Starting MD monitoring service" "mdadm --monitor" + mkdir -p $RUNDIR + set +e + start-stop-daemon -S -p $PIDFILE -x $MDADM -- \ + --monitor --pid-file $PIDFILE --daemonise --scan ${DAEMON_OPTIONS:-} + log_end_msg $? + set -e + fi + if [ "$(echo $RUNDIR/md[0-9]*.pid)" != "$RUNDIR/md[0-9]*.pid" ]; then + log_daemon_msg "Restarting MD external metadata monitor" "mdmon --takeover --all" + set +e + $MDMON --takeover --all + log_end_msg $? + set -e + fi + ;; + stop) + if [ -f $PIDFILE ] ; then + log_daemon_msg "Stopping MD monitoring service" "mdadm --monitor" + set +e + start-stop-daemon -K -p $PIDFILE -x $MDADM + rm -f $PIDFILE + log_end_msg $? + set -e + fi + for file in $RUNDIR/md[0-9]*.pid ; do + [ ! -f "$file" ] && continue + ln -sf $file /run/sendsigs.omit.d/mdmon-${file##*/} + done + ;; + status) + status_of_proc -p $PIDFILE "$MDADM" "mdadm" && exit 0 || exit $? + ;; + restart|reload|force-reload) + ${0:-} stop + ${0:-} start + ;; + *) + echo "Usage: ${0:-} {start|stop|status|restart|reload|force-reload}" >&2 + exit 1 + ;; +esac + +exit 0 diff --git a/debian/mdadm.initramfs-hook b/debian/mdadm.initramfs-hook new file mode 100644 index 0000000..c89d034 --- /dev/null +++ b/debian/mdadm.initramfs-hook @@ -0,0 +1,109 @@ +#!/bin/sh +# +# Copyright © 2006-2008 Martin F. Krafft <madduck@debian.org>, +# 2012 Michael Tokarev <mjt@tls.msk.ru> +# based on the scripts in the initramfs-tools package. +# released under the terms of the Artistic Licence. +# +set -eu + +PREREQ="udev" +prereqs() +{ + echo "$PREREQ" +} + +case "${1:-}" in + prereqs) + prereqs + exit 0 + ;; +esac + +is_true() +{ + case "${1:-}" in + [Yy]es|[Yy]|1|[Tt]rue|[Tt]) return 0;; + *) return 1;; + esac +} + +write() +{ + local PREFIX; PREFIX=$1; shift + echo "${PREFIX}: mdadm: $@" >&2 +} + +info() +{ + is_true ${VERBOSE:-false} && write I "$@" || : +} + +warn() +{ + write W "$@" +} + +. /usr/share/initramfs-tools/hook-functions + +# copy the binary as early as possible +copy_exec /sbin/mdadm /sbin +copy_exec /sbin/mdmon /sbin + +# Copy udev rules, which udev no longer does +for UDEV_RULE in 63-md-raid-arrays.rules 64-md-raid-assembly.rules; do +for rules_folder in /lib/udev/rules.d /etc/udev/rules.d; do + if [ -f $rules_folder/$UDEV_RULE ]; then + mkdir -p $DESTDIR$rules_folder + cp $rules_folder/$UDEV_RULE $DESTDIR$rules_folder/$UDEV_RULE + fi +done +done + +# load raid modules in the initramfs +for module in linear multipath raid0 raid1 raid456 raid5 raid6 raid10; do + force_load $module +done + +# load efivars for Intel RST IMSM, see Bug#962844 +force_load efivarfs || true + +# copy the mdadm configuration +CONFIG=/etc/mdadm/mdadm.conf +ALTCONFIG=/etc/mdadm.conf +DESTMDADMCONF=$DESTDIR/etc/mdadm/mdadm.conf +[ ! -f $CONFIG ] && [ -f $ALTCONFIG ] && CONFIG=$ALTCONFIG || : +mkdir -p ${DESTDIR}/etc/mdadm + +if [ ! -f $CONFIG ]; then + # there is no configuration file, so let's create one + if /usr/share/mdadm/mkconf generate $CONFIG; then + # all is well + cp -p $CONFIG $DESTMDADMCONF + info "auto-generated the mdadm.conf configuration file." + else + # we failed to auto-generate, so let the emergency procedure take over + warn "failed to auto-generate the mdadm.conf file." + warn "please read /usr/share/doc/mdadm/README.upgrading-2.5.3.gz ." + fi +else + cp -p $CONFIG ${DESTDIR}/etc/mdadm + sed -i '/^CREATE/s/^/#/' $DESTMDADMCONF + if ! grep -q '^ARRAY' $CONFIG; then + tmpfile="${DESTMDADMCONF}.tmp" + if /usr/share/mdadm/mkconf > $tmpfile; then + cp -p $tmpfile $DESTMDADMCONF + rm -f $tmpfile + else + warn "failed to auto-generate temporary mdadm.conf file." + fi + else + # make sure the configuration file knows about all running devices + /sbin/mdadm --detail --scan | while read array device params; do + uuid=${params#*UUID=}; uuid=${uuid%% *} + if grep -qi "UUID=$uuid" $DESTMDADMCONF; then + info "$uuid $device added to the mdadm.conf in the initramfs" + fi + done + fi +fi |