summaryrefslogtreecommitdiff
path: root/debian/mdadm.postinst
blob: f1091f828ffba9ae9fe11a7f0609f14ffc828a8f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/bin/sh -eu
# Copyright © 2001-2005 Mario Jou/3en <joussen@debian.org>
# Copyright © 2005-2006 Martin F. Krafft <madduck@debian.org>
# Distributable under the terms of the GNU GPL version 2.
#
# $Id$
#

if [ "${1:-}" = "configure" ]; then

  set +u # debconf workaround. See #369953
  . /usr/share/debconf/confmodule
  set -u

  if [ ! -f /proc/mdstat ] && [ -x $(command -v modprobe) ] ; then
    modprobe -k md >/dev/null 2>&1 || :
  fi
  if [ ! -f /proc/mdstat ]; then
    echo 'W: failed to load RAID subsystem.' >&2
  fi

  if [ ! -e /dev/md15 ] \
    && [ ! -e /dev/.static/dev/md15 ] \
    && [ ! -e /dev/.devfsd ]; then

      echo -n 'Generating device nodes... ' >&2
      cd /dev
      if /sbin/MAKEDEV md >&2 >/dev/null; then
        echo 'done.' >&2
      else
        echo 'failed.' >&2
      fi
  fi

  DEBIANCONFIG=/etc/default/mdadm
  CONFIG=/etc/mdadm/mdadm.conf
  ALTCONFIG=/etc/mdadm.conf
  MDADM=/sbin/mdadm

  if [ -z "$2" ] && [ -s /etc/mdctl/mdctl.conf ] && [ ! -f /etc/mdadm/mdadm.conf ] ; then
    cp -a /etc/mdctl/mdctl.conf /etc/mdadm/mdadm.conf
  fi

  if [ ! -f $CONFIG ] && [ ! -f $ALTCONFIG ]; then
    echo -n 'Generating mdadm.conf... ' >&2
    if /usr/share/mdadm/mkconf >$CONFIG 2>/dev/null; then
      mkdir -p /var/lib/mdadm
      md5sum $CONFIG > /var/lib/mdadm/mdadm.conf-generated
      echo done. >&2
    else
      echo "failed (/proc probably not mounted)." >&2
      rm -f $CONFIG
    fi
  fi

  [ ! -f $CONFIG ] && CONFIG=$ALTCONFIG

  db_get mdadm/initrdstart
  INITRDSTART="${RET:-all}"
  db_get mdadm/autostart
  AUTOSTART="${RET:-true}"
  db_get mdadm/autocheck
  AUTOCHECK="${RET:-true}"
  db_get mdadm/start_daemon
  START_DAEMON="${RET:-true}"
  db_get mdadm/mail_to
  MAILADDR="${RET:-root}"

  cat <<_eof > $DEBIANCONFIG
# mdadm Debian configuration
#
# You can run 'dpkg-reconfigure mdadm' to modify the values in this file, if
# you want. You can also edit things here and changes will be preserved.
#

# INITRDSTART:
#   list of devices (or 'all') to start automatically when the initial ramdisk
#   loads. This list *must* include the device of your root filesystem.
INITRDSTART='$INITRDSTART'

# AUTOSTART:
#   should mdadm start devices listed in /etc/mdadm/mdadm.conf automatically
#   during boot?
AUTOSTART=$AUTOSTART

# AUTOCHECK:
#   should mdadm run periodic parity checks over your arrays? See
#   /etc/cron.d/mdadm.
AUTOCHECK=$AUTOCHECK

# START_DAEMON:
#   should mdadm start the RAID monitoring daemon during boot?
START_DAEMON=$START_DAEMON

# MAIL_TO
#   this variable is now managed in /etc/mdadm/mdadm.conf (MAILADDR).
#   Please see mdadm.conf(5).

# USE_DEPRECATED_MDRUN=
#   mdrun is deprecated. If you still want to use it without a warning, set
#   the following to true.
#
#   NOTE: changes to this variable will not be preserved!
#
USE_DEPRECATED_MDRUN=false
_eof

  if grep -q '^MAILADDR' $CONFIG; then
    sed -i -e "s,^MAILADDR.*,MAILADDR $MAILADDR," $CONFIG
  else
    echo "MAILADDR $MAILADDR" >> $CONFIG
  fi

  db_stop

  command -v update-initramfs >/dev/null && update-initramfs -u -k all
fi

# remove S04 installed as a fix to #294404 as it does not work
# we only remove the startup links if the previous version was 1.9.0-2.1 (the
# one with the erroneous fix) and the S04 link exists to make sure that
# chances are minimised to overwrite admin changes (even though this would
# not affect woody upgraders)
if [ "${1:-}" = "configure" ] && [ "${2:-}" = "1.9.0-2.1" ] \
   && test -L /etc/rcS.d/S04mdadm-raid;
then 
	update-rc.d -f mdadm-raid remove
fi

#DEBHELPER#

# do start mdadm-raid, but don't use dh_installinit to do so, to prevent
# stopping raids on remove/upgrade.
if [ -x /etc/init.d/mdadm-raid ]; then
  if [ -x "$(command -v invoke-rc.d)" ]; then
    invoke-rc.d mdadm-raid start || exit $?
  else
    /etc/init.d/mdadm-raid start || exit $?
  fi
fi

# install udev symlink if it's not already there and we're being upgraded,
# see #359614
V=2.5.2-10
F=/etc/udev/rules.d/z60_mdadm.rules
if [ "${1:-}" = "configure" ] && dpkg --compare-versions "${2:-$V}" lt $V \
  && [ ! -e $F ]; then

  ln -s ../mdadm.rules $F
fi