25 lines
419 B
Bash
25 lines
419 B
Bash
#!/bin/sh
|
|
|
|
set -e
|
|
|
|
case "$1" in
|
|
start)
|
|
loopdev=$(losetup --show -f /data/swapfile)
|
|
swapon $loopdev
|
|
;;
|
|
stop)
|
|
loopdev=$(losetup -j /data/swapfile | grep -o "/dev/loop[0-9]*")
|
|
swapoff $loopdev
|
|
losetup -d $loopdev
|
|
;;
|
|
restart)
|
|
loopdev=$(losetup -j /data/swapfile | grep -o "/dev/loop[0-9]*")
|
|
swapoff $loopdev
|
|
swapon $loopdev
|
|
;;
|
|
*)
|
|
echo "Usage: $0 { start | stop | restart }" >&2
|
|
exit 1
|
|
;;
|
|
esac
|