File boot.compcache of Package compcache
#!/bin/sh
#
# System startup script loading compcache kernel module
# Copyright (C) 2008 Takashi Iwai <tiwai@suse.de>
#
# /etc/init.d/compcache
#
### BEGIN INIT INFO
# Provides: compcache
# Required-Start: boot.swap
# Required-Stop: boot.swap
# Should-Start:
# Should-Stop:
# Default-Start: B
# Default-Stop: B
# Description: Loads compcache - compressed RAM based swap device
### END INIT INFO
. /etc/rc.status
. /etc/sysconfig/compcache
SWAPON_BIN=/sbin/swapon
SWAPOFF_BIN=/sbin/swapoff
UDEVADM_BIN=/sbin/udevadm
MODPROBE_BIN=/sbin/modprobe
SWAPDEV=/dev/ramzswap0
is_comp_swap_on () {
grep -q ramzswap /proc/swaps
return $?
}
rc_reset
case "$1" in
start|restart)
test -z "$COMPCACHE_SIZE_KB" && COMPCACHE_SIZE_KB="0"
if [ "$COMPCACHE_SIZE_KB" -lt 0 ]; then
rc_exit
fi
if [ "$COMPCACHE_SIZE_KB" = "0" ]; then
echo "No compcache size is given, using default 25% of RAM"
param=""
else
param="disksize_kb=$COMPCACHE_SIZE_KB"
fi
echo -n "Loading ramzswap driver"
$MODPROBE_BIN -q ramzswap &>/dev/null
rc_status -v
# /dev/ramzswap0 is not available immediately after insmod returns
# So, let udev complete its work before we do swapon
if [ ! -f $SWAPDEV ]; then
if [ -f "$UDEVADM_BIN" ]; then
$UDEVADM_BIN settle
else
sleep 2
fi
fi
# Set it as swap device with highest priority
if ! is_comp_swap_on; then
echo -n "Setting up ramzswap swap device"
$SWAPON_BIN $SWAPDEV -p 100
rc_status -v
fi
;;
stop)
if is_comp_swap_on; then
echo -n "Turning off ramzswap swap device"
$SWAPOFF_BIN $SWAPDEV
rc_status -v
fi
echo -n "Unloading ramzswap module"
$MODPROBE_BIN -qr ramzswap &>/dev/null
rc_status -v
;;
restart)
$0 stop
$0 start
;;
status)
echo -n "Checking for compcache "
if is_comp_swap_on; then
rc_failed 0
else
rc_failed 3
fi
rc_status -v
;;
*)
echo "Usage: $0 {start|stop|status|restart}"
exit 1
;;
esac
rc_exit