#!/bin/sh DAEMON=swap CONF_NAME=mod . /etc/init.d/modlibrc has_swap() { sed '1d' /proc/swaps | grep -v /dev/ramzswap0 | grep -q '' } start() { echo -n "Starting $DAEMON ... " if has_swap; then echo 'already running.' exit 1 fi swapon "$MOD_SWAP_FILE" 2>/dev/null exitval=$? if [ "$exitval" -eq 0 ]; then echo $MOD_SWAP_SWAPPINESS >/proc/sys/vm/swappiness echo 'done.' else echo 'failed.' exit $exitval fi } stop() { echo -n "Stopping $DAEMON ... " if ! has_swap; then echo 'not running.' exit 1 fi sed '1d' /proc/swaps | grep -v /dev/ramzswap0 | while read swap _; do swapoff $swap done if has_swap; then echo 'failed.' exit 1 else echo 'done.' fi } autohelper() { if [ $# -ne 2 ]; then echo "Usage: $0 [autostart|autostop] [file or partition]" 1>&2 return 1 fi echo "$MOD_SWAP_FILE" | grep -q $2 || exit 2 # not the defined swap-partition, abort [ "$MOD_SWAP" != yes ] && exit 3 # auto-mode is disabled, abort $1 >> /var/log/mod_swap.log } case $1 in ""|load) modreg daemon -p mod swap if [ "$MOD_SWAP" != yes ]; then echo "$DAEMON is disabled." 1>&2 exit 1 fi echo "$DAEMON is enabled." 1>&2 ;; unload) stop modunreg daemon mod swap ;; start) start ;; stop) stop ;; restart) stop sleep 1 start ;; autostart) autohelper start $2 ;; autostop) autohelper stop $2 ;; status) if has_swap; then echo 'running' else echo 'stopped' fi ;; *) echo "Usage: $0 [load|unload|start|stop|restart|autostart|autostop|status]" 1>&2 exit 1 ;; esac exit 0