2007-01-10 14:07:57 +01:00
|
|
|
{library, utillinux, swapDevices}:
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
devicesByPath =
|
|
|
|
map (x: x.device) (library.filter (x: x ? device) swapDevices);
|
|
|
|
|
|
|
|
devicesByLabel =
|
|
|
|
map (x: x.label) (library.filter (x: x ? label) swapDevices);
|
|
|
|
|
|
|
|
in
|
2006-12-21 02:07:23 +01:00
|
|
|
|
|
|
|
{
|
|
|
|
name = "swap";
|
|
|
|
|
|
|
|
job = "
|
|
|
|
start on startup
|
2006-12-21 20:21:36 +01:00
|
|
|
start on new-devices
|
2006-12-21 02:07:23 +01:00
|
|
|
|
|
|
|
script
|
2007-01-10 14:07:57 +01:00
|
|
|
for device in ${toString devicesByPath}; do
|
2006-12-21 02:07:23 +01:00
|
|
|
${utillinux}/sbin/swapon \"$device\" || true
|
|
|
|
done
|
|
|
|
|
2007-01-10 14:07:57 +01:00
|
|
|
for label in ${toString devicesByLabel}; do
|
|
|
|
${utillinux}/sbin/swapon -L \"$label\" || true
|
2006-12-21 02:07:23 +01:00
|
|
|
done
|
2007-01-10 14:07:57 +01:00
|
|
|
|
|
|
|
# Remove swap devices not listed in swapDevices.
|
|
|
|
# !!! disabled because it doesn't work with labels
|
|
|
|
#for used in $(cat /proc/swaps | grep '^/' | sed 's/ .*//'); do
|
|
|
|
# found=
|
|
|
|
# for device in $ {toString swapDevices}; do
|
|
|
|
# if test \"$used\" = \"$device\"; then found=1; fi
|
|
|
|
# done
|
|
|
|
# if test -z \"$found\"; then
|
|
|
|
# ${utillinux}/sbin/swapoff \"$used\" || true
|
|
|
|
# fi
|
|
|
|
#done
|
2006-12-21 02:07:23 +01:00
|
|
|
|
|
|
|
end script
|
|
|
|
";
|
|
|
|
|
|
|
|
}
|