From 78d5bd14154bfbb25298113545857f96c198e4fa Mon Sep 17 00:00:00 2001 From: Marcin Krol Date: Fri, 24 Jul 2015 16:21:23 +0000 Subject: [PATCH] - from PLD --- mdadm-checkarray | 184 +++++++++++++++++++++++++++++++++++++++++++++++ mdadm.cron | 13 ++++ mdadm.init | 83 +++++++++++++++++++++ mdadm.spec | 178 +++++++++++++++++++++++++++++++++++++++++++++ mdadm.sysconfig | 17 +++++ 5 files changed, 475 insertions(+) create mode 100644 mdadm-checkarray create mode 100644 mdadm.cron create mode 100644 mdadm.init create mode 100644 mdadm.spec create mode 100644 mdadm.sysconfig diff --git a/mdadm-checkarray b/mdadm-checkarray new file mode 100644 index 0000000..4cca581 --- /dev/null +++ b/mdadm-checkarray @@ -0,0 +1,184 @@ +#!/bin/sh +# +# checkarray -- initiates a check run of an MD array's redundancy information. +# +# Copyright © martin f. krafft +# distributed under the terms of the Artistic Licence 2.0 +# +set -eu + +PROGNAME=${0##*/} + +about() +{ + echo "$PROGNAME -- MD array (RAID) redundancy checker tool" + echo '$Id$' + echo "Copyright (C) martin f. krafft " + echo "Released under the terms of the Artistic Licence 2.0" +} + +usage() +{ + about + echo + echo "Usage: $PROGNAME [options] [arrays]" + echo + echo "Valid options are:" + cat <<-_eof | column -s\& -t + -a|--all & check all assembled arrays (check /proc/mdstat). + -c|--cron & honour AUTOCHECK setting in /etc/sysconfig/mdadm. + -s|--status & print redundancy check status of devices. + -x|--cancel & queue a request to cancel a running redundancy check. + -q|--quiet & suppress informational messages. + -Q|--real-quiet & suppress all output messages, including warnings and errors. + -h|--help & show this output. + -V|--version & show version information. + _eof + echo + echo "Examples:" + echo " $PROGNAME --all" + echo " $PROGNAME --quiet /dev/md[123]" + echo " $PROGNAME -sa" + echo " $PROGNAME -x --all" + echo + echo "Devices can be specified in almost any format. The following are" + echo "all equivalent:" + echo " /dev/md0, md0, /dev/md/0, /sys/block/md0" + echo + echo "The --all option overrides all arrays passed to the script." + echo + echo "You can also control the status of a check with /proc/mdstat ." +} + +SHORTOPTS=achVqQsx +LONGOPTS=all,cron,help,version,quiet,real-quiet,status,cancel + +if [ $# -eq 0 ]; then + usage >&2 + exit 0 +fi + +eval set -- $(getopt -o $SHORTOPTS -l $LONGOPTS -n $PROGNAME -- "$@") + +arrays='' +cron=0 +all=0 +quiet=0 +status=0 +action=check + +for opt in "$@"; do + case "$opt" in + -a|--all) all=1;; + -c|--cron) cron=1;; + -s|--status) action=status;; + -x|--cancel) action=idle;; + -h|--help) usage; exit 0;; + -q|--quiet) quiet=1;; + -Q|--real-quiet) quiet=2;; + -V|--version) about; exit 0;; + /dev/md/*|md/*) arrays="${arrays:+$arrays }md${opt#*md/}";; + /dev/md*|md*) arrays="${arrays:+$arrays }${opt#/dev/}";; + /sys/block/md*) arrays="${arrays:+$arrays }${opt#/sys/block/}";; + --) :;; + *) echo "$PROGNAME: E: invalid option: $opt" >&2; usage >&2; exit 0;; + esac +done + +is_true() +{ + case "${1:-}" in + [Yy]es|[Yy]|1|[Tt]rue|[Tt]) return 0;; + *) return 1; + esac +} + +DEBIANCONFIG=/etc/sysconfig/mdadm +[ -r $DEBIANCONFIG ] && . $DEBIANCONFIG +if [ $cron = 1 ] && ! is_true ${AUTOCHECK:-false}; then + [ $quiet -lt 1 ] && echo "$PROGNAME: I: disabled in $DEBIANCONFIG ." >&2 + exit 0 +fi + +if [ ! -f /proc/mdstat ]; then + [ $quiet -lt 2 ] && echo "$PROGNAME: E: MD subsystem not loaded, or /proc unavailable." >&2 + exit 2 +fi + +if [ ! -d /sys/block ]; then + [ $quiet -lt 2 ] && echo "$PROGNAME: E: /sys filesystem not available." >&2 + exit 7 +fi + +if [ -z "$(ls /sys/block/md* 2>/dev/null)" ]; then + if [ $quiet -lt 2 ] && [ $cron != 1 ]; then + echo "$PROGNAME: W: no active MD arrays found." >&2 + echo "$PROGNAME: W: (maybe uninstall the mdadm package?)" >&2 + fi + exit 5 +fi + +if [ -z "$(ls /sys/block/md*/md/level 2>/dev/null)" ]; then + [ $quiet -lt 2 ] && echo "$PROGNAME: E: kernel too old, no support for redundancy checks." >&2 + exit 6 +fi + +if ! egrep -q '^raid([1456]|10)$' /sys/block/md*/md/level 2>/dev/null; then + [ $quiet -lt 1 ] && echo "$PROGNAME: I: no redundant arrays present; skipping checks..." >&2 + exit 0 +fi + +if [ -z "$(ls /sys/block/md*/md/sync_action 2>/dev/null)" ]; then + [ $quiet -lt 2 ] && echo "$PROGNAME: E: no kernel support for redundancy checks." >&2 + exit 3 +fi + +if [ $all = 1 ]; then + arrays="$(ls -d1 /sys/block/md* | cut -d/ -f4)" +elif [ -z "$arrays" ]; then + echo "$PROGNAME: E: specify array devices in command line." >&2 + exit 0 +fi + +for array in $arrays; do + SYNC_ACTION_CTL=/sys/block/$array/md/sync_action + + if [ ! -e $SYNC_ACTION_CTL ]; then + [ $quiet -lt 1 ] && echo "$PROGNAME: I: skipping non-redundant array $array." >&2 + continue + fi + + cur_status="$(cat $SYNC_ACTION_CTL)" + + if [ $action = status ]; then + echo "$array: $cur_status" + continue + fi + + if [ ! -w $SYNC_ACTION_CTL ]; then + [ $quiet -lt 2 ] && echo "$PROGNAME: E: $SYNC_ACTION_CTL not writeable." >&2 + exit 4 + fi + + case "$action" in + idle) + echo $action > $SYNC_ACTION_CTL + [ $quiet -lt 1 ] && echo "$PROGNAME: I: cancel request queued for array $array." >&2 + ;; + + check) + if [ "$cur_status" != idle ]; then + [ $quiet -lt 2 ] && echo "$PROGNAME: W: array $array not idle, skipping..." >&2 + continue + fi + + # queue request for the array. The kernel will make sure that these requests + # are properly queued so as to not kill one of the array. + echo $action > $SYNC_ACTION_CTL + [ $quiet -lt 1 ] && echo "$PROGNAME: I: check queued for array $array." >&2 + ;; + esac + +done + +exit 0 diff --git a/mdadm.cron b/mdadm.cron new file mode 100644 index 0000000..4c180f8 --- /dev/null +++ b/mdadm.cron @@ -0,0 +1,13 @@ +# +# cron.d/mdadm -- schedules periodic redundancy checks of MD devices +# +# Copyright © martin f. krafft +# distributed under the terms of the Artistic Licence 2.0 +# + +# By default, run at 00:57 on every Sunday, but do nothing unless the day of +# the month is less than or equal to 7. Thus, only run on the first Sunday of +# each month. crontab(5) sucks, unfortunately, in this regard; therefore this +# hack (see debian#380425). +57 0 * * 0 root [ $(date +\%d) -le 7 ] && /sbin/mdadm-checkarray --cron --all --quiet + diff --git a/mdadm.init b/mdadm.init new file mode 100644 index 0000000..423954e --- /dev/null +++ b/mdadm.init @@ -0,0 +1,83 @@ +#!/bin/sh +# +# mdadm This shell script takes care of starting and stopping mdadm. +# +# chkconfig: 2345 80 30 +# description: RAID array monitoring +# +# processname: mdadm +# config: /etc/mdadm.conf +# pidfile: /var/run/mdadm.pid + +# Source function library. +. /etc/rc.d/init.d/functions + +# Source mdadm configuration. +if [ -f /etc/sysconfig/mdadm ]; then + . /etc/sysconfig/mdadm +fi + +start() { + # Start daemons. + if [ ! -f /var/lock/subsys/mdadm ]; then + [ -n "$MDADM_EMAIL" ] && echo "WARNING: sysconfig/mdadm:MDADM_EMAIL no longer supported. Please use /etc/mdadm.conf:MAILADDR setting." >&2 + msg_starting mdadm + daemon /sbin/mdadm --monitor --scan --daemonise --pid-file /var/run/mdadm.pid ${MDADM_OPTS} + RETVAL=$? + [ $RETVAL -eq 0 ] && touch /var/lock/subsys/mdadm + else + msg_already_running mdadm + fi +} + +stop() { + # Stop daemons. + if [ -f /var/lock/subsys/mdadm ]; then + msg_stopping mdadm + killproc --pidfile /var/run/mdadm.pid mdadm + rm -f /var/lock/subsys/mdadm >/dev/null 2>&1 + else + msg_not_running mdadm + fi +} + +condrestart() { + if [ -f /var/lock/subsys/mdadm ]; then + stop + start + else + msg_not_running mdadm + RETVAL=$1 + fi +} + +RETVAL=0 +# See how we were called. +case "$1" in + start) + start + ;; + stop) + stop + ;; + restart) + stop + start + ;; + try-restart) + condrestart 0 + ;; + force-reload) + condrestart 7 + ;; + status) + cat /proc/mdstat + status mdadm + exit $? + ;; + *) + msg_usage "$0 {start|stop|restart|try-restart|force-reload|status}" + exit 3 +esac + +exit $RETVAL diff --git a/mdadm.spec b/mdadm.spec new file mode 100644 index 0000000..9589584 --- /dev/null +++ b/mdadm.spec @@ -0,0 +1,178 @@ +# +# Conditional build: +%bcond_with initrd # don't build initrd version +%bcond_with dietlibc # link initrd version with static glibc instead of dietlibc +%bcond_without tests # don't perform "make test" + +Summary: Tool for creating and maintaining software RAID devices +Summary(pl.UTF-8): Narzędzie do tworzenia i obsługi programowych macierzy RAID +Name: mdadm +Version: 3.3.2 +Release: 2 +License: GPL v2+ +Group: Base +Source0: https://www.kernel.org/pub/linux/utils/raid/mdadm/%{name}-%{version}.tar.xz +# Source0-md5: 44698d351501cac6a89072dc877eb220 +Source1: %{name}.init +Source2: %{name}.sysconfig +Source3: %{name}.cron +Source4: %{name}-checkarray +URL: https://www.kernel.org/pub/linux/utils/raid/mdadm/ +BuildRequires: groff +BuildRequires: rpmbuild(macros) >= 1.213 +%if %{with initrd} + %if %{with dietlibc} +BuildRequires: dietlibc-static + %else +BuildRequires: glibc-static + %endif +%endif +BuildRequires: rpmbuild(macros) >= 1.268 +BuildRequires: tar >= 1:1.22 +BuildRequires: xz +Requires(post,preun): /sbin/chkconfig +Requires: /sbin/chkconfig +Requires: rc-scripts >= 0.4.2.4-2 +Suggests: crondaemon +%{!?with_initrd:Obsoletes: mdadm-initrd < %{version}-%{release}} +Obsoletes: mdctl +BuildRoot: %{tmpdir}/%{name}-%{version}-root-%(id -u -n) + +%define _sbindir /sbin + +%description +This package includes tool you need to set up and maintain a software +RAID device under Linux. It's thought as an alternative to raidtools +package. + +%description -l pl.UTF-8 +Pakiet ten zawiera narzędzie potrzebne do tworzenia i obsługi +programowych macierzy RAID. Program ten jest pomyślany jako +alternatywa dla pakietu raidtools. + +%package initrd +Summary: Tool for maintaining software RAID devices - initrd version +Summary(pl.UTF-8): Narzędzie do obsługi programowych macierzy RAID, wersja dla initrd +Group: Base +Conflicts: geninitrd < 10000.10 + +%description initrd +Tool for maintaining software RAID devices - statically linked for +initrd. + +%description initrd -l pl.UTF-8 +Narzędzie do zarządzania programowymi macierzami RAID - statycznie +skonsolidowane na potrzeby initrd. + +%prep +%setup -q + +%build +%if %{with initrd} +%if %{with dietlibc} +%{__make} mdadm \ + CC="diet %{__cc} %{rpmcflags} %{rpmcppflags} %{rpmldflags} -Os -static" \ + CWFLAGS="-Wall" +mv -f mdadm initrd-mdadm +%{__make} clean +diet %{__cc} -DUCLIBC -DMDASSEMBLE_AUTO -DMDASSEMBLE %{rpmcflags} %{rpmcppflags} %{rpmldflags} -Os -static \ + -o initrd-mdassemble \ + mdassemble.c Assemble.c Manage.c config.c policy.c dlink.c util.c lib.c \ + super0.c super1.c super-ddf.c super-intel.c sha1.c crc32.c sg_io.c mdstat.c \ + platform-intel.c probe_roms.c sysfs.c super-mbr.c super-gpt.c mdopen.c maps.c xmalloc.c +%else +%{__make} mdadm.static \ + CC="%{__cc}" \ + CFLAGS="%{rpmcflags} %{rpmcppflags}" \ + LDFLAGS="%{rpmldflags}" +mv -f mdadm.static initrd-mdadm +%{__make} clean +%{__cc} -DMDASSEMBLE_AUTO -DMDASSEMBLE %{rpmcflags} %{rpmcppflags} %{rpmldflags} -DHAVE_STDINT_H -static \ + -o initrd-mdassemble \ + mdassemble.c Assemble.c Manage.c config.c policy.c dlink.c util.c lib.c \ + super0.c super1.c super-ddf.c super-intel.c sha1.c crc32.c sg_io.c mdstat.c \ + platform-intel.c probe_roms.c sysfs.c super-mbr.c super-gpt.c mdopen.c maps.c xmalloc.c +%endif +%{__make} clean +%endif + +%{__make} mdassemble \ + MDASSEMBLE_AUTO=1 \ + CC="%{__cc}" \ + CFLAGS="%{rpmcflags} %{rpmcppflags}" \ + LDFLAGS="%{rpmldflags}" \ + SYSCONFDIR="%{_sysconfdir}" +mv mdassemble regular-mdassemble +%{__make} clean + +%{__make} all mdadm mdadm.8 \ + CC="%{__cc}" \ + CFLAGS="%{rpmcflags} %{rpmcppflags}" \ + LDFLAGS="%{rpmldflags}" \ + SYSCONFDIR="%{_sysconfdir}" + +%{?with_tests:%{__make} test} + +%install +rm -rf $RPM_BUILD_ROOT +install -d $RPM_BUILD_ROOT{%{_sbindir},%{_mandir}/man{5,8},/etc/{rc.d/init.d,sysconfig,cron.d}} + +%if %{with initrd} +install -d $RPM_BUILD_ROOT%{_libdir}/initrd +install -p initrd-mdadm $RPM_BUILD_ROOT%{_libdir}/initrd/mdadm +install -p initrd-mdassemble $RPM_BUILD_ROOT%{_libdir}/initrd/mdassemble +ln -s mdadm $RPM_BUILD_ROOT%{_libdir}/initrd/mdctl +%endif + +install -p regular-mdassemble $RPM_BUILD_ROOT%{_sbindir}/mdassemble +install -p mdadm $RPM_BUILD_ROOT%{_sbindir} + +cp -p md*.5 $RPM_BUILD_ROOT%{_mandir}/man5 +cp -p md*.8 $RPM_BUILD_ROOT%{_mandir}/man8 + +cp -p mdadm.conf-example $RPM_BUILD_ROOT%{_sysconfdir}/mdadm.conf + +ln -s mdadm $RPM_BUILD_ROOT%{_sbindir}/mdctl + +install -p %{SOURCE1} $RPM_BUILD_ROOT/etc/rc.d/init.d/%{name} +cp -p %{SOURCE2} $RPM_BUILD_ROOT/etc/sysconfig/%{name} + +cp -p %{SOURCE3} $RPM_BUILD_ROOT/etc/cron.d/mdadm-checkarray +install -p %{SOURCE4} $RPM_BUILD_ROOT%{_sbindir}/mdadm-checkarray + +%clean +rm -rf $RPM_BUILD_ROOT + +%post +/sbin/chkconfig --add %{name} +%service mdadm restart "RAID monitoring" + +%preun +if [ "$1" = "0" ]; then + %service mdadm stop + /sbin/chkconfig --del mdadm +fi + +%files +%defattr(644,root,root,755) +%doc ANNOUNCE* ChangeLog TODO +%attr(755,root,root) %{_sbindir}/mdadm +%attr(755,root,root) %{_sbindir}/mdadm-checkarray +%attr(755,root,root) %{_sbindir}/mdassemble +%attr(755,root,root) %{_sbindir}/mdctl +%attr(640,root,root) %config(noreplace,missingok) %verify(not md5 mtime size) %{_sysconfdir}/mdadm.conf +%{_mandir}/man5/mdadm.conf.5* +%{_mandir}/man8/mdadm.8* +%{_mandir}/man8/mdassemble.8* +%{_mandir}/man8/mdmon.8* +%attr(754,root,root) /etc/rc.d/init.d/%{name} +%attr(640,root,root) %config(noreplace) %verify(not md5 mtime size) /etc/sysconfig/%{name} +%config(noreplace) %attr(640,root,root) /etc/cron.d/mdadm-checkarray + +%if %{with initrd} +%files initrd +%defattr(644,root,root,755) +%attr(755,root,root) %{_libdir}/initrd/mdadm +%attr(755,root,root) %{_libdir}/initrd/mdassemble +%attr(755,root,root) %{_libdir}/initrd/mdctl +%endif diff --git a/mdadm.sysconfig b/mdadm.sysconfig new file mode 100644 index 0000000..410af02 --- /dev/null +++ b/mdadm.sysconfig @@ -0,0 +1,17 @@ +# Customized setings for sysconf + +# Nice level for sysconf +SERVICE_RUN_NICE_LEVEL="+5" + +# Should mdadm run monthly redundancy checks of the MD arrays? +# +# If the kernel supports it (versions greater than 2.6.14), mdadm can periodically check the +# redundancy of MD arrays (RAIDs). This may be a resource-intensive process, +# depending on the local setup, but it could help prevent rare cases of data loss. +# Note that this is a read-only check unless errors are found; if errors are +# found, mdadm will try to correct them, which may result in write access to +# the media. +# . +# The default, if turned on, is to check on the first Sunday of every +# month at 01:06. +AUTOCHECK=yes -- 2.44.0