* Use postStart instead of preStart.

* Assemble devices only if there is a new entry.
* Add 'new-raid-array' flag to assemble new arrays.
* Emit new-devices flag to triggers the 'filesystems' task.

svn path=/nixos/trunk/; revision=19145
This commit is contained in:
Nicolas Pierron 2009-12-29 14:10:05 +00:00
parent e70214c853
commit 4cf78fdb77

View File

@ -15,7 +15,7 @@ let
echo "$@" >> ${logFile} echo "$@" >> ${logFile}
case $1 in case $1 in
(NewArray) (NewArray)
initctl emit -n new-devices initctl emit -n new-raid-array
;; ;;
(*) ;; (*) ;;
esac esac
@ -25,33 +25,51 @@ in
{ {
jobs.swraid = jobs.swraid = {
{ startOn = [ "startup" "new-devices" ]; startOn = [ "new-raid-array" ];
description = "Assemble RAID arrays.";
script = script = ''
'' # Load the necessary RAID personalities.
# Load the necessary RAID personalities. # !!! hm, doesn't the kernel load these automatically?
# !!! hm, doesn't the kernel load these automatically? for mod in raid0 raid1 raid5; do
for mod in raid0 raid1 raid5; do ${modprobe}/sbin/modprobe $mod || true
${modprobe}/sbin/modprobe $mod || true done
done
# Scan /proc/partitions for RAID devices. # Save previous probe
${mdadm}/sbin/mdadm --examine --brief --scan -c partitions > ${tempConf} mv ${tempConf} ${tempConf}.old
if ! test -s ${tempConf}; then exit 0; fi # Scan /proc/partitions for RAID devices.
${mdadm}/sbin/mdadm --examine --brief --scan -c partitions > ${tempConf}
# Activate each device found. if ! diff ${tempConf} ${tempConf}.old > /dev/null; then
${mdadm}/sbin/mdadm --assemble -c ${tempConf} --scan # Activate each device found.
''; ${mdadm}/sbin/mdadm --assemble -c ${tempConf} --scan
task = true; # Send notifications.
}; initctl emit -n new-devices
fi
# Remove previous configuration.
rm ${tempConf}.old
'';
task = true;
};
jobs.swraidEvents = { jobs.swraidEvents = {
name = "swraid-events"; name = "swraid-events";
description = "Watch mdadm events."; description = "Watch mdadm events.";
startOn = [ "startup" ]; startOn = [ "startup" ];
postStart = ''
echo > ${tempConf}
# Assemble early raid devices.
initctl emit -n new-raid-array
'';
# !!! Someone should ensure that this is indeed doing what the manual says.
exec = "${mdadm}/sbin/mdadm --monitor --scan --program ${mdadmEventHandler}"; exec = "${mdadm}/sbin/mdadm --monitor --scan --program ${mdadmEventHandler}";
}; };