freebsd-dev/etc/rc.d/addswap

70 lines
1.2 KiB
Plaintext
Raw Normal View History

#!/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"