freebsd-skq/etc/rc.d/addswap
Chris Rees c45506efd1 Clean up swapfile memory disk on shutdown
Make the md unit number configurable so that it can be predicted

PR:		bin/168544
Submitted by:	wblock (based on)
Approved by:	kevlo
2013-06-12 16:44:17 +00:00

70 lines
1.2 KiB
Bash
Executable File

#!/bin/sh
#
# Add additional swap files
#
# $FreeBSD$
#
# PROVIDE: addswap
# REQUIRE: FILESYSTEMS kld
# BEFORE: netif
# KEYWORD: nojail shutdown
. /etc/rc.subr
name="addswap"
start_cmd="addswap_start"
stop_cmd="addswap_stop"
addswap_start()
{
case ${swapfile} in
[Nn][Oo] | '')
;;
*)
if [ -w "${swapfile}" ]; then
check_startmsgs && echo "Adding ${swapfile} as additional swap"
if [ -n "${swapfile_mdunit}" ]; then
mdev="/dev/md${swapfile_mdunit#md}"
mdconfig -a -t vnode -f "${swapfile}" -u ${swapfile_mdunit}
else
mdev="/dev/`mdconfig -a -t vnode -f "${swapfile}"`"
fi
if [ $? -eq 0 ]; then
swapon ${mdev}
else
echo "error creating swapfile device"
fi
fi
;;
esac
}
addswap_stop()
{
case ${swapfile} in
[Nn][Oo] | '')
;;
*)
if [ -n "${swapfile_mdunit}" ]; then
mdev="/dev/md${swapfile_mdunit#md}"
else
mdev="/dev/`mdconfig -lv | grep "${swapfile}" | cut -f1`"
swapfile_mdunit=${mdev#md}
fi
if [ -n "${swapfile_mdunit}" ]; then
swapctl -l | grep -q ${mdev}
if [ $? -eq 0 ]; then
echo "Dismounting swapfile ${swapfile}"
swapoff ${mdev} && mdconfig -d -u ${swapfile_mdunit}
fi
fi
;;
esac
}
load_rc_config $name
run_rc_command "$1"